Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 643fee9

Browse files
fix(.github/workflows): manage the refresh PR through the REST API
gh pr list/create/edit go through GraphQL, whose queries resolve reviewer and team fields that require the read:org scope. cdrci's token carries only repo and workflow, so the calls succeed while no pull request exists and fail once CODEOWNERS attaches a reviewer: the first refresh would open a PR and every run after it would fail. Observed on this branch: run 32058047624 created #28224, then 32058781222 and 32059086614 both failed on gh pr list with a read:org scope error. The equivalent REST endpoints need only repo.
1 parent c8f49c4 commit 643fee9

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

.github/workflows/aigateway-prices-refresh.yaml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,25 @@ jobs:
138138
# snapshot each week, so the previous contents are always stale.
139139
git push --force origin "refs/heads/${REFRESH_BRANCH}"
140140
141-
pr_number="$(gh pr list --head "${REFRESH_BRANCH}" --base main --state open --json number --jq '.[0].number // empty')"
141+
# REST rather than `gh pr list/create/edit`: those go through
142+
# GraphQL, whose queries resolve reviewer and team fields that need
143+
# the read:org scope. cdrci's token has only repo and workflow, so
144+
# they fail as soon as the pull request has a requested reviewer.
145+
owner="${GITHUB_REPOSITORY%%/*}"
146+
pr_number="$(gh api "repos/${GITHUB_REPOSITORY}/pulls?state=open&base=main&head=${owner}:${REFRESH_BRANCH}" --jq '.[0].number // empty')"
142147
if [ -n "${pr_number}" ]; then
143-
gh pr edit "${pr_number}" --title "${PR_TITLE}" --body-file "${RUNNER_TEMP}/body.md"
148+
gh api --method PATCH "repos/${GITHUB_REPOSITORY}/pulls/${pr_number}" \
149+
-f title="${PR_TITLE}" \
150+
-f body="$(cat "${RUNNER_TEMP}/body.md")" \
151+
--silent
144152
echo "Updated existing PR #${pr_number}."
145153
else
146-
gh pr create \
147-
--base main \
148-
--head "${REFRESH_BRANCH}" \
149-
--title "${PR_TITLE}" \
150-
--body-file "${RUNNER_TEMP}/body.md"
154+
gh api --method POST "repos/${GITHUB_REPOSITORY}/pulls" \
155+
-f title="${PR_TITLE}" \
156+
-f head="${REFRESH_BRANCH}" \
157+
-f base=main \
158+
-f body="$(cat "${RUNNER_TEMP}/body.md")" \
159+
--jq '.html_url'
151160
fi
152161
153162
- name: Send Slack notification on failure

0 commit comments

Comments
 (0)