File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -108,17 +108,27 @@ jobs:
108108 if (!passed) {
109109 try {
110110 const pat = process.env.DRAFT_PAT;
111- await github.graphql(
112- `mutation ($id: ID!) {
113- convertPullRequestToDraft(input: { pullRequestId: $id }) {
114- pullRequest { isDraft }
115- }
116- }`,
117- {
118- id: pr.node_id,
119- ...(pat ? { headers: { authorization: `Bearer ${pat}` } } : {}),
111+ if (!pat) throw new Error('PR_GOVERNANCE_PAT is not configured');
112+ // 不走 github.graphql:octokit 的 auth 钩子会强制覆盖 authorization 头,传入的 PAT 会被 GITHUB_TOKEN 顶掉,而该 mutation 不接受 integration token。
113+ const res = await fetch('https://api.github.com/graphql', {
114+ method: 'POST',
115+ headers: {
116+ authorization: `Bearer ${pat}`,
117+ 'content-type': 'application/json',
120118 },
121- );
119+ body: JSON.stringify({
120+ query: `mutation ($id: ID!) {
121+ convertPullRequestToDraft(input: { pullRequestId: $id }) {
122+ pullRequest { isDraft }
123+ }
124+ }`,
125+ variables: { id: pr.node_id },
126+ }),
127+ });
128+ const out = await res.json();
129+ if (!res.ok || out.errors?.length) {
130+ throw new Error(out.errors?.map((e) => e.message).join('; ') || `HTTP ${res.status}`);
131+ }
122132 drafted = true;
123133 } catch (e) {
124134 core.warning(`Failed to convert to draft (${e.message}); the check is still red and merge blocking is unaffected.`);
You can’t perform that action at this time.
0 commit comments