Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fast-track, test: check per current expectation of fast-track PR
  • Loading branch information
priyank-p committed Nov 21, 2017
commit 41cc6032bfc486a603d60f65fc3dc83065b72791
29 changes: 22 additions & 7 deletions lib/pr_checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class PRChecker {
const status = [
this.checkReviews(comments),
this.checkCommitsAfterReview(),
this.checkPRWait(new Date()),
this.checkCI(),
this.checkPRWait(new Date()),
this.checkMergeableState()
];

Expand Down Expand Up @@ -150,16 +150,29 @@ class PRChecker {
* @param {Date} now
*/
checkPRWait(now) {
const { pr } = this;
const { cli } = this;
const {
pr, cli, reviewers, CIStatus
} = this;
const labels = pr.labels.nodes;

const fast =
labels.some((l) => ['code-and-learn', 'fast-track'].includes(l.name)) ||
(labels.length === 1 && labels[0].name === 'doc');
labels.some((l) => ['fast-track'].includes(l.name));
if (fast) {
cli.info('This PR is being fast-tracked.');
return true;
const { approved } = reviewers;
if (approved.length > 1 && CIStatus) {
cli.info('This PR is being fast-tracked');
return true;
} else {
const msg = ['This PR is being fast-tracked, but awating '];
if (approved.length < 2) msg.push('approvals of 2 contributors');
if (!CIStatus) msg.push('a CI run');

let warnMsg = msg.length === 2
? msg.join('') : `${msg[0] + msg[1]} and ${msg[2]}`;
cli.warn(warnMsg);
}

return false;
}

const wait = this.getWait(now);
Expand Down Expand Up @@ -188,6 +201,7 @@ class PRChecker {
let status = true;
if (!ciMap.size) {
cli.error('No CI runs detected');
this.CIStatus = false;
return false;
} else if (!ciMap.get(FULL)) {
status = false;
Expand Down Expand Up @@ -237,6 +251,7 @@ class PRChecker {
}
}

this.CIStatus = status;
return status;
}

Expand Down
124 changes: 103 additions & 21 deletions test/unit/pr_checker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,67 +201,149 @@ describe('PRChecker', () => {
cli.assertCalledWith(expectedLogs);
});

it('should skip wait check for Code & Learn PR', () => {
it('should log as expected if PR can be fast-tracked', () => {
const cli = new TestCLI();

const expectedLogs = {
info: [['This PR is being fast-tracked.']]
info: [
[ 'This PR is being fast-tracked' ]
]
};

const now = new Date();
const youngPR = Object.assign({}, firstTimerPR, {
createdAt: '2017-10-27T14:25:41.682Z',
const now = new Date('2017-11-01T14:25:41.682Z');
const PR = Object.assign({}, firstTimerPR, {
createdAt: '2017-10-31T13:00:41.682Z',
labels: {
nodes: [
{
name: 'code-and-learn'
}
{ name: 'fast-track' }
]
}
});

const options = {
pr: youngPR,
pr: PR,
reviewers: allGreenReviewers,
comments: commentsWithLGTM,
comments: commentsWithCI,
reviews: approvingReviews,
commits: simpleCommits,
commits: [],
collaborators
};
const checker = new PRChecker(cli, options, argv);

checker.checkCI();
cli.clearCalls();
const status = checker.checkPRWait(now);
assert(status);
cli.assertCalledWith(expectedLogs);
});

it('should skip wait check for fast-track labelled PR', () => {
it('should warn about approvals and CI for fast-tracked PR', () => {
const cli = new TestCLI();

const expectedLogs = {
info: [['This PR is being fast-tracked.']]
warn: [
[ 'This PR is being fast-tracked, but awating ' +
'approvals of 2 contributors and a CI run' ]
]
};

const youngPR = Object.assign({}, firstTimerPR, {
createdAt: '2017-10-27T14:25:41.682Z',
const now = new Date('2017-11-01T14:25:41.682Z');
const PR = Object.assign({}, firstTimerPR, {
createdAt: '2017-10-31T13:00:41.682Z',
labels: {
nodes: [
{ name: 'fast-track' }
]
}
});

const checker = new PRChecker(cli, {
pr: youngPR,
const options = {
pr: PR,
reviewers: requestedChangesReviewers,
comments: [],
reviews: requestingChangesReviews,
commits: simpleCommits,
collaborators
};
const checker = new PRChecker(cli, options, argv);

checker.checkCI();
cli.clearCalls();
const status = checker.checkPRWait(now);
assert(!status);
cli.assertCalledWith(expectedLogs);
});

it('should warn cannot be fast-tracked because of approvals', () => {
const cli = new TestCLI();

const expectedLogs = {
warn: [
[ 'This PR is being fast-tracked, but awating ' +
'approvals of 2 contributors' ]
]
};

const now = new Date('2017-11-01T14:25:41.682Z');
const PR = Object.assign({}, firstTimerPR, {
createdAt: '2017-10-31T13:00:41.682Z',
labels: {
nodes: [
{ name: 'fast-track' }
]
}
});

const options = {
pr: PR,
reviewers: requestedChangesReviewers,
comments: commentsWithCI,
reviews: approvingReviews,
commits: [],
collaborators
};
const checker = new PRChecker(cli, options, argv);

checker.checkCI();
cli.clearCalls();
const status = checker.checkPRWait(now);
assert(!status);
cli.assertCalledWith(expectedLogs);
});

it('should warn if the PR has no CI and cannot be fast-tracked', () => {
const cli = new TestCLI();

const expectedLogs = {
warn: [
[ 'This PR is being fast-tracked, but awating a CI run' ]
]
};

const now = new Date('2017-11-01T14:25:41.682Z');
const PR = Object.assign({}, firstTimerPR, {
createdAt: '2017-10-31T13:00:41.682Z',
labels: {
nodes: [
{ name: 'fast-track' }
]
}
});

const options = {
pr: PR,
reviewers: allGreenReviewers,
comments: commentsWithLGTM,
comments: [],
reviews: approvingReviews,
commits: simpleCommits,
collaborators
});
};
const checker = new PRChecker(cli, options, argv);

const status = checker.checkPRWait(new Date());
assert(status);
checker.checkCI();
cli.clearCalls();
const status = checker.checkPRWait(now);
assert(!status);
cli.assertCalledWith(expectedLogs);
});
});
Expand Down