From 11acadc1c5083028bb7bfdffd852d07f94c7b832 Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Mon, 1 Feb 2021 13:15:35 -0500 Subject: [PATCH] Deploy action: validate-new-issue.yml --- .github/workflows/validate-new-issue.yml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/validate-new-issue.yml b/.github/workflows/validate-new-issue.yml index c99c9ce0931..a134fd60450 100644 --- a/.github/workflows/validate-new-issue.yml +++ b/.github/workflows/validate-new-issue.yml @@ -26,16 +26,25 @@ jobs: # - extra headings in the issue are fine # - order doesn't matter # - case-sensitive tho + # - can't post a template unchanged (ignoring whitespace) function extract-headings { { grep '^#' "$1" || echo -n ''; } | sort; } - extract-headings <(jq -r .issue.body "$GITHUB_EVENT_PATH") > headings-in-issue + 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! 👍 💃" - exit 0 + if diff -Bw "$template" issue > /dev/null; then + echo "... like, an /exact/ match. 😖" + break + else + exit 0 + fi else echo "No match. 👎" fi @@ -48,8 +57,5 @@ jobs: # 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 comment ${{ github.event.issue.number }} --body "$(cat comment)" gh issue close ${{ github.event.issue.number }}