ci: require milestones on develop PRs (#25688)

This commit is contained in:
Nico André
2026-03-10 09:52:31 +01:00
committed by GitHub
parent 25a3b96284
commit bf2b1cb6bf
5 changed files with 90 additions and 17 deletions
+3 -3
View File
@@ -1,6 +1,6 @@
# PR checker for status
This action checks a PR labels, milestone and status to validate it is ready for merging into main.
This action checks a PR labels, milestone and status to validate it is ready for merging.
> ❗️ When making changes to this code, make sure to run the build before committing. See [Development](#development) to know more.
@@ -12,8 +12,8 @@ This action checks a PR labels, milestone and status to validate it is ready for
- `flag: don't merge`
2. The PR should have one and only one `source: *` label.
3. The PR should have one and only one `issue-type: *` label.
4. The PR must have a milestone defined.
3. The PR should have one and only one `pr: *` label.
4. PRs targeting `develop` must have a milestone defined.
## Contributing
@@ -7,6 +7,10 @@ const github = require('@actions/github');
const core = require('@actions/core');
const action = require('../index');
beforeEach(() => {
jest.clearAllMocks();
});
test.each(action.BLOCKING_LABELS)('Test blocking labels %s', async (label) => {
github.context = {
payload: {
@@ -101,3 +105,72 @@ test('Test too many pr label', async () => {
setFailed.mockRestore();
});
test('Test missing milestone for develop PR', async () => {
github.context = {
payload: {
pull_request: {
base: {
ref: 'develop',
},
labels: [{ name: 'pr: enhancement' }, { name: 'source: core' }],
milestone: null,
},
},
};
const setFailed = jest.spyOn(core, 'setFailed');
await action();
expect(setFailed).toHaveBeenCalled();
expect(setFailed.mock.calls[0][0]).toBe(`The PR must have a milestone.`);
setFailed.mockRestore();
});
test('Test missing milestone for non-develop PR', async () => {
github.context = {
payload: {
pull_request: {
base: {
ref: 'main',
},
labels: [{ name: 'pr: enhancement' }, { name: 'source: core' }],
milestone: null,
},
},
};
const setFailed = jest.spyOn(core, 'setFailed');
await action();
expect(setFailed).not.toHaveBeenCalled();
setFailed.mockRestore();
});
test('Test develop PR with milestone', async () => {
github.context = {
payload: {
pull_request: {
base: {
ref: 'develop',
},
labels: [{ name: 'pr: enhancement' }, { name: 'source: core' }],
milestone: {
title: '5.0.0',
},
},
},
};
const setFailed = jest.spyOn(core, 'setFailed');
await action();
expect(setFailed).not.toHaveBeenCalled();
setFailed.mockRestore();
});
File diff suppressed because one or more lines are too long
+8 -9
View File
@@ -32,15 +32,14 @@ async function main() {
core.setFailed(`The PR must have one and only one 'pr:' label.`);
}
// NOTE: to avoid manual work, this is commented until we can set the workflow to trigger on pull_request milestone changes.
// ref: https://github.community/t/feature-request-add-milestone-changes-as-activity-type-to-pull-request/16778/16
/*
const milestone = context.payload.pull_request?.milestone;
const hasMilestone = !!milestone;
if (!hasMilestone) {
core.setFailed(`The PR must have a milestone.`);
}
*/
const baseRef = github.context.payload.pull_request?.base?.ref;
const milestone = github.context.payload.pull_request?.milestone;
const requiresMilestone = baseRef === 'develop';
const isMissingMilestone = milestone === null || milestone === undefined;
if (requiresMilestone === true && isMissingMilestone === true) {
core.setFailed(`The PR must have a milestone.`);
}
} catch (error) {
core.setFailed(error.message);
}
+3
View File
@@ -4,10 +4,13 @@ on:
pull_request:
types:
- opened
- edited
- synchronize
- reopened
- labeled
- unlabeled
- milestoned
- demilestoned
branches:
- main
- develop