Skip to content

Commit 4768226

Browse files
thenav56claude
andcommitted
fix(helm): make PR provenance lookup work and fail visibly
The commit->PR lookup (gh api commits/{sha}/pulls) needs pull-requests:read, but the error was swallowed by `2>/dev/null || true` so a 403 looked like "No PR associated". Surface API failures as a warning and declare pull-requests:read on the helm_publish job. The caller must also grant `pull-requests: read` since a reusable workflow can only narrow the caller token. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 38b3d65 commit 4768226

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

.github/workflows/pipeline.yml

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,13 @@ jobs:
330330
- docker_build
331331
- helm_validate
332332
runs-on: ubuntu-latest
333+
# NOTE: pull-requests:read is needed to resolve the PR from the commit for
334+
# provenance annotations. A reusable workflow can only narrow the caller's
335+
# token, so the CALLER must also grant `pull-requests: read`.
336+
permissions:
337+
contents: read
338+
packages: write
339+
pull-requests: read
333340
defaults:
334341
run:
335342
working-directory: ${{ inputs.helm__chart_directory }}
@@ -418,17 +425,22 @@ jobs:
418425
419426
# PR metadata: helm publishes on push/tag (no PR context), so resolve
420427
# the PR from the commit. Omit these keys when the commit has no PR.
421-
PR_JSON="$(gh api "repos/${GITHUB_REPOSITORY}/commits/${GITHUB_SHA}/pulls" --jq '.[0] // empty' 2>/dev/null || true)"
422-
if [ -n "$PR_JSON" ]; then
423-
export PR_NUMBER PR_AUTHOR PR_AUTHOR_IMAGE_URL
424-
PR_NUMBER="$(echo "$PR_JSON" | jq -r '.number')"
425-
PR_AUTHOR="$(echo "$PR_JSON" | jq -r '.user.login')"
426-
PR_AUTHOR_IMAGE_URL="https://github.com/${PR_AUTHOR}.png"
427-
EXPR="${EXPR} | ${P}.\"${A}/pr-number\" = strenv(PR_NUMBER)"
428-
EXPR="${EXPR} | ${P}.\"${A}/pr-author\" = strenv(PR_AUTHOR)"
429-
EXPR="${EXPR} | ${P}.\"${A}/pr-author-image-url\" = strenv(PR_AUTHOR_IMAGE_URL)"
428+
# Requires `pull-requests: read`; a failed API call is surfaced (not
429+
# silently treated as "no PR") so a missing scope is diagnosable.
430+
if PR_JSON="$(gh api "repos/${GITHUB_REPOSITORY}/commits/${GITHUB_SHA}/pulls" --jq '.[0] // empty' 2>/tmp/gh_pr_err)"; then
431+
if [ -n "$PR_JSON" ]; then
432+
export PR_NUMBER PR_AUTHOR PR_AUTHOR_IMAGE_URL
433+
PR_NUMBER="$(echo "$PR_JSON" | jq -r '.number')"
434+
PR_AUTHOR="$(echo "$PR_JSON" | jq -r '.user.login')"
435+
PR_AUTHOR_IMAGE_URL="https://github.com/${PR_AUTHOR}.png"
436+
EXPR="${EXPR} | ${P}.\"${A}/pr-number\" = strenv(PR_NUMBER)"
437+
EXPR="${EXPR} | ${P}.\"${A}/pr-author\" = strenv(PR_AUTHOR)"
438+
EXPR="${EXPR} | ${P}.\"${A}/pr-author-image-url\" = strenv(PR_AUTHOR_IMAGE_URL)"
439+
else
440+
echo "::notice::No PR associated with ${GITHUB_SHA}; skipping pr-* annotations."
441+
fi
430442
else
431-
echo "::notice::No PR associated with ${GITHUB_SHA}; skipping pr-* annotations."
443+
echo "::warning::Could not query PRs for ${GITHUB_SHA} (does the token have 'pull-requests: read'?); skipping pr-* annotations. $(cat /tmp/gh_pr_err)"
432444
fi
433445
434446
yq -i "$EXPR" values.yaml

0 commit comments

Comments
 (0)