|
1 | 1 | name: Validate new issue |
2 | 2 | on: |
3 | 3 | issues: |
4 | | - types: ['opened'] |
| 4 | + types: ["opened"] |
5 | 5 | jobs: |
6 | 6 | validate-new-issue: |
7 | 7 | runs-on: ubuntu-latest |
8 | 8 | 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 }}." |
16 | 16 |
|
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 |
24 | 24 |
|
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 |
45 | 48 | else |
46 | | - exit 0 |
| 49 | + echo "No match. 👎" |
47 | 50 | 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 | + ---- |
52 | 58 |
|
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[](https://www.youtube.com/watch?v=Fy3rjQGc6lA)"} |
56 | | - EOF |
| 59 | + [](https://www.youtube.com/watch?v=Fy3rjQGc6lA)" |
| 60 | + EOF |
57 | 61 |
|
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