Skip to content

fix: parse PR number from merge commit message - #16

Merged
sergioaten merged 2 commits into
mainfrom
fix/pr-number-from-commit-msg
Mar 19, 2026
Merged

sergioaten merged 2 commits into
mainfrom
fix/pr-number-from-commit-msg

Conversation

@sergioaten

Copy link
Copy Markdown
Contributor

Problem

The apply job failed with:

Could not determine PR number for commit 62a31361...

The /commits/{sha}/pulls GitHub API returns empty for merge commits — the merge commit only exists in main's history after the PR closes, not in the PR's own commit list.

Fix

Parse the PR number from the merge commit message, which GitHub always embeds:

  • Regular merge: Merge pull request #37 from owner/branch
  • Squash merge: Some title (#37)

Pattern: grep -oP '(?<=pull request #)\d+|(?<=\(#)\d+(?=\))'

🤖 Generated with Claude Code

sergioaten and others added 2 commits March 19, 2026 18:47
The GitHub API /commits/{sha}/pulls returns empty for merge commits
because the merge commit is not part of the PR's commit list — it only
exists in main's history after the PR is closed. This caused the apply
job to fail with "Could not determine PR number".

Extract the PR number from the commit message instead, which works for
both merge strategies GitHub supports:
  - Regular merge: "Merge pull request #37 from owner/branch"
  - Squash merge:  "Some title (#37)"

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The inline ${{ steps.apply_summarize.outputs.summary }} substitution
happens before bash evaluates the script. When the summary contains
Terragrunt output with paths like 'iac/prod/github' or tokens like
'github_repository.default[0]::', bash interprets them as commands,
causing 'command not found' errors.

Use env: + printf '%s\n' "$SUMMARY" (same pattern as the plan job's
Write plan summary to file step) to pass the value through the
environment instead of inline substitution.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sergioaten
sergioaten merged commit 3024789 into main Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant