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
16 changes: 3 additions & 13 deletions lib/pr_checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ const SECOND = 1000;
const MINUTE = SECOND * 60;
const HOUR = MINUTE * 60;

const SUNDAY = 0;
const SATURDAY = 6;

const WEEKDAY_WAIT = 48;
const WEEKEND_WAIT = 72;
const WAIT_TIME = 48;

const {
REVIEW_SOURCES: { FROM_COMMENT, FROM_REVIEW_COMMENT }
Expand Down Expand Up @@ -136,16 +132,11 @@ class PRChecker {
*/
getWait(now) {
const createTime = new Date(this.pr.createdAt);
const utcDay = createTime.getUTCDay();
// TODO: do we need to lose this a bit considering timezones?
const isWeekend = (utcDay === SUNDAY || utcDay === SATURDAY);
const waitTime = isWeekend ? WEEKEND_WAIT : WEEKDAY_WAIT;
const timeLeft = waitTime - Math.ceil(
const timeLeft = WAIT_TIME - Math.ceil(
(now.getTime() - createTime.getTime()) / HOUR
);

return {
isWeekend,
timeLeft
};
}
Expand Down Expand Up @@ -183,8 +174,7 @@ class PRChecker {
const wait = this.getWait(now);
if (wait.timeLeft > 0) {
const dateStr = new Date(pr.createdAt).toDateString();
const type = wait.isWeekend ? 'weekend' : 'weekday';
cli.info(`This PR was created on ${dateStr} (${type} in UTC)`);
cli.info(`This PR was created on ${dateStr}`);
cli.warn(`Wait at least ${wait.timeLeft} more hours before landing`);
return false;
}
Expand Down
36 changes: 2 additions & 34 deletions test/unit/pr_checker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,44 +165,12 @@ describe('PRChecker', () => {
});

describe('checkPRWait', () => {
it('should warn about PR younger than 72h on weekends', () => {
const cli = new TestCLI();

const expectedLogs = {
warn: [['Wait at least 49 more hours before landing']],
info: [['This PR was created on Sat Oct 28 2017 (weekend in UTC)']]
};

const now = new Date('2017-10-29T13:00:41.682Z');
const youngPR = Object.assign({}, firstTimerPR, {
createdAt: '2017-10-28T14:25:41.682Z'
});

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

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

it('should warn about PR younger than 48h on weekdays', () => {
it('should warn about PR younger than 48h', () => {
const cli = new TestCLI();

const expectedLogs = {
warn: [['Wait at least 22 more hours before landing']],
info: [['This PR was created on Tue Oct 31 2017 (weekday in UTC)']]
info: [['This PR was created on Tue Oct 31 2017']]
};

const now = new Date('2017-11-01T14:25:41.682Z');
Expand Down