Skip to content

Commit fb0a435

Browse files
Fix #304: Add check for hotfix label (#305)
Co-authored-by: Vojtěch Jelínek <[email protected]>
1 parent 3760568 commit fb0a435

File tree

5 files changed

+69
-1
lines changed

5 files changed

+69
-1
lines changed

constants.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const claCheckGithubAction = 'cla-check-github-action';
3737
const changelogCheck = 'changelog-check';
3838
const datastoreLabelCheck = 'datastore-label-check';
3939
const prLabelCheck = 'pr-label-check';
40+
const hotfixLabelCheck = 'hotfix-label-check';
4041
const prTemplateCheck = 'pr-template-check';
4142
// This check is required in re-open events as well to
4243
// prevent user from reopening the PR.
@@ -98,7 +99,7 @@ const checksWhitelist = {
9899
modelCheck,
99100
prTemplateCheck
100101
],
101-
[PRLabelEvent]: [assigneeCheck, prLabelCheck],
102+
[PRLabelEvent]: [assigneeCheck, prLabelCheck, hotfixLabelCheck],
102103
[synchronizeEvent]: [
103104
mergeConflictCheck,
104105
jobCheck,
@@ -169,6 +170,7 @@ module.exports.issuesLabelCheck = issuesLabelCheck;
169170
module.exports.issuesAssignedCheck = issuesAssignedCheck;
170171
module.exports.datastoreLabelCheck = datastoreLabelCheck;
171172
module.exports.prLabelCheck = prLabelCheck;
173+
module.exports.hotfixLabelCheck = hotfixLabelCheck;
172174
module.exports.prTemplateCheck = prTemplateCheck;
173175
module.exports.forcePushCheck = forcePushCheck;
174176
module.exports.pullRequestReviewCheck = pullRequestReviewCheck;

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ const runChecks = async (context, checkEvent) => {
110110
checkPullRequestLabelsModule.checkForIssueLabel(context)
111111
);
112112
break;
113+
case constants.hotfixLabelCheck:
114+
callable.push(
115+
checkPullRequestLabelsModule.checkHotfixLabel(context)
116+
);
117+
break;
113118
case constants.datastoreLabelCheck:
114119
callable.push(
115120
checkPullRequestLabelsModule.checkCriticalLabel(context)

lib/checkPullRequestLabels.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
const {
1919
LABELS_EXCLUDED_FROM_CODEOWNER_ASSIGNMENT,
2020
DATASTORE_LABEL,
21+
HOTFIX_LABEL,
2122
OLD_BUILD_LABEL,
2223
getProjectOwnerFromLabel,
2324
getChangelogLabelFromPullRequest,
@@ -340,6 +341,29 @@ module.exports.checkCriticalLabel = async function (context) {
340341
}
341342
};
342343

344+
/**
345+
* This function pings the release team if PR is labelled as required
346+
* for hotfix.
347+
*
348+
* @param {import('probot').Context} context
349+
*/
350+
module.exports.checkHotfixLabel = async function (context) {
351+
/**
352+
* @type {import('probot').Octokit.IssuesGetLabelResponse} label
353+
*/
354+
const label = context.payload.label;
355+
if (label.name === HOTFIX_LABEL) {
356+
var commentParams = context.issue({
357+
body:
358+
'Hi, @oppia/release-coordinators flagging this pull request for ' +
359+
'for your attention since this is labelled as a hotfix PR. ' +
360+
'Please ensure that you add the "PR: for current release" ' +
361+
'label if the next release is in progress. Thanks!'
362+
});
363+
await context.github.issues.createComment(commentParams);
364+
}
365+
};
366+
343367
/**
344368
* This function checks if a label is allowed on Pull Requests.
345369
*

lib/utils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
const { 'default': Axios } = require('axios');
2020

2121
const DATASTORE_LABEL = 'PR: Affects datastore layer';
22+
const HOTFIX_LABEL = 'PR: Needs to be hotfixed';
2223
// Labels here are excluded from codeowner assignment because the project
2324
// owners need to review all pull requests with the label.
2425
const LABELS_EXCLUDED_FROM_CODEOWNER_ASSIGNMENT = [
@@ -486,6 +487,7 @@ module.exports = {
486487
THREE_MINUTES,
487488
LABELS_EXCLUDED_FROM_CODEOWNER_ASSIGNMENT,
488489
DATASTORE_LABEL,
490+
HOTFIX_LABEL,
489491
OLD_BUILD_LABEL,
490492
JOBS_AND_FETURES_TESTING_WIKI_LINK,
491493
getAllChangedFiles,

spec/checkPullRequestLabelsSpec.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,41 @@ describe('Pull Request Label Check', () => {
661661
});
662662
});
663663

664+
describe('when hotfix label gets added', () => {
665+
const label = {
666+
id: 638839900,
667+
node_id: 'MDU6TGFiZWw2Mzg4Mzk5MDA=',
668+
url: 'https://api.github.com/repos/oppia/oppia/labels/PR:%20released',
669+
name: 'PR: Needs to be hotfixed',
670+
color: '00FF00',
671+
};
672+
673+
beforeEach(async () => {
674+
payloadData.payload.action = 'labeled';
675+
payloadData.payload.label = label;
676+
spyOn(checkPullRequestLabelModule, 'checkHotfixLabel').and.callThrough();
677+
await robot.receive(payloadData);
678+
});
679+
680+
it('should check for hotfix label', () => {
681+
expect(checkPullRequestLabelModule.checkHotfixLabel).toHaveBeenCalled();
682+
});
683+
684+
it('should comment on PR', () => {
685+
expect(github.issues.createComment).toHaveBeenCalled();
686+
expect(github.issues.createComment).toHaveBeenCalledWith({
687+
body:
688+
'Hi, @oppia/release-coordinators flagging this pull request for ' +
689+
'for your attention since this is labelled as a hotfix PR. ' +
690+
'Please ensure that you add the "PR: for current release" ' +
691+
'label if the next release is in progress. Thanks!',
692+
number: payloadData.payload.pull_request.number,
693+
owner: payloadData.payload.repository.owner.login,
694+
repo: payloadData.payload.repository.name
695+
})
696+
})
697+
});
698+
664699
describe('when another label gets removed', () => {
665700
const label = {
666701
id: 638839900,

0 commit comments

Comments
 (0)