Skip to content

Commit 40ea02e

Browse files
authored
build(release): fetch PR body in get_pr_info and grant PR read permissions (#4177)
The release preparation completion workflow parses the merged PR body to locate the associated release tracking issue. Previously, the workflow failed to resolve the tracking issue because `get_pr_info` omitted the PR `body` field and the GitHub Actions workflow lacked permission to read pull requests. Request the `body` field when querying PR metadata and grant `pull-requests: read` permission to the workflow so it can extract the issue number from the merged preparation PR. Work towards #4175
1 parent 9cc620e commit 40ea02e

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

‎.github/workflows/release_complete_prepare.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ on:
2727
permissions:
2828
contents: write
2929
issues: write
30+
pull-requests: read
3031

3132
jobs:
3233
complete_prepare:

‎dev/release/gh.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,9 +731,9 @@ def get_pr_info(self, pr_num: int) -> PrDict:
731731
pr_num: The PR number.
732732
733733
Returns:
734-
Dictionary containing PR fields (state, isDraft, mergeCommit, etc.).
734+
Dictionary containing PR fields (state, isDraft, mergeCommit, body, etc.).
735735
"""
736-
output = self._gh_pr_view(pr_num, "state", "isDraft", "mergeCommit")
736+
output = self._gh_pr_view(pr_num, "state", "isDraft", "mergeCommit", "body")
737737
return json.loads(output) if output else {}
738738

739739
@override

‎tests/tools/private/release/gh_test.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,29 @@ def test_get_pr_files(gh, auto_patch_cmd_helpers):
122122
)
123123

124124

125+
def test_get_pr_info(gh, auto_patch_cmd_helpers):
126+
auto_patch_cmd_helpers.run_gh.return_value = (
127+
'{"state": "MERGED", "isDraft": false, '
128+
'"mergeCommit": {"oid": "abc1234"}, "body": "Work towards #4175"}'
129+
)
130+
info = gh.get_pr_info(123)
131+
assert info == {
132+
"state": "MERGED",
133+
"isDraft": False,
134+
"mergeCommit": {"oid": "abc1234"},
135+
"body": "Work towards #4175",
136+
}
137+
auto_patch_cmd_helpers.run_gh.assert_called_with(
138+
"pr",
139+
"view",
140+
"123",
141+
"--json=state,isDraft,mergeCommit,body",
142+
"--repo=my-owner/my-repo",
143+
check=True,
144+
capture_output=True,
145+
)
146+
147+
125148
def test_get_pr_files_not_found(gh, auto_patch_cmd_helpers):
126149
auto_patch_cmd_helpers.run_gh.side_effect = subprocess.CalledProcessError(1, ["gh"])
127150
with pytest.raises(GetPrError, match="Failed to get PR #123 on my-owner/my-repo"):

0 commit comments

Comments
 (0)