Skip to content

Commit 5bad6ed

Browse files
authored
meta(gha): Deploy action validate-new-issue.yml (#849)
I are a bot, here to deploy [validate-new-issue.yml](https://github.com/getsentry/.github/blob/f663e1dd631880fa51cba2126f6192c92826c437/.github/workflows/validate-new-issue.yml). 🤖
1 parent 9e94e37 commit 5bad6ed

File tree

1 file changed

+43
-27
lines changed

1 file changed

+43
-27
lines changed

.github/workflows/validate-new-issue.yml

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@v2
10-
- name: "Validate issue against templates"
10+
- name: "Validate new issue"
1111
shell: bash
1212
env:
1313
GITHUB_TOKEN: ${{ github.token }}
@@ -22,43 +22,59 @@ jobs:
2222
echo "${{ github.actor }} is not a member of the getsentry org. 🧐"
2323
fi
2424
25-
# Look for a template where all the headings are also in this issue.
26-
# - extra headings in the issue are fine
27-
# - order doesn't matter
28-
# - case-sensitive tho
29-
# - can't post a template unchanged (ignoring whitespace)
25+
# Prep reasons for error message comment.
26+
REASON="your issue does not properly use one of this repo's available issue templates"
27+
REASON_EXACT_MATCH="you created an issue from a template without filling in anything"
28+
REASON_EMPTY="you created an empty issue"
29+
30+
# Definition of valid:
31+
# - not empty (ignoring whitespace)
32+
# - matches a template
33+
# - all the headings are also in this issue
34+
# - extra headings in the issue are fine
35+
# - order doesn't matter
36+
# - case-sensitive tho
37+
# - not an *exact* match for a template (ignoring whitespace)
3038
function extract-headings { { sed 's/\r$//' "$1" | grep '^#' || echo -n ''; } | sort; }
3139
jq -r .issue.body "$GITHUB_EVENT_PATH" > issue
32-
extract-headings <(cat issue) > headings-in-issue
33-
for template in $(ls .github/ISSUE_TEMPLATE/*.md 2> /dev/null); do
34-
# Strip front matter. https://stackoverflow.com/a/29292490/14946704
35-
sed -i'' '1{/^---$/!q;};1,/^---$/d' "$template"
36-
extract-headings "$template" > headings-in-template
37-
echo -n "$(basename $template)? "
38-
if [ ! -s headings-in-template ]; then
39-
echo "No headers in template. 🤷"
40-
elif [ -z "$(comm -23 headings-in-template headings-in-issue)" ]; then
41-
echo "Match! 👍 💃"
42-
if diff -Bw "$template" issue > /dev/null; then
43-
echo "... like, an /exact/ match. 😖"
44-
break
40+
if ! grep -q '[^[:space:]]' issue; then
41+
REASON="${REASON_EMPTY}"
42+
else
43+
extract-headings <(cat issue) > headings-in-issue
44+
for template in $(ls .github/ISSUE_TEMPLATE/*.md 2> /dev/null); do
45+
# Strip front matter. https://stackoverflow.com/a/29292490/14946704
46+
sed -i'' '1{/^---$/!q;};1,/^---$/d' "$template"
47+
extract-headings "$template" > headings-in-template
48+
echo -n "$(basename $template)? "
49+
if [ ! -s headings-in-template ]; then
50+
echo "No headers in template. 🤷"
51+
elif [ -z "$(comm -23 headings-in-template headings-in-issue)" ]; then
52+
echo "Match! 👍 💃"
53+
if diff -Bw "$template" issue > /dev/null; then
54+
echo "... like, an /exact/ match. 😖"
55+
REASON="${REASON_EXACT_MATCH}"
56+
break
57+
else
58+
exit 0
59+
fi
4560
else
46-
exit 0
61+
echo "No match. 👎"
4762
fi
48-
else
49-
echo "No match. 👎"
50-
fi
51-
done
63+
done
64+
fi
5265
53-
# Failed to find a match! Close the issue.
66+
# Failed validation! Close the issue with a comment.
5467
cat << EOF > comment
55-
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 }}). 😬)
68+
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 }}). 😬)
5669
5770
----
5871
59-
[![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)"
72+
[![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)
73+
74+
([log](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}))
6075
EOF
6176
6277
echo -n "Commented: "
6378
gh issue comment ${{ github.event.issue.number }} --body "$(cat comment)"
6479
gh issue close ${{ github.event.issue.number }}
80+
echo "Closed with: \"${REASON}.\""

0 commit comments

Comments
 (0)