Skip to content

Commit 19ddfb6

Browse files
authoredApr 25, 2022
fix: check last fast-track request comment (#606)
Refs: nodejs/node#42141
1 parent 7c73862 commit 19ddfb6

File tree

4 files changed

+87
-1
lines changed

4 files changed

+87
-1
lines changed
 

‎lib/pr_checker.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export default class PRChecker {
169169
}
170170

171171
if (isFastTracked) {
172-
const comment = this.comments.find((c) =>
172+
const comment = [...this.comments].reverse().find((c) =>
173173
FAST_TRACK_RE.test(c.bodyText));
174174
if (!comment) {
175175
cli.error('Unable to find the fast-track request comment.');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[
2+
{
3+
"publishedAt": "2017-10-22T04:16:36.458Z",
4+
"bodyText": "Fast-track has been requested by @bar. Please 👍 to approve.",
5+
"author": {
6+
"login": "github-actions"
7+
},
8+
"reactions": {
9+
"nodes": []
10+
}
11+
},
12+
{
13+
"publishedAt": "2017-10-22T04:17:36.458Z",
14+
"bodyText": "Oups.",
15+
"author": {
16+
"login": "bar"
17+
},
18+
"reactions": {
19+
"nodes": []
20+
}
21+
},
22+
{
23+
"publishedAt": "2017-10-22T05:16:36.458Z",
24+
"bodyText": "Fast-track has been requested by @bar. Please 👍 to approve.",
25+
"author": {
26+
"login": "github-actions"
27+
},
28+
"reactions": {
29+
"nodes": [
30+
{ "user": { "login": "bar" } },
31+
{ "user": { "login": "foo" } },
32+
{ "user": { "login": "Baz" } }
33+
]
34+
}
35+
}
36+
]

‎test/fixtures/data.js

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export const requestingChangesReviews =
3535
readJSON('reviews_requesting_changes.json');
3636

3737
export const commentsWithFastTrack = readJSON('comments_with_fast_track.json');
38+
export const commentsWithTwoFastTrack =
39+
readJSON('comments_with_two_fast_track.json');
3840
export const commentsWithFastTrackInsuffientApprovals =
3941
readJSON('comments_with_fast_track_insufficient_approvals.json');
4042
export const commentsWithCI = readJSON('comments_with_ci.json');

‎test/unit/pr_checker.test.js

+48
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
requestingChangesReviews,
1818
noReviewers,
1919
commentsWithFastTrack,
20+
commentsWithTwoFastTrack,
2021
commentsWithFastTrackInsuffientApprovals,
2122
commentsWithCI,
2223
commentsWithFailedCI,
@@ -534,6 +535,53 @@ describe('PRChecker', () => {
534535
cli.assertCalledWith(expectedLogs);
535536
});
536537

538+
it('should check the last fast-track request comment', () => {
539+
const cli = new TestCLI();
540+
541+
const expectedLogs = {
542+
ok:
543+
[['Approvals: 4'],
544+
['- Foo User (@foo): https://github.com/nodejs/node/pull/16438#pullrequestreview-71480624'],
545+
['- Quux User (@Quux): LGTM'],
546+
['- Baz User (@Baz): https://github.com/nodejs/node/pull/16438#pullrequestreview-71488236'],
547+
['- Bar User (@bar) (TSC): lgtm']],
548+
info:
549+
[['This PR was created on Fri, 30 Nov 2018 17:50:44 GMT'],
550+
['This PR is being fast-tracked']]
551+
};
552+
553+
const pr = Object.assign({}, firstTimerPR, {
554+
author: {
555+
login: 'bar'
556+
},
557+
createdAt: LT_48H,
558+
labels: {
559+
nodes: [
560+
{ name: 'fast-track' }
561+
]
562+
}
563+
});
564+
565+
const data = {
566+
pr,
567+
reviewers: allGreenReviewers,
568+
comments: commentsWithTwoFastTrack,
569+
reviews: approvingReviews,
570+
commits: [],
571+
collaborators,
572+
authorIsNew: () => true,
573+
getThread() {
574+
return PRData.prototype.getThread.call(this);
575+
}
576+
};
577+
const checker = new PRChecker(cli, data, {}, argv);
578+
579+
cli.clearCalls();
580+
const status = checker.checkReviewsAndWait(new Date(NOW));
581+
assert(status);
582+
cli.assertCalledWith(expectedLogs);
583+
});
584+
537585
it('should error with 1 fast-track approval from the pr author', () => {
538586
const cli = new TestCLI();
539587

0 commit comments

Comments
 (0)