Skip to content

Commit

Permalink
meta(gha): Deploy action validate-new-issue.yml (getsentry#849)
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre authored Feb 2, 2021
1 parent 9e94e37 commit 5bad6ed
Showing 1 changed file with 43 additions and 27 deletions.
70 changes: 43 additions & 27 deletions .github/workflows/validate-new-issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: "Validate issue against templates"
- name: "Validate new issue"
shell: bash
env:
GITHUB_TOKEN: ${{ github.token }}
Expand All @@ -22,43 +22,59 @@ jobs:
echo "${{ github.actor }} is not a member of the getsentry org. 🧐"
fi
# Look for a template where all the headings are also in this issue.
# - extra headings in the issue are fine
# - order doesn't matter
# - case-sensitive tho
# - can't post a template unchanged (ignoring whitespace)
# Prep reasons for error message comment.
REASON="your issue does not properly use one of this repo's available issue templates"
REASON_EXACT_MATCH="you created an issue from a template without filling in anything"
REASON_EMPTY="you created an empty issue"
# Definition of valid:
# - not empty (ignoring whitespace)
# - matches a template
# - all the headings are also in this issue
# - extra headings in the issue are fine
# - order doesn't matter
# - case-sensitive tho
# - not an *exact* match for a template (ignoring whitespace)
function extract-headings { { sed 's/\r$//' "$1" | grep '^#' || echo -n ''; } | sort; }
jq -r .issue.body "$GITHUB_EVENT_PATH" > issue
extract-headings <(cat issue) > headings-in-issue
for template in $(ls .github/ISSUE_TEMPLATE/*.md 2> /dev/null); do
# Strip front matter. https://stackoverflow.com/a/29292490/14946704
sed -i'' '1{/^---$/!q;};1,/^---$/d' "$template"
extract-headings "$template" > headings-in-template
echo -n "$(basename $template)? "
if [ ! -s headings-in-template ]; then
echo "No headers in template. 🤷"
elif [ -z "$(comm -23 headings-in-template headings-in-issue)" ]; then
echo "Match! 👍 💃"
if diff -Bw "$template" issue > /dev/null; then
echo "... like, an /exact/ match. 😖"
break
if ! grep -q '[^[:space:]]' issue; then
REASON="${REASON_EMPTY}"
else
extract-headings <(cat issue) > headings-in-issue
for template in $(ls .github/ISSUE_TEMPLATE/*.md 2> /dev/null); do
# Strip front matter. https://stackoverflow.com/a/29292490/14946704
sed -i'' '1{/^---$/!q;};1,/^---$/d' "$template"
extract-headings "$template" > headings-in-template
echo -n "$(basename $template)? "
if [ ! -s headings-in-template ]; then
echo "No headers in template. 🤷"
elif [ -z "$(comm -23 headings-in-template headings-in-issue)" ]; then
echo "Match! 👍 💃"
if diff -Bw "$template" issue > /dev/null; then
echo "... like, an /exact/ match. 😖"
REASON="${REASON_EXACT_MATCH}"
break
else
exit 0
fi
else
exit 0
echo "No match. 👎"
fi
else
echo "No match. 👎"
fi
done
done
fi
# Failed to find a match! Close the issue.
# Failed validation! Close the issue with a comment.
cat << EOF > comment
Sorry, friend. As far as this ol' bot can tell, your issue does not use one of this repo's available issue templates. Please [try again using a template](https://github.com/${{ github.repository }}/issues/new/choose) so that we have the best chance of understanding and addressing your issue. (And if I'm confused, please [let us know](https://github.com/getsentry/.github/issues/new?title=template+enforcer+is+confused&body=${{ github.event.issue.html_url }}). 😬)
Sorry, friend. As far as this ol' bot can tell, ${REASON}. Please [try again](https://github.com/${{ github.repository }}/issues/new/choose), if you like. (And if I'm confused, please [let us know](https://github.com/getsentry/.github/issues/new?title=template+enforcer+is+confused&body=${{ github.event.issue.html_url }}). 😬)
----
[![Did you see the memo about this?](https://user-images.githubusercontent.com/134455/104515469-e04a9c80-55c0-11eb-8e15-ffe9c0b8dd7f.gif)](https://www.youtube.com/watch?v=Fy3rjQGc6lA)"
[![Did you see the memo about this?](https://user-images.githubusercontent.com/134455/104515469-e04a9c80-55c0-11eb-8e15-ffe9c0b8dd7f.gif)](https://www.youtube.com/watch?v=Fy3rjQGc6lA)
([log](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}))
EOF
echo -n "Commented: "
gh issue comment ${{ github.event.issue.number }} --body "$(cat comment)"
gh issue close ${{ github.event.issue.number }}
echo "Closed with: \"${REASON}.\""

0 comments on commit 5bad6ed

Please sign in to comment.