Skip to content

Commit fd83070

Browse files
refactor: update constants format
1 parent 3d8ab2b commit fd83070

File tree

5 files changed

+25
-22
lines changed

5 files changed

+25
-22
lines changed

spec/utils.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BACKPORT_REQUESTED_LABEL } from '../src/constants';
1+
import { BACKPORT_REVIEW_LABELS } from '../src/constants';
22
import { LogLevel } from '../src/enums';
33
import {
44
handleSemverMinorBackportLabel,
@@ -104,10 +104,10 @@ describe('utils', () => {
104104
labelsToAdd,
105105
'testFunction',
106106
);
107-
expect(labelsToAdd).toContain(BACKPORT_REQUESTED_LABEL);
107+
expect(labelsToAdd).toContain(BACKPORT_REVIEW_LABELS.REQUESTED);
108108
});
109109

110-
it('should not add BACKPORT_REQUESTED_LABEL if PR is not semver minor', async () => {
110+
it('should not add BACKPORT_REVIEW_LABELS.REQUESTED if PR is not semver minor', async () => {
111111
jest.spyOn(utils, 'isSemverMinorPR').mockResolvedValue(false);
112112

113113
await handleSemverMinorBackportLabel(
@@ -117,7 +117,7 @@ describe('utils', () => {
117117
'testFunction',
118118
);
119119

120-
expect(labelsToAdd).not.toContain(BACKPORT_REQUESTED_LABEL);
120+
expect(labelsToAdd).not.toContain(BACKPORT_REVIEW_LABELS.REQUESTED);
121121
});
122122

123123
it('should not add BACKPORT_REQUESTED_LABEL if PR is already approved', async () => {
@@ -133,7 +133,7 @@ describe('utils', () => {
133133
'testFunction',
134134
);
135135

136-
expect(labelsToAdd).not.toContain(BACKPORT_REQUESTED_LABEL);
136+
expect(labelsToAdd).not.toContain(BACKPORT_REVIEW_LABELS.REQUESTED);
137137
});
138138
});
139139
});

src/constants.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@ export const SEMVER_LABELS = {
1919
MAJOR: 'semver/major',
2020
};
2121

22-
export const SKIP_CHECK_LABEL =
23-
process.env.SKIP_CHECK_LABEL || 'backport-check-skip';
24-
25-
export const BACKPORT_REQUESTED_LABEL =
26-
process.env.BACKPORT_REQUESTED_LABEL || 'backport/requested 🗳';
27-
28-
export const BACKPORT_APPROVED_LABEL = 'backport/approved ✅';
22+
export const BACKPORT_REVIEW_LABELS = {
23+
SKIP: process.env.SKIP_CHECK_LABEL || 'backport-check-skip',
24+
REQUESTED: process.env.BACKPORT_REQUESTED_LABEL || 'backport/requested 🗳',
25+
APPROVED: 'backport/approved ✅',
26+
};
2927

3028
export const DEFAULT_BACKPORT_REVIEW_TEAM =
3129
process.env.DEFAULT_BACKPORT_REVIEW_TEAM;

src/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import {
1111
labelExistsOnPR,
1212
removeLabel,
1313
} from './utils/label-utils';
14-
import { CHECK_PREFIX, NO_BACKPORT_LABEL, SKIP_CHECK_LABEL } from './constants';
14+
import {
15+
BACKPORT_REVIEW_LABELS,
16+
CHECK_PREFIX,
17+
NO_BACKPORT_LABEL,
18+
} from './constants';
1519
import { getEnvVar } from './utils/env-util';
1620
import { PRChange, PRStatus, BackportPurpose, CheckRunStatus } from './enums';
1721
import { Label } from '@octokit/webhooks-types';
@@ -251,9 +255,11 @@ const probotHandler: ApplicationFunction = async (robot, { getRouter }) => {
251255

252256
// If a branch is targeting something that isn't main it might not be a backport;
253257
// allow for a label to skip backport validity check for these branches.
254-
if (await labelExistsOnPR(context, pr.number, SKIP_CHECK_LABEL)) {
258+
if (
259+
await labelExistsOnPR(context, pr.number, BACKPORT_REVIEW_LABELS.SKIP)
260+
) {
255261
robot.log(
256-
`#${pr.number} is labeled with ${SKIP_CHECK_LABEL} - skipping backport validation check`,
262+
`#${pr.number} is labeled with ${BACKPORT_REVIEW_LABELS.SKIP} - skipping backport validation check`,
257263
);
258264
await updateBackportValidityCheck(context, checkRun, {
259265
title: 'Backport Check Skipped',

src/operations/update-manual-backport.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BACKPORT_LABEL, SKIP_CHECK_LABEL } from '../constants';
1+
import { BACKPORT_LABEL, BACKPORT_REVIEW_LABELS } from '../constants';
22
import { PRChange, PRStatus, LogLevel } from '../enums';
33
import { WebHookPRContext } from '../types';
44
import { handleSemverMinorBackportLabel, tagBackportReviewers } from '../utils';
@@ -55,7 +55,7 @@ export const updateManualBackport = async (
5555
const skipCheckLabelExists = await labelUtils.labelExistsOnPR(
5656
context,
5757
pr.number,
58-
SKIP_CHECK_LABEL,
58+
BACKPORT_REVIEW_LABELS.SKIP,
5959
);
6060
if (!skipCheckLabelExists) {
6161
newPRLabelsToAdd.push(BACKPORT_LABEL);

src/utils.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ import simpleGit from 'simple-git';
55

66
import queue from './Queue';
77
import {
8-
BACKPORT_REQUESTED_LABEL,
9-
DEFAULT_BACKPORT_REVIEW_TEAM,
108
BACKPORT_LABEL,
11-
BACKPORT_APPROVED_LABEL,
9+
BACKPORT_REVIEW_LABELS,
10+
DEFAULT_BACKPORT_REVIEW_TEAM,
1211
} from './constants';
1312
import { PRStatus, BackportPurpose, LogLevel, PRChange } from './enums';
1413

@@ -806,11 +805,11 @@ export const handleSemverMinorBackportLabel = async (
806805
const hasApprovedLabel = await labelUtils.labelExistsOnPR(
807806
context,
808807
pr.number,
809-
BACKPORT_APPROVED_LABEL,
808+
BACKPORT_REVIEW_LABELS.APPROVED,
810809
);
811810

812811
if (!hasApprovedLabel) {
813-
labelsToAdd.push(BACKPORT_REQUESTED_LABEL);
812+
labelsToAdd.push(BACKPORT_REVIEW_LABELS.REQUESTED);
814813
return;
815814
}
816815

0 commit comments

Comments
 (0)