Skip to content

Commit f4b4945

Browse files
authored
ci: accept cross-repo issue references in the PR body check (#124)
The PR Body check only matched a same-repo '#N' after closes, fixes, resolves or refs, so a PR tracked by another repo's issue failed even though GitHub links the reference. It now accepts GitHub's closing keywords plus Refs, in any casing and with an optional colon, followed by #N, GH-N, owner/repo#N or a github.com issue URL. Word boundaries keep it strict: repo#N without an owner, fragments on other sites and keywords glued to other text do not count. Refs CryptOS-PKI/.github#5 Signed-off-by: Bugs5382 <12115015+Bugs5382@users.noreply.github.com> Co-authored-by: Bugs5382 <12115015+Bugs5382@users.noreply.github.com>
1 parent aad6451 commit f4b4945

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

‎.github/workflows/job-pr-checks.yaml‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,19 @@ jobs:
5252
if: ${{ !cancelled() }}
5353
env:
5454
BODY: ${{ github.event.pull_request.body }}
55+
# An issue reference is a keyword (GitHub's closing keywords, or Refs),
56+
# an optional colon, then a reference GitHub links: #12, GH-12,
57+
# owner/repo#12, or https://github.com/owner/repo/issues/12. Casing is
58+
# free. A repo without its owner (repo#12) or a fragment on another
59+
# site does not count, because GitHub does not link those.
5560
run: |
5661
fail=0
57-
printf '%s' "$BODY" | grep -qiE '(closes|fixes|resolves|refs) #[0-9]+' \
58-
|| { echo "PR body must reference an issue (e.g. 'Closes #12')."; fail=1; }
62+
owner='[[:alnum:]][[:alnum:]-]*'
63+
repo='[[:alnum:]._-]+'
64+
target="(#|gh-|${owner}/${repo}#|https://github\\.com/${owner}/${repo}/issues/)[0-9]+"
65+
ref="(^|[^[:alnum:]_])(close[sd]?|fix(e[sd])?|resolve[sd]?|refs):?[[:space:]]+${target}([^[:alnum:]_]|\$)"
66+
printf '%s' "$BODY" | grep -qiE "$ref" \
67+
|| { echo "PR body must reference an issue (e.g. 'Closes #12' or 'Refs owner/repo#12')."; fail=1; }
5968
printf '%s' "$BODY" | grep -qiE '##[[:space:]]*what' \
6069
|| { echo "PR body must follow the template (a 'What and why' section)."; fail=1; }
6170
[ "$fail" -eq 0 ] || exit 1

0 commit comments

Comments
 (0)