Skip to content

Commit cc14afc

Browse files
authored
fix(ci): exempt Dependabot PRs from issue acceptance (#4928)
Signed-off-by: Simon Scatton <sscatton@nvidia.com>
1 parent 9c6c252 commit cc14afc

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

‎tasks/scripts/check_issue_acceptance.cjs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ module.exports = async function checkIssueAcceptance({ github, context, core })
88
});
99
const author = pr.user.login;
1010

11+
if (author === 'dependabot[bot]') {
12+
core.info('Dependabot PRs are exempt from issue acceptance.');
13+
return;
14+
}
15+
1116
async function evaluate() {
1217
try {
1318
const { data } = await github.rest.repos.getCollaboratorPermissionLevel({

‎tasks/scripts/check_issue_acceptance.test.cjs‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const checkIssueAcceptance = require('./check_issue_acceptance.cjs');
88
async function check({
99
permission = 'read', issues = [], body = '', permissionError,
1010
number = 7, headSha = 'pr-head', pullError, issueError, labelError,
11+
author = 'contributor', actor = 'maintainer',
1112
} = {}) {
1213
const failures = [];
1314
const github = {
@@ -17,13 +18,13 @@ async function check({
1718
assert.equal(pull_number, number);
1819
if (pullError) throw new Error('PR lookup failed');
1920
return { data: {
20-
number, user: { login: 'contributor' }, head: { sha: headSha }, body,
21+
number, user: { login: author }, head: { sha: headSha }, body,
2122
} };
2223
},
2324
},
2425
repos: {
2526
getCollaboratorPermissionLevel: async ({ username }) => {
26-
assert.equal(username, 'contributor');
27+
assert.equal(username, author);
2728
if (permissionError) throw Object.assign(new Error('lookup failed'), { status: permissionError });
2829
return { data: { permission } };
2930
},
@@ -53,13 +54,31 @@ async function check({
5354
context: {
5455
repo: { owner: 'NVIDIA', repo: 'OpenShell' },
5556
payload: { pull_request: { number } },
56-
actor: 'maintainer', sha: 'base-commit', serverUrl: 'https://github.com', runId: 42,
57+
actor, sha: 'base-commit', serverUrl: 'https://github.com', runId: 42,
5758
},
5859
core: { info() {}, setFailed: message => failures.push(message) },
5960
});
6061
return failures;
6162
}
6263

64+
test('Dependabot PRs pass without permission or issue lookups', async () => {
65+
assert.deepEqual(await check({
66+
author: 'dependabot[bot]', permissionError: 403, issueError: true,
67+
}), []);
68+
});
69+
70+
test('other bots still require an accepted issue', async () => {
71+
const failures = await check({ author: 'renovate[bot]' });
72+
assert.equal(failures.length, 1);
73+
assert.match(failures[0], /must link an issue with state:accepted/);
74+
});
75+
76+
test('Dependabot triggering another author\'s PR does not bypass acceptance', async () => {
77+
const failures = await check({ actor: 'dependabot[bot]' });
78+
assert.equal(failures.length, 1);
79+
assert.match(failures[0], /must link an issue with state:accepted/);
80+
});
81+
6382
for (const permission of ['write', 'maintain', 'admin']) {
6483
test(`${permission} access allows an issue-less PR`, async () => {
6584
assert.deepEqual(await check({ permission }), []);

0 commit comments

Comments
 (0)