Skip to content

Commit 829c68d

Browse files
committed
fix: allow pending dependabot checks in PR checker
GitHub support says that they are expected to show up by design. This also removes some code duplication and normalizes log level and format.
1 parent e98d72e commit 829c68d

File tree

4 files changed

+73
-51
lines changed

4 files changed

+73
-51
lines changed

lib/pr_checker.js

+9-40
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ class PRChecker {
339339
return status;
340340
}
341341

342-
checkActionsCI() {
342+
checkGitHubCI() {
343343
const { cli, commits } = this;
344344

345345
if (!commits || commits.length === 0) {
@@ -359,44 +359,13 @@ class PRChecker {
359359
}
360360

361361
// GitHub new Check API
362-
for (const { status, conclusion } of checkSuites.nodes) {
363-
if (status !== 'COMPLETED') {
364-
cli.error('GitHub CI is still running');
365-
return false;
366-
}
367-
368-
if (!GITHUB_SUCCESS_CONCLUSIONS.includes(conclusion)) {
369-
cli.error('Last GitHub CI failed');
370-
return false;
362+
for (const { status, conclusion, app } of checkSuites.nodes) {
363+
if (app && app.slug === 'dependabot') {
364+
// Ignore Dependabot check suites. They are expected to show up
365+
// sometimes and never complete.
366+
continue;
371367
}
372-
}
373-
374-
cli.ok('Last GitHub Actions successful');
375-
this.CIStatus = true;
376-
return true;
377-
}
378-
379-
checkGitHubCI() {
380-
const { cli, commits } = this;
381368

382-
if (!commits || commits.length === 0) {
383-
cli.error('No commits detected');
384-
return false;
385-
}
386-
387-
// NOTE(mmarchini): we only care about the last commit. Maybe in the future
388-
// we'll want to check all commits for a successful CI.
389-
const { commit } = commits[commits.length - 1];
390-
391-
this.CIStatus = false;
392-
const checkSuites = commit.checkSuites || { nodes: [] };
393-
if (!commit.status && checkSuites.nodes.length === 0) {
394-
cli.error('No GitHub CI runs detected');
395-
return false;
396-
}
397-
398-
// GitHub new Check API
399-
for (const { status, conclusion } of checkSuites.nodes) {
400369
if (status !== 'COMPLETED') {
401370
cli.error('GitHub CI is still running');
402371
return false;
@@ -422,7 +391,7 @@ class PRChecker {
422391
}
423392
}
424393

425-
cli.info('Last GitHub CI successful');
394+
cli.ok('Last GitHub CI successful');
426395
this.CIStatus = true;
427396
return true;
428397
}
@@ -460,14 +429,14 @@ class PRChecker {
460429
}
461430

462431
async checkNodejsCI() {
463-
let status = this.checkActionsCI();
432+
let status = this.checkGitHubCI();
464433
if (
465434
this.pr.labels.nodes.some((l) => l.name === 'needs-ci') ||
466435
this.requiresJenkinsRun()
467436
) {
468437
status &= await this.checkJenkinsCI();
469438
} else {
470-
this.cli.info('Green GitHub Actions CI is sufficient');
439+
this.cli.info('Green GitHub CI is sufficient');
471440
}
472441
return status;
473442
}

lib/queries/PRCommits.gql

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ query Commits($prid: Int!, $owner: String!, $repo: String!, $after: String) {
2727
authoredByCommitter
2828
checkSuites(first: 100) {
2929
nodes {
30+
app {
31+
slug
32+
}
3033
conclusion,
3134
status
3235
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[
2+
{
3+
"commit": {
4+
"committedDate": "2017-10-26T12:10:20Z",
5+
"oid": "9d098ssiskj8dhd39js0sjd0cn2ng4is9n40sj12d",
6+
"messageHeadline": "doc: add api description README",
7+
"author": {
8+
"login": "foo"
9+
},
10+
"checkSuites": {
11+
"nodes": [
12+
{
13+
"app": {
14+
"slug": "dependabot"
15+
},
16+
"status": "QUEUED",
17+
"conclusion": null
18+
},
19+
{
20+
"status": "COMPLETED",
21+
"conclusion": "SUCCESS"
22+
}
23+
]
24+
}
25+
}
26+
}
27+
]
28+

test/unit/pr_checker.test.js

+33-11
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ describe('PRChecker', () => {
800800
['No GitHub CI runs detected']
801801
],
802802
info: [
803-
['Green GitHub Actions CI is sufficient']
803+
['Green GitHub CI is sufficient']
804804
]
805805
};
806806

@@ -839,10 +839,10 @@ describe('PRChecker', () => {
839839

840840
const expectedLogs = {
841841
ok: [
842-
['Last GitHub Actions successful']
842+
['Last GitHub CI successful']
843843
],
844844
info: [
845-
['Green GitHub Actions CI is sufficient']
845+
['Green GitHub CI is sufficient']
846846
]
847847
};
848848

@@ -883,10 +883,10 @@ describe('PRChecker', () => {
883883

884884
const expectedLogs = {
885885
ok: [
886-
['Last GitHub Actions successful']
886+
['Last GitHub CI successful']
887887
],
888888
info: [
889-
['Green GitHub Actions CI is sufficient']
889+
['Green GitHub CI is sufficient']
890890
]
891891
};
892892

@@ -1086,7 +1086,7 @@ describe('PRChecker', () => {
10861086

10871087
const expectedLogs = {
10881088
ok: [
1089-
['Last GitHub Actions successful'],
1089+
['Last GitHub CI successful'],
10901090
['Last Jenkins CI successful']
10911091
],
10921092
error: [
@@ -1462,7 +1462,7 @@ describe('PRChecker', () => {
14621462
const cli = new TestCLI();
14631463

14641464
const expectedLogs = {
1465-
info: [
1465+
ok: [
14661466
['Last GitHub CI successful']
14671467
]
14681468
};
@@ -1477,6 +1477,28 @@ describe('PRChecker', () => {
14771477
cli.assertCalledWith(expectedLogs);
14781478
});
14791479

1480+
it(
1481+
'should succeed if status succeeded with queued Dependabot check',
1482+
async() => {
1483+
const cli = new TestCLI();
1484+
1485+
const expectedLogs = {
1486+
ok: [
1487+
['Last GitHub CI successful']
1488+
]
1489+
};
1490+
1491+
const commits = githubCI['success-dependabot-queued'];
1492+
const data = Object.assign({}, baseData, { commits });
1493+
1494+
const checker = new PRChecker(cli, data, {}, testArgv);
1495+
1496+
const status = await checker.checkCI();
1497+
assert(status);
1498+
cli.assertCalledWith(expectedLogs);
1499+
}
1500+
);
1501+
14801502
it('should error if Check suite failed', async() => {
14811503
const cli = new TestCLI();
14821504

@@ -1519,7 +1541,7 @@ describe('PRChecker', () => {
15191541
const cli = new TestCLI();
15201542

15211543
const expectedLogs = {
1522-
info: [
1544+
ok: [
15231545
['Last GitHub CI successful']
15241546
]
15251547
};
@@ -1576,7 +1598,7 @@ describe('PRChecker', () => {
15761598
const cli = new TestCLI();
15771599

15781600
const expectedLogs = {
1579-
info: [
1601+
ok: [
15801602
['Last GitHub CI successful']
15811603
]
15821604
};
@@ -1595,7 +1617,7 @@ describe('PRChecker', () => {
15951617
const cli = new TestCLI();
15961618

15971619
const expectedLogs = {
1598-
info: [
1620+
ok: [
15991621
['Last GitHub CI successful']
16001622
]
16011623
};
@@ -1671,7 +1693,7 @@ describe('PRChecker', () => {
16711693
const cli = new TestCLI();
16721694

16731695
const expectedLogs = {
1674-
info: [
1696+
ok: [
16751697
['Last GitHub CI successful']
16761698
]
16771699
};

0 commit comments

Comments
 (0)