Skip to content

Commit 7c5f9f5

Browse files
fix(ci): Use gh CLI to convert PR to draft (#5874)
The GraphQL `convertPullRequestToDraft` mutation doesn't work with GitHub App installation tokens ("Resource not accessible by integration"). This switches to `gh pr ready --undo` which handles the auth correctly via the `GH_TOKEN` env var. Also splits the workflow into two steps: draft conversion via `gh` CLI, then labeling + commenting via `actions/github-script`. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 11b8262 commit 7c5f9f5

1 file changed

Lines changed: 7 additions & 18 deletions

File tree

.github/workflows/enforce-draft-pr.yml

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,20 @@ jobs:
1818
private-key: ${{ secrets.SDK_MAINTAINER_BOT_PRIVATE_KEY }}
1919

2020
- name: Convert PR to draft
21+
env:
22+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
23+
PR_URL: ${{ github.event.pull_request.html_url }}
24+
run: |
25+
gh pr ready "$PR_URL" --undo
26+
27+
- name: Label and comment
2128
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
2229
with:
2330
github-token: ${{ steps.app-token.outputs.token }}
2431
script: |
2532
const pullRequest = context.payload.pull_request;
2633
const repo = context.repo;
2734
28-
// Convert to draft via GraphQL (REST API doesn't support this)
29-
try {
30-
await github.graphql(`
31-
mutation($pullRequestId: ID!) {
32-
convertPullRequestToDraft(input: { pullRequestId: $pullRequestId }) {
33-
pullRequest {
34-
isDraft
35-
}
36-
}
37-
}
38-
`, {
39-
pullRequestId: pullRequest.node_id
40-
});
41-
} catch (error) {
42-
core.warning(`Failed to convert PR to draft: ${error.message}`);
43-
return;
44-
}
45-
4635
// Label the PR so maintainers can filter/track violations
4736
await github.rest.issues.addLabels({
4837
...repo,

0 commit comments

Comments
 (0)