You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/action.mjs
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -88,7 +88,7 @@ fragment PR on PullRequest {
88
88
baseRef { name }
89
89
headRef { name }
90
90
}
91
-
`,Zb=[],Xb=[];switch(process.env.GITHUB_EVENT_NAME){case"push":case"workflow_dispatch":await uW();break;case"pull_request":case"pull_request_target":await lW();break;default:throw new Error(`Event ${process.env.GITHUB_EVENT_NAME} is not supported. Only push, workflow_dispatch, pull_request, and pull_request_target are supported.`)}LA.default.setOutput("updated-prs",Zb.join(","));LA.default.setOutput("conflicted-prs",Xb.join(","));async function uW(){Ei.isString.assert(process.env.GITHUB_EVENT_PATH);let{ref:e,repository:A}=JSON.parse(await Hb.readFile(process.env.GITHUB_EVENT_PATH)),t="refs/heads/";if(!e.startsWith(t))return;let r=e.slice(t.length),s={repo:A.name,owner:A.owner.name??A.owner.login};await Cu(5e3);let o=`repo:${s.owner}/${s.repo} is:open is:pr base:${r}`;for await(let n of IW({search:o}))await Bu(s,n)}async function lW(){Ei.isString.assert(process.env.GITHUB_EVENT_PATH);let{action:e,number:A,repository:t}=JSON.parse(await Hb.readFile(process.env.GITHUB_EVENT_PATH)),r={repo:t.name,owner:t.owner.name??t.owner.login};(e==="opened"||e==="synchronize")&&await Cu(5e3);let s=await Kb({...r,number:A});await Bu(r,s)}async function Bu(e,A){switch(A.mergeable){case"CONFLICTING":await BW(e,A);break;case"MERGEABLE":{let t=[hW(e,A),QW(e,A)];await Promise.all(t);break}case"UNKNOWN":{console.info(`[PR ${A.number}] Conflict state is not yet known. Retrying.`),await Cu(1e3);let t=await Kb({...e,number:A.number});await Bu(e,t);break}}}function gi(e,A){return e.labels.nodes.some(t=>A.includes(t.name))}async function QW(e,A){if(!aW)return;if(cW&&!A.autoMergeRequest){console.info(`[${A.number}] Auto-merge is not enabled, skipping update.`);return}if(uu.length>0&&!gi(A,uu)){console.info(`[${A.number}] Does not any of the labels (${uu}), skipping update.`);return}if(lu.length>0&&gi(A,lu)){console.info(`[${A.number}] Has one of the excluded (${lu}), skipping update.`);return}if(EW.includes(zb(A.author))){console.info(`[${A.number}] Was created by an excluded author, skipping update.`);return}if(!$b(A,gW)){console.info(`[${A.number}] Not in the expected ready state, skipping update.`);return}if(await CW(e,A)&&(Zb.push(A.number),console.info(`[${A.number}] \u2705 Updating branch.`),!ci))return oW.rest.pulls.updateBranch({...e,pull_number:A.number})}async function CW(e,A){return(await Ot.graphql(`
91
+
`,Zb=[],Xb=[];switch(process.env.GITHUB_EVENT_NAME){case"push":case"workflow_dispatch":await uW();break;case"pull_request":case"pull_request_target":await lW();break;default:throw new Error(`Event ${process.env.GITHUB_EVENT_NAME} is not supported. Only push, workflow_dispatch, pull_request, and pull_request_target are supported.`)}LA.default.setOutput("updated-prs",Zb.join(","));LA.default.setOutput("conflicted-prs",Xb.join(","));async function uW(){Ei.isString.assert(process.env.GITHUB_EVENT_PATH);let{ref:e,repository:A}=JSON.parse(await Hb.readFile(process.env.GITHUB_EVENT_PATH)),t="refs/heads/";if(!e.startsWith(t))return;let r=e.slice(t.length),s={repo:A.name,owner:A.owner.name??A.owner.login};await Cu(1e4);let o=`repo:${s.owner}/${s.repo} is:open is:pr base:${r}`;for await(let n of IW({search:o}))console.info(`Handling PRs ${n.map(i=>i.number).join(", ")}`),await Promise.all(n.map(async i=>Bu(s,i)))}async function lW(){Ei.isString.assert(process.env.GITHUB_EVENT_PATH);let{action:e,number:A,repository:t}=JSON.parse(await Hb.readFile(process.env.GITHUB_EVENT_PATH)),r={repo:t.name,owner:t.owner.name??t.owner.login};(e==="opened"||e==="synchronize")&&await Cu(5e3);let s=await Kb({...r,number:A});await Bu(r,s)}async function Bu(e,A){switch(A.mergeable){case"CONFLICTING":await BW(e,A);break;case"MERGEABLE":{let t=[hW(e,A),QW(e,A)];await Promise.all(t);break}case"UNKNOWN":{console.info(`[PR ${A.number}] Conflict state is not yet known. Retrying.`),await Cu(1e3);let t=await Kb({...e,number:A.number});await Bu(e,t);break}}}function gi(e,A){return e.labels.nodes.some(t=>A.includes(t.name))}async function QW(e,A){if(!aW)return;if(cW&&!A.autoMergeRequest){console.info(`[${A.number}] Auto-merge is not enabled, skipping update.`);return}if(uu.length>0&&!gi(A,uu)){console.info(`[${A.number}] Does not any of the labels (${uu}), skipping update.`);return}if(lu.length>0&&gi(A,lu)){console.info(`[${A.number}] Has one of the excluded (${lu}), skipping update.`);return}if(EW.includes(zb(A.author))){console.info(`[${A.number}] Was created by an excluded author, skipping update.`);return}if(!$b(A,gW)){console.info(`[${A.number}] Not in the expected ready state, skipping update.`);return}if(await CW(e,A)&&(Zb.push(A.number),console.info(`[${A.number}] \u2705 Updating branch.`),!ci))return oW.rest.pulls.updateBranch({...e,pull_number:A.number})}async function CW(e,A){return(await Ot.graphql(`
`,{...e,cursor:A});for(let r of t.search.nodes)yield r;if(!t.search.pageInfo.hasNextPage)break;A=t.search.pageInfo.endCursor}}function zb(e){return e.__typename==="Bot"?`app/${e.login}`:e.login}function $b(e,A){switch(A){case"all":return!0;case"draft":return e.isDraft;case"ready_for_review":return!e.isDraft}}function eD(e){return $b(e,nW)?gu.length>0&&!gi(e,gu)?(console.info(`[${e.number}] Does not any of the labels (${gu}), skipping conflict handling.`),!1):Eu.length>0&&gi(e,Eu)?(console.info(`[${e.number}] Has one of the excluded (${Eu}), skipping conflict handling.`),!1):iW.includes(zb(e.author))?(console.info(`[${e.number}] Was created by an excluded author, skipping conflict handling.`),!1):!0:(console.info(`[${e.number}] Not in the expected ready state, skipping conflict handling.`),!1)}
129
+
`,{...e,cursor:A});if(yield t.search.nodes,!t.search.pageInfo.hasNextPage)break;A=t.search.pageInfo.endCursor}}function zb(e){return e.__typename==="Bot"?`app/${e.login}`:e.login}function $b(e,A){switch(A){case"all":return!0;case"draft":return e.isDraft;case"ready_for_review":return!e.isDraft}}function eD(e){return $b(e,nW)?gu.length>0&&!gi(e,gu)?(console.info(`[${e.number}] Does not any of the labels (${gu}), skipping conflict handling.`),!1):Eu.length>0&&gi(e,Eu)?(console.info(`[${e.number}] Has one of the excluded (${Eu}), skipping conflict handling.`),!1):iW.includes(zb(e.author))?(console.info(`[${e.number}] Was created by an excluded author, skipping conflict handling.`),!1):!0:(console.info(`[${e.number}] Not in the expected ready state, skipping conflict handling.`),!1)}
0 commit comments