Skip to content

Commit 50b0f8e

Browse files
joyeecheungpriyank-p
authored andcommitted
ci: parse CI links after sorting the comments by publishedDate
This helps newer CI runs take precedence over old ones if they are posted in the same comment (usually done when someone use `<del>` to delete a bad build in the comment to avoid multiple notifications)
1 parent bba3461 commit 50b0f8e

File tree

4 files changed

+45
-41
lines changed

4 files changed

+45
-41
lines changed

lib/ci/ci_type_parser.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const { parsePRFromURL } = require('../links');
44
const PRData = require('../pr_data');
5+
const { ascending } = require('../comp');
56

67
const CI_URL_RE = /\/\/ci\.nodejs\.org(\S+)/mg;
78
const CI_DOMAIN = 'ci.nodejs.org';
@@ -141,7 +142,9 @@ class JobParser {
141142
* @param {{bodyText: string, publishedAt: string}[]} thread
142143
*/
143144
constructor(thread) {
144-
this.thread = thread;
145+
this.thread = thread.sort(
146+
(a, b) => ascending(a.publishedAt, b.publishedAt)
147+
);
145148
}
146149

147150
/**
@@ -155,14 +158,13 @@ class JobParser {
155158
if (!text.includes(CI_DOMAIN)) continue;
156159
const jobs = this.parseText(text);
157160
for (const job of jobs) {
158-
const entry = result.get(job.type);
159-
if (!entry || entry.date < c.publishedAt) {
160-
result.set(job.type, {
161-
link: job.link,
162-
date: c.publishedAt,
163-
jobid: job.jobid
164-
});
165-
}
161+
// Always take the last one
162+
// TODO(joyeecheung): exlcude links wrapped in `<del>`
163+
result.set(job.type, {
164+
link: job.link,
165+
date: c.publishedAt,
166+
jobid: job.jobid
167+
});
166168
}
167169
}
168170
return result;
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
[
22
{
3-
"publishedAt": "2017-10-27T04:16:36.458Z",
3+
"publishedAt": "2017-10-22T04:16:36.458Z",
44
"bodyText": "CI: https://ci.nodejs.org/job/node-test-pull-request/10984/\ncitgm: https://ci.nodejs.org/job/citgm-smoker/1030/"
55
},
66
{
7-
"publishedAt": "2017-10-24T04:16:36.458Z",
7+
"publishedAt": "2017-10-23T04:16:36.458Z",
88
"bodyText": "https://ci.nodejs.org/job/libuv-test-commit/537/"
99
},
1010
{
11-
"publishedAt": "2017-10-23T04:16:36.458Z",
11+
"publishedAt": "2017-10-24T04:16:36.458Z",
1212
"bodyText": "https://ci.nodejs.org/job/node-test-commit-nointl/7/"
1313
},
1414
{
15-
"publishedAt": "2017-10-22T04:16:36.458Z",
16-
"bodyText": "CI: https://ci.nodejs.org/job/node-test-pull-request/10992/\nV8 CI: https://ci.nodejs.org/job/node-test-commit-v8-linux/1018/"
15+
"publishedAt": "2017-10-25T04:16:36.458Z",
16+
"bodyText": "<del>CI: https://ci.nodejs.org/job/node-test-pull-request/10991/\n</del>\nCI: https://ci.nodejs.org/job/node-test-pull-request/10992/\nV8 CI: https://ci.nodejs.org/job/node-test-commit-v8-linux/1018/"
1717
},
1818
{
19-
"publishedAt": "2017-10-21T04:16:36.458Z",
19+
"publishedAt": "2017-10-26T04:16:36.458Z",
2020
"bodyText": "Oh nice, it's back now. Benchmark CI: https://ci.nodejs.org/job/benchmark-node-micro-benchmarks/20/"
2121
},
2222
{
23-
"publishedAt": "2017-10-22T04:16:36.458Z",
23+
"publishedAt": "2017-10-27T04:16:36.458Z",
2424
"bodyText": "Linter CI: https://ci.nodejs.org/job/node-test-linter/13127/"
25-
},{
26-
"publishedAt": "2018-02-09T21:38:30Z",
25+
},
26+
{
27+
"publishedAt": "2017-10-28T04:16:36.458Z",
2728
"bodyText": "CI https://ci.nodejs.org/job/node-test-commit-lite/246/"
28-
},{
29-
"publishedAt": "2017-10-21T04:16:36.458Z",
29+
},
30+
{
31+
"publishedAt": "2017-10-29T04:16:36.458Z",
3032
"bodyText": "@contributer build started: https://ci.nodejs.org/job/node-test-pull-request-lite-pipeline/7213/pipeline/"
3133
}
3234
]

test/unit/ci_type_parser.test.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,48 @@ const {
1111

1212
const expected = new Map([
1313
['PR', {
14-
link: 'https://ci.nodejs.org/job/node-test-pull-request/10984/',
15-
date: '2017-10-27T04:16:36.458Z',
16-
jobid: 10984
14+
link: 'https://ci.nodejs.org/job/node-test-pull-request/10992/',
15+
date: '2017-10-25T04:16:36.458Z',
16+
jobid: 10992
1717
}],
1818
['CITGM', {
1919
link: 'https://ci.nodejs.org/job/citgm-smoker/1030/',
20-
date: '2017-10-27T04:16:36.458Z',
20+
date: '2017-10-22T04:16:36.458Z',
2121
jobid: 1030
2222
}],
2323
['LIBUV', {
2424
link: 'https://ci.nodejs.org/job/libuv-test-commit/537/',
25-
date: '2017-10-24T04:16:36.458Z',
25+
date: '2017-10-23T04:16:36.458Z',
2626
jobid: 537
2727
}],
2828
['NOINTL', {
2929
link: 'https://ci.nodejs.org/job/node-test-commit-nointl/7/',
30-
date: '2017-10-23T04:16:36.458Z',
30+
date: '2017-10-24T04:16:36.458Z',
3131
jobid: 7
3232
}],
3333
['V8', {
3434
link: 'https://ci.nodejs.org/job/node-test-commit-v8-linux/1018/',
35-
date: '2017-10-22T04:16:36.458Z',
35+
date: '2017-10-25T04:16:36.458Z',
3636
jobid: 1018
3737
}],
3838
['BENCHMARK', {
3939
link: 'https://ci.nodejs.org/job/benchmark-node-micro-benchmarks/20/',
40-
date: '2017-10-21T04:16:36.458Z',
40+
date: '2017-10-26T04:16:36.458Z',
4141
jobid: 20
4242
}],
4343
['LINTER', {
4444
link: 'https://ci.nodejs.org/job/node-test-linter/13127/',
45-
date: '2017-10-22T04:16:36.458Z',
45+
date: '2017-10-27T04:16:36.458Z',
4646
jobid: 13127
4747
}],
4848
['LITE_COMMIT', {
4949
link: 'https://ci.nodejs.org/job/node-test-commit-lite/246/',
50-
date: '2018-02-09T21:38:30Z',
50+
date: '2017-10-28T04:16:36.458Z',
5151
jobid: 246
5252
}],
5353
['LITE_PR_PIPELINE', {
5454
link: 'https://ci.nodejs.org/job/node-test-pull-request-lite-pipeline/7213/pipeline/',
55-
date: '2017-10-21T04:16:36.458Z',
55+
date: '2017-10-29T04:16:36.458Z',
5656
jobid: 7213
5757
}]
5858
]);

test/unit/pr_checker.test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -427,39 +427,39 @@ describe('PRChecker', () => {
427427
const expectedLogs = {
428428
info: [
429429
[
430-
'Last Full PR CI on 2017-10-27T04:16:36.458Z: ' +
431-
'https://ci.nodejs.org/job/node-test-pull-request/10984/'
430+
'Last Full PR CI on 2017-10-25T04:16:36.458Z: ' +
431+
'https://ci.nodejs.org/job/node-test-pull-request/10992/'
432432
],
433433
[
434-
'Last CITGM CI on 2017-10-27T04:16:36.458Z: ' +
434+
'Last CITGM CI on 2017-10-22T04:16:36.458Z: ' +
435435
'https://ci.nodejs.org/job/citgm-smoker/1030/'
436436
],
437437
[
438-
'Last libuv CI on 2017-10-24T04:16:36.458Z: ' +
438+
'Last libuv CI on 2017-10-23T04:16:36.458Z: ' +
439439
'https://ci.nodejs.org/job/libuv-test-commit/537/'
440440
],
441441
[
442-
'Last No Intl CI on 2017-10-23T04:16:36.458Z: ' +
442+
'Last No Intl CI on 2017-10-24T04:16:36.458Z: ' +
443443
'https://ci.nodejs.org/job/node-test-commit-nointl/7/'
444444
],
445445
[
446-
'Last V8 CI on 2017-10-22T04:16:36.458Z: ' +
446+
'Last V8 CI on 2017-10-25T04:16:36.458Z: ' +
447447
'https://ci.nodejs.org/job/node-test-commit-v8-linux/1018/'
448448
],
449449
[
450-
'Last Benchmark CI on 2017-10-21T04:16:36.458Z: ' +
450+
'Last Benchmark CI on 2017-10-26T04:16:36.458Z: ' +
451451
'https://ci.nodejs.org/job/benchmark-node-micro-benchmarks/20/'
452452
],
453453
[
454-
'Last Linter CI on 2017-10-22T04:16:36.458Z: ' +
454+
'Last Linter CI on 2017-10-27T04:16:36.458Z: ' +
455455
'https://ci.nodejs.org/job/node-test-linter/13127/'
456456
],
457457
[
458-
'Last Lite Commit CI on 2018-02-09T21:38:30Z: ' +
458+
'Last Lite Commit CI on 2017-10-28T04:16:36.458Z: ' +
459459
'https://ci.nodejs.org/job/node-test-commit-lite/246/'
460460
],
461461
[
462-
'Last Lite PR Pipeline CI on 2017-10-21T04:16:36.458Z: ' +
462+
'Last Lite PR Pipeline CI on 2017-10-29T04:16:36.458Z: ' +
463463
'https://ci.nodejs.org/job/node-test-pull-request-lite-pipeline/7213/pipeline/'
464464
]
465465
]

0 commit comments

Comments
 (0)