Skip to content

Commit 75592aa

Browse files
authored
Add GitHub Action to enforce JIRA ticket reference in PR description
1 parent 2c8c677 commit 75592aa

2 files changed

Lines changed: 73 additions & 1 deletion

File tree

.github/pull_request_template.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33

44

55
## Project tracking
6-
<!-- What is the Jira Issue URL for this PR? -->
6+
<!-- Required: Provide the Jira Issue key or URL below. Use the override checkbox if not applicable. -->
7+
8+
9+
- [ ] This PR does not require a JIRA ticket (explain below why)
10+
<!-- If checked, you MUST provide an explanation below or the PR will be blocked. -->
711

812

913
## Do any added TODOs have an issue in the backlog?

.github/workflows/jira-check.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: jira-check
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited, reopened, synchronize]
6+
branches:
7+
- master
8+
- stable/**
9+
10+
permissions:
11+
pull-requests: read
12+
13+
jobs:
14+
jira-check:
15+
name: JIRA ticket validation
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Validate JIRA reference in PR body
19+
env:
20+
PR_BODY: ${{ github.event.pull_request.body }}
21+
JIRA_PROJECT_KEY: ${{ vars.JIRA_PROJECT_KEY }}
22+
run: |
23+
set -euo pipefail
24+
25+
if [[ -z "${JIRA_PROJECT_KEY:-}" ]]; then
26+
echo "::error::Repository variable JIRA_PROJECT_KEY is not set."
27+
exit 1
28+
fi
29+
30+
if [[ -z "${PR_BODY:-}" ]]; then
31+
echo "::error::PR body is empty. Please use the PR template and provide a JIRA ticket under '## Project tracking'."
32+
exit 1
33+
fi
34+
35+
# Extract the "Project tracking" section (between its heading and the next ## heading).
36+
SECTION=$(printf '%s\n' "$PR_BODY" | sed -n '/^## Project tracking/,/^## /{/^## Project tracking/d;/^## /d;p}')
37+
38+
if [[ -z "$SECTION" ]]; then
39+
echo "::error::Could not find the '## Project tracking' section in the PR body. Please use the PR template."
40+
exit 1
41+
fi
42+
43+
if grep -iqE "${JIRA_PROJECT_KEY}-[0-9]+" <<<"$SECTION"; then
44+
echo "Found JIRA reference in Project tracking section."
45+
exit 0
46+
fi
47+
48+
# No JIRA found — check for the override checkbox.
49+
if grep -qE '^\s*- \[[xX]\]' <<<"$SECTION"; then
50+
# Checkbox is checked. Now verify an explanation exists after the checkbox line.
51+
# Grab all lines after the checkbox, strip HTML comments and blank lines.
52+
EXPLANATION=$(printf '%s\n' "$SECTION" \
53+
| sed -n '/^\s*- \[[xX]\]/,$ p' \
54+
| tail -n +2 \
55+
| sed 's/<!--.*-->//g' \
56+
| grep -v '^\s*$' || true)
57+
58+
if [[ -n "$EXPLANATION" ]]; then
59+
echo "No JIRA required — override accepted with explanation."
60+
exit 0
61+
else
62+
echo "::error::Override checkbox is checked but no explanation was provided. Please explain why a JIRA ticket is not needed."
63+
exit 1
64+
fi
65+
fi
66+
67+
echo "::error::No JIRA ticket found in the '## Project tracking' section. Either add a JIRA reference or check the override checkbox and provide an explanation."
68+
exit 1

0 commit comments

Comments
 (0)