-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
48 lines (44 loc) · 2.29 KB
/
validate-new-issue.yml
File metadata and controls
48 lines (44 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
name: Validate new issue
on:
issues:
types: ['opened']
jobs:
validate-new-issue:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: "Validate issue against templates"
shell: bash
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
# Trust users who belong to the getsentry org.
if gh api "https://api.github.com/orgs/getsentry/members/${{ github.actor }}" >/dev/null 2>&1; then
echo "Skipping validation, because ${{ github.actor }} is a member of the getsentry org."
exit 0
else
echo "${{ github.actor }} is not a member of the getsentry org. 🧐"
fi
# Look for a template where the headings match this issue's
echo "${{ github.event.issue.body }}" > issue-body
for template in $(ls .github/ISSUE_TEMPLATE/*.md 2> /dev/null); do
echo -n "$(basename $template)? "
# <() is process substitution - https://superuser.com/a/1060002
if diff -rub <(grep '^#' $template) <(grep '^#' issue-body) > /dev/null; then
echo "👍 💃"
exit 0
else
echo "👎"
fi
done
# Failed to find a match! Close the issue.
cat << EOF > comment
{"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)"}
EOF
# Might get `gh issue comment` some day - https://github.com/cli/cli/issues/517
echo -n "Commented: "
gh api "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments" \
--method POST \
--input comment \
| jq .html_url
gh issue close ${{ github.event.issue.number }}