-
Notifications
You must be signed in to change notification settings - Fork 122
git-node: wait time for PR with single approval #290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
One Collaborator approval is enough only if the pull request has been open for more than 7 days Refs: nodejs/node#22255
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ const MINUTE = SECOND * 60; | |
| const HOUR = MINUTE * 60; | ||
|
|
||
| const WAIT_TIME = 48; | ||
| const WAIT_TIME_SINGLE_APPROVAL = 168; | ||
|
|
||
| const { | ||
| REVIEW_SOURCES: { FROM_COMMENT, FROM_REVIEW_COMMENT } | ||
|
|
@@ -132,12 +133,16 @@ class PRChecker { | |
| */ | ||
| getWait(now) { | ||
| const createTime = new Date(this.pr.createdAt); | ||
| const timeLeft = WAIT_TIME - Math.ceil( | ||
| const hoursFromCreateTime = Math.ceil( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems rather complicated. I believe we can just combine
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (The two methods are separated only because previously a human would check these two conditions separately, but now there is a relationship between the two we should do what a human brain would do here instead and combine the logic.) |
||
| (now.getTime() - createTime.getTime()) / HOUR | ||
| ); | ||
| const timeLeft = WAIT_TIME - hoursFromCreateTime; | ||
| const timeLeftSingleApproval = | ||
| WAIT_TIME_SINGLE_APPROVAL - hoursFromCreateTime; | ||
|
|
||
| return { | ||
| timeLeft | ||
| timeLeft, | ||
| timeLeftSingleApproval | ||
| }; | ||
| } | ||
|
|
||
|
|
@@ -149,12 +154,12 @@ class PRChecker { | |
| const { | ||
| pr, cli, reviewers, CIStatus | ||
| } = this; | ||
| const { approved } = reviewers; | ||
| const labels = pr.labels.nodes; | ||
|
|
||
| const fast = | ||
| labels.some((l) => ['fast-track'].includes(l.name)); | ||
| if (fast) { | ||
| const { approved } = reviewers; | ||
| if (approved.length > 1 && CIStatus) { | ||
| cli.info('This PR is being fast-tracked'); | ||
| return true; | ||
|
|
@@ -171,14 +176,25 @@ class PRChecker { | |
| return false; | ||
| } | ||
|
|
||
| const dateStr = new Date(pr.createdAt).toDateString(); | ||
| cli.info(`This PR was created on ${dateStr}`); | ||
|
|
||
| const wait = this.getWait(now); | ||
| if (wait.timeLeft > 0) { | ||
| const dateStr = new Date(pr.createdAt).toDateString(); | ||
| cli.info(`This PR was created on ${dateStr}`); | ||
| if (approved.length > 1 && wait.timeLeft > 0) { | ||
| cli.warn(`Wait at least ${wait.timeLeft} more hours before landing`); | ||
| return false; | ||
| } else if (approved.length === 1 && wait.timeLeftSingleApproval > 0) { | ||
| const waitMsg = wait.timeLeft > 0 | ||
| ? ` and ${wait.timeLeft} more hours` | ||
| : ''; | ||
| cli.warn('Wait at one of the following:'); | ||
| cli.warn(`* another approval${waitMsg}`); | ||
| cli.warn(`* ${wait.timeLeftSingleApproval} more hours` + | ||
| ' with existing single approval'); | ||
| return false; | ||
| } | ||
|
|
||
| cli.info('No more waiting required'); | ||
| return true; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
7 * 24or add comment to make it obvious that this is 7 days