Skip to content

Commit 233ef22

Browse files
PDP-969: Fetch live PR title on re-runs to handle stale event payload
1 parent a8490ef commit 233ef22

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

.github/workflows/jira-id-check.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ jobs:
4343
steps:
4444
- name: 🏷️ Validate JIRA ticket ID in PR title
4545
shell: bash
46+
env:
47+
GH_TOKEN: ${{ github.token }}
4648
run: |
4749
# Get PR title from context or input parameter (for pull_request_target support)
4850
if [[ -n "${{ inputs.pr-title }}" ]]; then
@@ -52,6 +54,25 @@ jobs:
5254
PR_TITLE="${{ github.event.pull_request.title }}"
5355
echo "Using PR title from GitHub event context"
5456
fi
57+
58+
# Fetch the current PR title from the API to handle re-runs correctly.
59+
# When a workflow is re-run (either directly or via a reusable workflow caller),
60+
# the event payload contains the title from the original trigger, not the current
61+
# state. If the user edited the title (e.g., to add a JIRA ID), we need to detect
62+
# that and use the updated title instead.
63+
PR_NUMBER="${{ github.event.pull_request.number }}"
64+
if [[ -n "$PR_NUMBER" ]]; then
65+
LIVE_TITLE=$(gh pr view "$PR_NUMBER" \
66+
--repo "${{ github.repository }}" \
67+
--json title --jq '.title' 2>/dev/null || true)
68+
69+
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"
73+
PR_TITLE="$LIVE_TITLE"
74+
fi
75+
fi
5576
echo "PR Title: $PR_TITLE"
5677
5778
# Set up inputs as environment variables

0 commit comments

Comments
 (0)