Skip to content

Commit 9e94e37

Browse files
authored
1 parent 020ded2 commit 9e94e37

File tree

1 file changed

+51
-48
lines changed

1 file changed

+51
-48
lines changed
Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,64 @@
11
name: Validate new issue
22
on:
33
issues:
4-
types: ['opened']
4+
types: ["opened"]
55
jobs:
66
validate-new-issue:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v2
10-
- name: "Validate issue against templates"
11-
shell: bash
12-
env:
13-
GITHUB_TOKEN: ${{ github.token }}
14-
run: |
15-
echo "Validating issue #${{ github.event.issue.number }}."
9+
- uses: actions/checkout@v2
10+
- name: "Validate issue against templates"
11+
shell: bash
12+
env:
13+
GITHUB_TOKEN: ${{ github.token }}
14+
run: |
15+
echo "Validating issue #${{ github.event.issue.number }}."
1616
17-
# Trust users who belong to the getsentry org.
18-
if gh api "https://api.github.com/orgs/getsentry/members/${{ github.actor }}" >/dev/null 2>&1; then
19-
echo "Skipping validation, because ${{ github.actor }} is a member of the getsentry org."
20-
exit 0
21-
else
22-
echo "${{ github.actor }} is not a member of the getsentry org. 🧐"
23-
fi
17+
# Trust users who belong to the getsentry org.
18+
if gh api "https://api.github.com/orgs/getsentry/members/${{ github.actor }}" >/dev/null 2>&1; then
19+
echo "Skipping validation, because ${{ github.actor }} is a member of the getsentry org."
20+
exit 0
21+
else
22+
echo "${{ github.actor }} is not a member of the getsentry org. 🧐"
23+
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)
30-
function extract-headings { { grep '^#' "$1" || echo -n ''; } | sort; }
31-
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
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)
30+
function extract-headings { { sed 's/\r$//' "$1" | grep '^#' || echo -n ''; } | sort; }
31+
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
45+
else
46+
exit 0
47+
fi
4548
else
46-
exit 0
49+
echo "No match. 👎"
4750
fi
48-
else
49-
echo "No match. 👎"
50-
fi
51-
done
51+
done
52+
53+
# Failed to find a match! Close the issue.
54+
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 }}). 😬)
56+
57+
----
5258
53-
# Failed to find a match! Close the issue.
54-
cat << EOF > comment
55-
{"body": "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 }}). 😬)\n\n----\n\n[![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)"}
56-
EOF
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)"
60+
EOF
5761
58-
# Might get `gh issue comment` some day - https://github.com/cli/cli/issues/517
59-
echo -n "Commented: "
60-
gh issue comment ${{ github.event.issue.number }} --body "$(cat comment)"
61-
gh issue close ${{ github.event.issue.number }}
62+
echo -n "Commented: "
63+
gh issue comment ${{ github.event.issue.number }} --body "$(cat comment)"
64+
gh issue close ${{ github.event.issue.number }}

0 commit comments

Comments
 (0)