diff --git a/.github/workflows/merge-to-stage.js b/.github/workflows/merge-to-stage.js index 19ef68f570..833f6564ae 100644 --- a/.github/workflows/merge-to-stage.js +++ b/.github/workflows/merge-to-stage.js @@ -15,6 +15,7 @@ const LABELS = { highPriority: 'high priority', readyForStage: 'Ready for Stage', SOTPrefix: 'SOT', + zeroImpact: 'zero-impact', }; const TEAM_MENTIONS = [ '@adobecom/miq-sot', @@ -24,8 +25,8 @@ const TEAM_MENTIONS = [ '@adobecom/document-cloud-sot', ]; const SLACK = { - merge: ({ html_url, number, title }) => - `:merged: PR merged to stage: <${html_url}|${number}: ${title}>.`, + merge: ({ html_url, number, title, prefix = '' }) => + `:merged: PR merged to stage: ${prefix} <${html_url}|${number}: ${title}>.`, openedSyncPr: ({ html_url, number }) => `:fast_forward: Created <${html_url}|Stage to Main PR ${number}>`, }; @@ -46,6 +47,7 @@ let body = ` `; const isHighPrio = (labels) => labels.includes(LABELS.highPriority); +const isZeroImpact = (labels) => labels.includes(LABELS.zeroImpact); const hasFailingChecks = (checks) => checks.some( @@ -80,11 +82,23 @@ const getPRs = async () => { return true; }); - return prs.reverse(); // OLD PRs first + return prs.reverse().reduce( + (categorizedPRs, pr) => { + if (isZeroImpact(pr.labels)) { + categorizedPRs.zeroImpactPRs.push(pr); + } else if (isHighPrio(pr.labels)) { + categorizedPRs.highImpactPRs.push(pr); + } else { + categorizedPRs.normalPRs.push(pr); + } + return categorizedPRs; + }, + { zeroImpactPRs: [], highImpactPRs: [], normalPRs: [] } + ); }; -const merge = async ({ prs }) => { - console.log(`Merging ${prs.length || 0} PRs that are ready... `); +const merge = async ({ prs, type }) => { + console.log(`Merging ${prs.length || 0} ${type} PRs that are ready... `); for await (const { number, files, html_url, title } of prs) { try { @@ -92,7 +106,10 @@ const merge = async ({ prs }) => { console.log(`Skipping ${number}: ${title} due to overlap in files.`); continue; } - files.forEach((file) => (SEEN[file] = true)); + if (type !== LABELS.zeroImpact) { + files.forEach((file) => (SEEN[file] = true)); + } + if (!process.env.LOCAL_RUN) { await github.rest.pulls.merge({ owner, @@ -101,12 +118,14 @@ const merge = async ({ prs }) => { merge_method: 'squash', }); } - body = `- ${html_url}\n${body}`; + const prefix = type === LABELS.zeroImpact ? ' [ZERO IMPACT]' : ''; + body = `-${prefix} ${html_url}\n${body}`; await slackNotification( SLACK.merge({ html_url, number, title, + prefix, }) ); await new Promise((resolve) => setTimeout(resolve, 5000)); @@ -185,11 +204,12 @@ const main = async (params) => { const stageToMainPR = await getStageToMainPR(); console.log('has Stage to Main PR:', !!stageToMainPR); if (stageToMainPR) body = stageToMainPR.body; + const { zeroImpactPRs, highImpactPRs, normalPRs } = await getPRs(); + await merge({ prs: zeroImpactPRs, type: LABELS.zeroImpact }); if (stageToMainPR?.labels.some((label) => label.includes(LABELS.SOTPrefix))) return console.log('PR exists & testing started. Stopping execution.'); - const prs = await getPRs(); - await merge({ prs: prs.filter(({ labels }) => isHighPrio(labels)) }); - await merge({ prs: prs.filter(({ labels }) => !isHighPrio(labels)) }); + await merge({ prs: highImpactPRs, type: LABELS.highPriority }); + await merge({ prs: normalPRs, type: 'normal' }); if (!stageToMainPR) await openStageToMainPR(); if (stageToMainPR && body !== stageToMainPR.body) { console.log("Updating PR's body...");