Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/pr_checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export default class PRChecker {
}

if (isFastTracked) {
const comment = this.comments.find((c) =>
const comment = [...this.comments].reverse().find((c) =>
FAST_TRACK_RE.test(c.bodyText));
if (!comment) {
cli.error('Unable to find the fast-track request comment.');
Expand Down
36 changes: 36 additions & 0 deletions test/fixtures/comments_with_two_fast_track.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[
{
"publishedAt": "2017-10-22T04:16:36.458Z",
"bodyText": "Fast-track has been requested by @bar. Please 👍 to approve.",
"author": {
"login": "github-actions"
},
"reactions": {
"nodes": []
}
},
{
"publishedAt": "2017-10-22T04:17:36.458Z",
"bodyText": "Oups.",
"author": {
"login": "bar"
},
"reactions": {
"nodes": []
}
},
{
"publishedAt": "2017-10-22T05:16:36.458Z",
"bodyText": "Fast-track has been requested by @bar. Please 👍 to approve.",
"author": {
"login": "github-actions"
},
"reactions": {
"nodes": [
{ "user": { "login": "bar" } },
{ "user": { "login": "foo" } },
{ "user": { "login": "Baz" } }
]
}
}
]
2 changes: 2 additions & 0 deletions test/fixtures/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export const requestingChangesReviews =
readJSON('reviews_requesting_changes.json');

export const commentsWithFastTrack = readJSON('comments_with_fast_track.json');
export const commentsWithTwoFastTrack =
readJSON('comments_with_two_fast_track.json');
export const commentsWithFastTrackInsuffientApprovals =
readJSON('comments_with_fast_track_insufficient_approvals.json');
export const commentsWithCI = readJSON('comments_with_ci.json');
Expand Down
48 changes: 48 additions & 0 deletions test/unit/pr_checker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
requestingChangesReviews,
noReviewers,
commentsWithFastTrack,
commentsWithTwoFastTrack,
commentsWithFastTrackInsuffientApprovals,
commentsWithCI,
commentsWithFailedCI,
Expand Down Expand Up @@ -534,6 +535,53 @@ describe('PRChecker', () => {
cli.assertCalledWith(expectedLogs);
});

it('should check the last fast-track request comment', () => {
const cli = new TestCLI();

const expectedLogs = {
ok:
[['Approvals: 4'],
['- Foo User (@foo): https://github.com/nodejs/node/pull/16438#pullrequestreview-71480624'],
['- Quux User (@Quux): LGTM'],
['- Baz User (@Baz): https://github.com/nodejs/node/pull/16438#pullrequestreview-71488236'],
['- Bar User (@bar) (TSC): lgtm']],
info:
[['This PR was created on Fri, 30 Nov 2018 17:50:44 GMT'],
['This PR is being fast-tracked']]
};

const pr = Object.assign({}, firstTimerPR, {
author: {
login: 'bar'
},
createdAt: LT_48H,
labels: {
nodes: [
{ name: 'fast-track' }
]
}
});

const data = {
pr,
reviewers: allGreenReviewers,
comments: commentsWithTwoFastTrack,
reviews: approvingReviews,
commits: [],
collaborators,
authorIsNew: () => true,
getThread() {
return PRData.prototype.getThread.call(this);
}
};
const checker = new PRChecker(cli, data, {}, argv);

cli.clearCalls();
const status = checker.checkReviewsAndWait(new Date(NOW));
assert(status);
cli.assertCalledWith(expectedLogs);
});

it('should error with 1 fast-track approval from the pr author', () => {
const cli = new TestCLI();

Expand Down