From 08600707aefe512c3ddb6110e02161ea4f1acad5 Mon Sep 17 00:00:00 2001 From: Alice Zhao Date: Sun, 21 Apr 2024 11:14:39 -0700 Subject: [PATCH 1/6] fix: Ensure backport-requested is not added is approved label exists --- src/constants.ts | 2 ++ src/utils.ts | 42 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index bfc0e6f..33f03e5 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -25,5 +25,7 @@ export const SKIP_CHECK_LABEL = export const BACKPORT_REQUESTED_LABEL = process.env.BACKPORT_REQUESTED_LABEL || 'backport/requested 🗳'; +export const BACKPORT_APPROVED_LABEL = 'backport/approved ✅'; + export const DEFAULT_BACKPORT_REVIEW_TEAM = process.env.DEFAULT_BACKPORT_REVIEW_TEAM; diff --git a/src/utils.ts b/src/utils.ts index 7ec29cd..e94fcf4 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -8,6 +8,7 @@ import { BACKPORT_REQUESTED_LABEL, DEFAULT_BACKPORT_REVIEW_TEAM, BACKPORT_LABEL, + BACKPORT_APPROVED_LABEL, } from './constants'; import { PRStatus, BackportPurpose, LogLevel, PRChange } from './enums'; @@ -640,14 +641,12 @@ export const backportImpl = async ( const labelsToAdd = [BACKPORT_LABEL, `${targetBranch}`]; - if (await isSemverMinorPR(context, pr)) { - log( - 'backportImpl', - LogLevel.INFO, - `Determined that ${pr.number} is semver-minor`, - ); - labelsToAdd.push(BACKPORT_REQUESTED_LABEL); - } + await handleSemverMinorBackportLabel( + context, + pr, + labelsToAdd, + 'backportImpl', + ); const semverLabel = labelUtils.getSemverLabel(pr); if (semverLabel) { @@ -787,3 +786,30 @@ export const backportImpl = async ( }, ); }; + +export const handleSemverMinorBackportLabel = async ( + context: SimpleWebHookRepoContext, + pr: WebHookPR, + labelsToAdd: string[], + functionName: string, +) => { + if (!(await isSemverMinorPR(context, pr))) { + return; + } + + log( + functionName, + LogLevel.INFO, + `Determined that ${pr.number} is semver-minor`, + ); + // Check to see if backport has already been approved. + const hasApprovedLabel = await labelUtils.labelExistsOnPR( + context, + pr.number, + BACKPORT_APPROVED_LABEL, + ); + + if (!hasApprovedLabel) { + labelsToAdd.push(BACKPORT_REQUESTED_LABEL); + } +}; From 5b3b97ea6f37abec62d592a646c52e6cf346e244 Mon Sep 17 00:00:00 2001 From: Alice Zhao Date: Sun, 21 Apr 2024 11:15:03 -0700 Subject: [PATCH 2/6] test: update tests for new helper function --- spec/operations.spec.ts | 3 +- spec/utils.spec.ts | 66 +++++++++++++++++++++++- src/operations/update-manual-backport.ts | 22 +++----- 3 files changed, 74 insertions(+), 17 deletions(-) diff --git a/spec/operations.spec.ts b/spec/operations.spec.ts index 1f4c971..d5d853a 100644 --- a/spec/operations.spec.ts +++ b/spec/operations.spec.ts @@ -22,8 +22,9 @@ const backportPRMergedEvent = require('./fixtures/backport_pull_request.merged.j const backportPROpenedEvent = require('./fixtures/backport_pull_request.opened.json'); jest.mock('../src/utils', () => ({ - tagBackportReviewers: jest.fn().mockReturnValue(Promise.resolve()), + tagBackportReviewers: jest.fn(), isSemverMinorPR: jest.fn().mockReturnValue(false), + handleSemverMinorBackportLabel: jest.fn(), })); jest.mock('../src/utils/label-utils', () => ({ diff --git a/spec/utils.spec.ts b/spec/utils.spec.ts index 2fb7b03..790ef43 100644 --- a/spec/utils.spec.ts +++ b/spec/utils.spec.ts @@ -1,6 +1,12 @@ -import * as logUtils from '../src/utils/log-util'; +import { BACKPORT_REQUESTED_LABEL } from '../src/constants'; import { LogLevel } from '../src/enums'; -import { tagBackportReviewers } from '../src/utils'; +import { + handleSemverMinorBackportLabel, + tagBackportReviewers, +} from '../src/utils'; +import * as utils from '../src/utils'; +import * as labelUtils from '../src/utils/label-utils'; +import * as logUtils from '../src/utils/log-util'; const backportPROpenedEvent = require('./fixtures/backport_pull_request.opened.json'); @@ -74,4 +80,60 @@ describe('utils', () => { ); }); }); + + describe('handleSemverMinorBackportLabel()', () => { + const context = { + octokit: {}, + repo: {}, + ...backportPROpenedEvent, + }; + const pr = context.payload.pull_request; + let labelsToAdd: string[]; + + beforeEach(() => { + labelsToAdd = []; + }); + + it('should add BACKPORT_REQUESTED_LABEL if PR is semver minor and not already approved', async () => { + jest.spyOn(labelUtils, 'labelExistsOnPR').mockResolvedValue(false); + jest.spyOn(utils, 'isSemverMinorPR').mockResolvedValue(true); + + await handleSemverMinorBackportLabel( + context, + pr, + labelsToAdd, + 'testFunction', + ); + expect(labelsToAdd).toContain(BACKPORT_REQUESTED_LABEL); + }); + + it('should not add BACKPORT_REQUESTED_LABEL if PR is not semver minor', async () => { + jest.spyOn(utils, 'isSemverMinorPR').mockResolvedValue(false); + + await handleSemverMinorBackportLabel( + context, + pr, + labelsToAdd, + 'testFunction', + ); + + expect(labelsToAdd).not.toContain(BACKPORT_REQUESTED_LABEL); + }); + + it('should not add BACKPORT_REQUESTED_LABEL if PR is already approved', async () => { + jest.spyOn(utils, 'isSemverMinorPR').mockResolvedValue(true); + + // Mocking labelExistsOnPR to return true (indicating backport is already approved) + jest.spyOn(labelUtils, 'labelExistsOnPR').mockResolvedValue(true); + + await handleSemverMinorBackportLabel( + context, + pr, + labelsToAdd, + 'testFunction', + ); + + expect(labelsToAdd).not.toContain(BACKPORT_REQUESTED_LABEL); + }); + }); }); diff --git a/src/operations/update-manual-backport.ts b/src/operations/update-manual-backport.ts index d2b1b67..0388f01 100644 --- a/src/operations/update-manual-backport.ts +++ b/src/operations/update-manual-backport.ts @@ -1,11 +1,7 @@ -import { - BACKPORT_LABEL, - BACKPORT_REQUESTED_LABEL, - SKIP_CHECK_LABEL, -} from '../constants'; +import { BACKPORT_LABEL, SKIP_CHECK_LABEL } from '../constants'; import { PRChange, PRStatus, LogLevel } from '../enums'; import { WebHookPRContext } from '../types'; -import { isSemverMinorPR, tagBackportReviewers } from '../utils'; +import { handleSemverMinorBackportLabel, tagBackportReviewers } from '../utils'; import * as labelUtils from '../utils/label-utils'; import { log } from '../utils/log-util'; @@ -98,14 +94,12 @@ export const updateManualBackport = async ( } } - if (await isSemverMinorPR(context, pr)) { - log( - 'updateManualBackport', - LogLevel.INFO, - `Determined that ${pr.number} is semver-minor`, - ); - newPRLabelsToAdd.push(BACKPORT_REQUESTED_LABEL); - } + await handleSemverMinorBackportLabel( + context, + pr, + newPRLabelsToAdd, + 'updateManualBackport', + ); // We should only comment if there is not a previous existing comment const commentBody = `@${pr.user.login} has manually backported this PR to "${pr.base.ref}", \ From 3d8ab2b9c271961932d37cbd5989410eca8c045f Mon Sep 17 00:00:00 2001 From: Alice Zhao Date: Sun, 21 Apr 2024 11:33:29 -0700 Subject: [PATCH 3/6] refactor: add log message --- src/utils.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/utils.ts b/src/utils.ts index e94fcf4..e99bd8e 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -811,5 +811,12 @@ export const handleSemverMinorBackportLabel = async ( if (!hasApprovedLabel) { labelsToAdd.push(BACKPORT_REQUESTED_LABEL); + return; } + + log( + functionName, + LogLevel.WARN, + `The backport for ${pr.number} has already been approved. No requested label added.`, + ); }; From fd83070c0e9ea134a491a9cbab205c5ca58c125d Mon Sep 17 00:00:00 2001 From: Alice Zhao Date: Sun, 21 Apr 2024 11:44:51 -0700 Subject: [PATCH 4/6] refactor: update constants format --- spec/utils.spec.ts | 10 +++++----- src/constants.ts | 12 +++++------- src/index.ts | 12 +++++++++--- src/operations/update-manual-backport.ts | 4 ++-- src/utils.ts | 9 ++++----- 5 files changed, 25 insertions(+), 22 deletions(-) diff --git a/spec/utils.spec.ts b/spec/utils.spec.ts index 790ef43..57a8e3c 100644 --- a/spec/utils.spec.ts +++ b/spec/utils.spec.ts @@ -1,4 +1,4 @@ -import { BACKPORT_REQUESTED_LABEL } from '../src/constants'; +import { BACKPORT_REVIEW_LABELS } from '../src/constants'; import { LogLevel } from '../src/enums'; import { handleSemverMinorBackportLabel, @@ -104,10 +104,10 @@ describe('utils', () => { labelsToAdd, 'testFunction', ); - expect(labelsToAdd).toContain(BACKPORT_REQUESTED_LABEL); + expect(labelsToAdd).toContain(BACKPORT_REVIEW_LABELS.REQUESTED); }); - it('should not add BACKPORT_REQUESTED_LABEL if PR is not semver minor', async () => { + it('should not add BACKPORT_REVIEW_LABELS.REQUESTED if PR is not semver minor', async () => { jest.spyOn(utils, 'isSemverMinorPR').mockResolvedValue(false); await handleSemverMinorBackportLabel( @@ -117,7 +117,7 @@ describe('utils', () => { 'testFunction', ); - expect(labelsToAdd).not.toContain(BACKPORT_REQUESTED_LABEL); + expect(labelsToAdd).not.toContain(BACKPORT_REVIEW_LABELS.REQUESTED); }); it('should not add BACKPORT_REQUESTED_LABEL if PR is already approved', async () => { @@ -133,7 +133,7 @@ describe('utils', () => { 'testFunction', ); - expect(labelsToAdd).not.toContain(BACKPORT_REQUESTED_LABEL); + expect(labelsToAdd).not.toContain(BACKPORT_REVIEW_LABELS.REQUESTED); }); }); }); diff --git a/src/constants.ts b/src/constants.ts index 33f03e5..d9ad40f 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -19,13 +19,11 @@ export const SEMVER_LABELS = { MAJOR: 'semver/major', }; -export const SKIP_CHECK_LABEL = - process.env.SKIP_CHECK_LABEL || 'backport-check-skip'; - -export const BACKPORT_REQUESTED_LABEL = - process.env.BACKPORT_REQUESTED_LABEL || 'backport/requested 🗳'; - -export const BACKPORT_APPROVED_LABEL = 'backport/approved ✅'; +export const BACKPORT_REVIEW_LABELS = { + SKIP: process.env.SKIP_CHECK_LABEL || 'backport-check-skip', + REQUESTED: process.env.BACKPORT_REQUESTED_LABEL || 'backport/requested 🗳', + APPROVED: 'backport/approved ✅', +}; export const DEFAULT_BACKPORT_REVIEW_TEAM = process.env.DEFAULT_BACKPORT_REVIEW_TEAM; diff --git a/src/index.ts b/src/index.ts index 1bbfd93..2c4073c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,7 +11,11 @@ import { labelExistsOnPR, removeLabel, } from './utils/label-utils'; -import { CHECK_PREFIX, NO_BACKPORT_LABEL, SKIP_CHECK_LABEL } from './constants'; +import { + BACKPORT_REVIEW_LABELS, + CHECK_PREFIX, + NO_BACKPORT_LABEL, +} from './constants'; import { getEnvVar } from './utils/env-util'; import { PRChange, PRStatus, BackportPurpose, CheckRunStatus } from './enums'; import { Label } from '@octokit/webhooks-types'; @@ -251,9 +255,11 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => { // If a branch is targeting something that isn't main it might not be a backport; // allow for a label to skip backport validity check for these branches. - if (await labelExistsOnPR(context, pr.number, SKIP_CHECK_LABEL)) { + if ( + await labelExistsOnPR(context, pr.number, BACKPORT_REVIEW_LABELS.SKIP) + ) { robot.log( - `#${pr.number} is labeled with ${SKIP_CHECK_LABEL} - skipping backport validation check`, + `#${pr.number} is labeled with ${BACKPORT_REVIEW_LABELS.SKIP} - skipping backport validation check`, ); await updateBackportValidityCheck(context, checkRun, { title: 'Backport Check Skipped', diff --git a/src/operations/update-manual-backport.ts b/src/operations/update-manual-backport.ts index 0388f01..0554f90 100644 --- a/src/operations/update-manual-backport.ts +++ b/src/operations/update-manual-backport.ts @@ -1,4 +1,4 @@ -import { BACKPORT_LABEL, SKIP_CHECK_LABEL } from '../constants'; +import { BACKPORT_LABEL, BACKPORT_REVIEW_LABELS } from '../constants'; import { PRChange, PRStatus, LogLevel } from '../enums'; import { WebHookPRContext } from '../types'; import { handleSemverMinorBackportLabel, tagBackportReviewers } from '../utils'; @@ -55,7 +55,7 @@ export const updateManualBackport = async ( const skipCheckLabelExists = await labelUtils.labelExistsOnPR( context, pr.number, - SKIP_CHECK_LABEL, + BACKPORT_REVIEW_LABELS.SKIP, ); if (!skipCheckLabelExists) { newPRLabelsToAdd.push(BACKPORT_LABEL); diff --git a/src/utils.ts b/src/utils.ts index e99bd8e..ba830a1 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -5,10 +5,9 @@ import simpleGit from 'simple-git'; import queue from './Queue'; import { - BACKPORT_REQUESTED_LABEL, - DEFAULT_BACKPORT_REVIEW_TEAM, BACKPORT_LABEL, - BACKPORT_APPROVED_LABEL, + BACKPORT_REVIEW_LABELS, + DEFAULT_BACKPORT_REVIEW_TEAM, } from './constants'; import { PRStatus, BackportPurpose, LogLevel, PRChange } from './enums'; @@ -806,11 +805,11 @@ export const handleSemverMinorBackportLabel = async ( const hasApprovedLabel = await labelUtils.labelExistsOnPR( context, pr.number, - BACKPORT_APPROVED_LABEL, + BACKPORT_REVIEW_LABELS.APPROVED, ); if (!hasApprovedLabel) { - labelsToAdd.push(BACKPORT_REQUESTED_LABEL); + labelsToAdd.push(BACKPORT_REVIEW_LABELS.REQUESTED); return; } From 2740c020d1b7c362b82bb27ef61023bdc5d0a4f7 Mon Sep 17 00:00:00 2001 From: Alice Zhao Date: Mon, 22 Apr 2024 16:36:09 -0700 Subject: [PATCH 5/6] refactor: update helper to return boolean instead of modifying array --- spec/operations.spec.ts | 2 +- spec/utils.spec.ts | 37 +++++------------------- src/operations/update-manual-backport.ts | 17 ++++++----- src/utils.ts | 37 ++++++++---------------- 4 files changed, 31 insertions(+), 62 deletions(-) diff --git a/spec/operations.spec.ts b/spec/operations.spec.ts index d5d853a..5bb7c51 100644 --- a/spec/operations.spec.ts +++ b/spec/operations.spec.ts @@ -24,7 +24,7 @@ const backportPROpenedEvent = require('./fixtures/backport_pull_request.opened.j jest.mock('../src/utils', () => ({ tagBackportReviewers: jest.fn(), isSemverMinorPR: jest.fn().mockReturnValue(false), - handleSemverMinorBackportLabel: jest.fn(), + needsSemverMinorBackportLabel: jest.fn().mockReturnValue(false), })); jest.mock('../src/utils/label-utils', () => ({ diff --git a/spec/utils.spec.ts b/spec/utils.spec.ts index 57a8e3c..d70ffcb 100644 --- a/spec/utils.spec.ts +++ b/spec/utils.spec.ts @@ -1,7 +1,6 @@ -import { BACKPORT_REVIEW_LABELS } from '../src/constants'; import { LogLevel } from '../src/enums'; import { - handleSemverMinorBackportLabel, + needsSemverMinorBackportLabel, tagBackportReviewers, } from '../src/utils'; import * as utils from '../src/utils'; @@ -81,7 +80,7 @@ describe('utils', () => { }); }); - describe('handleSemverMinorBackportLabel()', () => { + describe('needsSemverMinorBackportLabel()', () => { const context = { octokit: {}, repo: {}, @@ -94,46 +93,26 @@ describe('utils', () => { labelsToAdd = []; }); - it('should add BACKPORT_REQUESTED_LABEL if PR is semver minor and not already approved', async () => { + it('should should return true if PR is semver minor and not already approved', async () => { jest.spyOn(labelUtils, 'labelExistsOnPR').mockResolvedValue(false); jest.spyOn(utils, 'isSemverMinorPR').mockResolvedValue(true); - await handleSemverMinorBackportLabel( - context, - pr, - labelsToAdd, - 'testFunction', - ); - expect(labelsToAdd).toContain(BACKPORT_REVIEW_LABELS.REQUESTED); + expect(await needsSemverMinorBackportLabel(context, pr)).toBe(true); }); - it('should not add BACKPORT_REVIEW_LABELS.REQUESTED if PR is not semver minor', async () => { + it('should return false if PR is not semver minor', async () => { jest.spyOn(utils, 'isSemverMinorPR').mockResolvedValue(false); - await handleSemverMinorBackportLabel( - context, - pr, - labelsToAdd, - 'testFunction', - ); - - expect(labelsToAdd).not.toContain(BACKPORT_REVIEW_LABELS.REQUESTED); + expect(await needsSemverMinorBackportLabel(context, pr)).toBe(false); }); - it('should not add BACKPORT_REQUESTED_LABEL if PR is already approved', async () => { + it('should return false if PR is already approved', async () => { jest.spyOn(utils, 'isSemverMinorPR').mockResolvedValue(true); // Mocking labelExistsOnPR to return true (indicating backport is already approved) jest.spyOn(labelUtils, 'labelExistsOnPR').mockResolvedValue(true); - await handleSemverMinorBackportLabel( - context, - pr, - labelsToAdd, - 'testFunction', - ); - - expect(labelsToAdd).not.toContain(BACKPORT_REVIEW_LABELS.REQUESTED); + expect(await needsSemverMinorBackportLabel(context, pr)).toBe(false); }); }); }); diff --git a/src/operations/update-manual-backport.ts b/src/operations/update-manual-backport.ts index 0554f90..e7f1d77 100644 --- a/src/operations/update-manual-backport.ts +++ b/src/operations/update-manual-backport.ts @@ -1,7 +1,7 @@ import { BACKPORT_LABEL, BACKPORT_REVIEW_LABELS } from '../constants'; import { PRChange, PRStatus, LogLevel } from '../enums'; import { WebHookPRContext } from '../types'; -import { handleSemverMinorBackportLabel, tagBackportReviewers } from '../utils'; +import { needsSemverMinorBackportLabel, tagBackportReviewers } from '../utils'; import * as labelUtils from '../utils/label-utils'; import { log } from '../utils/log-util'; @@ -94,12 +94,15 @@ export const updateManualBackport = async ( } } - await handleSemverMinorBackportLabel( - context, - pr, - newPRLabelsToAdd, - 'updateManualBackport', - ); + if (await needsSemverMinorBackportLabel(context, pr)) { + log( + 'updateManualBackport', + LogLevel.INFO, + `Determined that ${pr.number} is semver-minor and needs backport review`, + ); + + newPRLabelsToAdd.push(BACKPORT_REVIEW_LABELS.REQUESTED); + } // We should only comment if there is not a previous existing comment const commentBody = `@${pr.user.login} has manually backported this PR to "${pr.base.ref}", \ diff --git a/src/utils.ts b/src/utils.ts index ba830a1..0554b30 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -640,12 +640,15 @@ export const backportImpl = async ( const labelsToAdd = [BACKPORT_LABEL, `${targetBranch}`]; - await handleSemverMinorBackportLabel( - context, - pr, - labelsToAdd, - 'backportImpl', - ); + if (await needsSemverMinorBackportLabel(context, pr)) { + log( + 'backportImpl', + LogLevel.INFO, + `Determined that ${pr.number} is semver-minor and needs backport review`, + ); + + labelsToAdd.push(BACKPORT_REVIEW_LABELS.REQUESTED); + } const semverLabel = labelUtils.getSemverLabel(pr); if (semverLabel) { @@ -786,21 +789,14 @@ export const backportImpl = async ( ); }; -export const handleSemverMinorBackportLabel = async ( +export const needsSemverMinorBackportLabel = async ( context: SimpleWebHookRepoContext, pr: WebHookPR, - labelsToAdd: string[], - functionName: string, ) => { if (!(await isSemverMinorPR(context, pr))) { - return; + return false; } - log( - functionName, - LogLevel.INFO, - `Determined that ${pr.number} is semver-minor`, - ); // Check to see if backport has already been approved. const hasApprovedLabel = await labelUtils.labelExistsOnPR( context, @@ -808,14 +804,5 @@ export const handleSemverMinorBackportLabel = async ( BACKPORT_REVIEW_LABELS.APPROVED, ); - if (!hasApprovedLabel) { - labelsToAdd.push(BACKPORT_REVIEW_LABELS.REQUESTED); - return; - } - - log( - functionName, - LogLevel.WARN, - `The backport for ${pr.number} has already been approved. No requested label added.`, - ); + return !hasApprovedLabel; }; From 0b2c5aac4c0a0d2effadcccc0a0fd1d0ae38d3b0 Mon Sep 17 00:00:00 2001 From: Alice Zhao Date: Mon, 22 Apr 2024 20:37:55 -0700 Subject: [PATCH 6/6] fix: add check if PR is merged --- spec/fixtures/backport_pull_request.opened.json | 2 +- spec/utils.spec.ts | 14 +++++++++----- src/utils.ts | 4 ++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/spec/fixtures/backport_pull_request.opened.json b/spec/fixtures/backport_pull_request.opened.json index 75d0821..af596b9 100644 --- a/spec/fixtures/backport_pull_request.opened.json +++ b/spec/fixtures/backport_pull_request.opened.json @@ -7,7 +7,7 @@ "number": 7, "url": "my_cool_url", "title": "CHANGE README", - "merged": true, + "merged": false, "user": { "login": "codebytere" }, diff --git a/spec/utils.spec.ts b/spec/utils.spec.ts index d70ffcb..7094385 100644 --- a/spec/utils.spec.ts +++ b/spec/utils.spec.ts @@ -8,6 +8,7 @@ import * as labelUtils from '../src/utils/label-utils'; import * as logUtils from '../src/utils/log-util'; const backportPROpenedEvent = require('./fixtures/backport_pull_request.opened.json'); +const backportPRClosedEvent = require('./fixtures/backport_pull_request.closed.json'); jest.mock('../src/constants', () => ({ ...jest.requireActual('../src/constants'), @@ -87,11 +88,6 @@ describe('utils', () => { ...backportPROpenedEvent, }; const pr = context.payload.pull_request; - let labelsToAdd: string[]; - - beforeEach(() => { - labelsToAdd = []; - }); it('should should return true if PR is semver minor and not already approved', async () => { jest.spyOn(labelUtils, 'labelExistsOnPR').mockResolvedValue(false); @@ -114,5 +110,13 @@ describe('utils', () => { expect(await needsSemverMinorBackportLabel(context, pr)).toBe(false); }); + + it('should return false if PR is merged', async () => { + const closedPr = backportPRClosedEvent.payload.pull_request; + + expect(await needsSemverMinorBackportLabel(context, closedPr)).toBe( + false, + ); + }); }); }); diff --git a/src/utils.ts b/src/utils.ts index 0554b30..5042cce 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -793,6 +793,10 @@ export const needsSemverMinorBackportLabel = async ( context: SimpleWebHookRepoContext, pr: WebHookPR, ) => { + if (pr.merged) { + return false; + } + if (!(await isSemverMinorPR(context, pr))) { return false; }