1616 required : false
1717 type : string
1818 description : ' The PR title to check (for pull_request_target support)'
19- regex-pattern :
20- required : false
21- type : string
22- description : ' Custom regex pattern to match JIRA IDs (defaults to "[A-Z]+-[0-9]+")'
23- default : ' [A-Z]+-[0-9]+'
24- fail-if-no-jira-id :
25- required : false
26- type : string
27- description : ' Whether to fail the check if no JIRA ID is found'
28- default : ' true'
2919 allow-wip :
3020 required : false
3121 type : string
4030jobs :
4131 check-jira-id :
4232 runs-on : ubuntu-latest
33+ permissions :
34+ pull-requests : read
4335 steps :
4436 - name : 🏷️ Validate JIRA ticket ID in PR title
4537 shell : bash
4638 env :
4739 GH_TOKEN : ${{ github.token }}
40+ INPUT_PR_TITLE : ${{ inputs.pr-title }}
41+ EVENT_PR_TITLE : ${{ github.event.pull_request.title }}
42+ PR_NUMBER : ${{ github.event.pull_request.number }}
43+ GH_REPO : ${{ github.repository }}
44+ INPUT_ALLOW_WIP : ${{ inputs.allow-wip }}
45+ INPUT_CASE_SENSITIVE : ${{ inputs.case-sensitive }}
4846 run : |
4947 # Get PR title from context or input parameter (for pull_request_target support)
50- if [[ -n "${{ inputs.pr-title }} " ]]; then
51- PR_TITLE="${{ inputs.pr-title }} "
48+ if [[ -n "$INPUT_PR_TITLE " ]]; then
49+ PR_TITLE="$INPUT_PR_TITLE "
5250 echo "Using PR title from input parameter"
5351 else
54- PR_TITLE="${{ github.event.pull_request.title }} "
52+ PR_TITLE="$EVENT_PR_TITLE "
5553 echo "Using PR title from GitHub event context"
5654 fi
57-
55+
5856 # Fetch the current PR title from the API to handle re-runs correctly.
5957 # When a workflow is re-run (either directly or via a reusable workflow caller),
6058 # the event payload contains the title from the original trigger, not the current
6159 # state. If the user edited the title (e.g., to add a JIRA ID), we need to detect
6260 # that and use the updated title instead.
63- PR_NUMBER="${{ github.event.pull_request.number }}"
6461 if [[ -n "$PR_NUMBER" ]]; then
6562 LIVE_TITLE=$(gh pr view "$PR_NUMBER" \
66- --repo "${{ github.repository }} " \
63+ --repo "$GH_REPO " \
6764 --json title --jq '.title' 2>/dev/null || true)
68-
65+
6966 if [[ -n "$LIVE_TITLE" && "$LIVE_TITLE" != "$PR_TITLE" ]]; then
70- echo "⚠️ PR title was updated since workflow was triggered"
71- echo " Event title: $PR_TITLE"
72- echo " Current title: $LIVE_TITLE"
67+ echo "PR title was updated since workflow was triggered"
68+ echo " Event title: $PR_TITLE"
69+ echo " Current title: $LIVE_TITLE"
7370 PR_TITLE="$LIVE_TITLE"
7471 fi
7572 fi
7673 echo "PR Title: $PR_TITLE"
77-
78- # Set up inputs as environment variables
79- # JIRA project keys are defined at the organization level
80- JIRA_PROJECT_KEYS="${{ env.ORGANIZATION_JIRA_PROJECT_KEYS }}"
81- REGEX_PATTERN="${{ inputs.regex-pattern }}"
82- FAIL_IF_NO_JIRA_ID="${{ inputs.fail-if-no-jira-id }}"
83- ALLOW_WIP="${{ inputs.allow-wip }}"
84- CASE_SENSITIVE="${{ inputs.case-sensitive }}"
85-
74+
75+ JIRA_PROJECT_KEYS="$ORGANIZATION_JIRA_PROJECT_KEYS"
76+ ALLOW_WIP="$INPUT_ALLOW_WIP"
77+ CASE_SENSITIVE="$INPUT_CASE_SENSITIVE"
78+
8679 echo "Using organization-wide JIRA project keys: $JIRA_PROJECT_KEYS"
87- echo "Using regex pattern: $REGEX_PATTERN"
88- echo "Fail if no JIRA ID: $FAIL_IF_NO_JIRA_ID"
8980 echo "Allow WIP PRs: $ALLOW_WIP"
9081 echo "Case sensitive: $CASE_SENSITIVE"
91-
82+
9283 # Handle WIP PRs
9384 if [[ "$ALLOW_WIP" == "true" && "${PR_TITLE,,}" =~ ^wip: ]]; then
9485 echo "This is a WIP PR. Skipping JIRA ID check."
9586 exit 0
9687 fi
97-
88+
9889 # Convert comma-separated project keys to array
9990 IFS=',' read -ra PROJECT_KEYS <<< "$JIRA_PROJECT_KEYS"
10091 echo "Valid project keys: ${PROJECT_KEYS[*]}"
101-
92+
10293 # Directly check for valid JIRA IDs in the PR title
10394 VALID_ID_FOUND=false
104-
95+
10596 for VALID_KEY in "${PROJECT_KEYS[@]}"; do
10697 # Create a pattern specifically for this project key
10798 if [[ "$CASE_SENSITIVE" == "true" ]]; then
@@ -122,7 +113,7 @@ jobs:
122113 fi
123114 fi
124115 done
125-
116+
126117 if [[ "$VALID_ID_FOUND" != "true" ]]; then
127118 echo "ERROR: No JIRA ID found in PR title: \"$PR_TITLE\". Valid project keys are: $JIRA_PROJECT_KEYS"
128119 echo "::error::No JIRA ID found in PR title: \"$PR_TITLE\". Valid project keys are: $JIRA_PROJECT_KEYS"
0 commit comments