Skip to content

Commit

Permalink
refactor: update constants format
Browse files Browse the repository at this point in the history
  • Loading branch information
alicelovescake committed Apr 21, 2024
1 parent 3d8ab2b commit fd83070
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 22 deletions.
10 changes: 5 additions & 5 deletions spec/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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 () => {
Expand All @@ -133,7 +133,7 @@ describe('utils', () => {
'testFunction',
);

expect(labelsToAdd).not.toContain(BACKPORT_REQUESTED_LABEL);
expect(labelsToAdd).not.toContain(BACKPORT_REVIEW_LABELS.REQUESTED);
});
});
});
12 changes: 5 additions & 7 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
12 changes: 9 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions src/operations/update-manual-backport.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 4 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit fd83070

Please sign in to comment.