Skip to content
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

Require all PRs to wait 1 day after creation before merging, unless they're unanimously approved #44

Merged
merged 7 commits into from
Jan 23, 2019
16 changes: 13 additions & 3 deletions validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import requests
import subprocess
import time
import datetime
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used, though not important enough to wipe approvals over

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, that was left in from the pre-time-refactor version.


def request(url):
request_headers = {'User-Agent': 'jeffkaufman/nomic'}
Expand Down Expand Up @@ -119,8 +120,14 @@ def seconds_since(ts):
def seconds_to_days(seconds):
return int(seconds / 60 / 60 / 24)

def days_since(ts):
return seconds_to_days(seconds_since(ts))

def days_since_last_commit():
return seconds_to_days(seconds_since(last_commit_ts()))
return days_since(last_commit_ts())

def days_since_pr_created(pr_json):
return days_since(pr_created_at_ts(pr_json))

def determine_if_mergeable():
users = get_users()
Expand Down Expand Up @@ -153,8 +160,7 @@ def determine_if_mergeable():
if rejections:
raise Exception('Rejected by: %s' % (' '.join(rejections)))

days_since_last_changed = seconds_to_days(
seconds_since(pr_last_changed_ts(pr_json)))
days_since_last_changed = days_since(pr_last_changed_ts(pr_json))

print('FYI: this PR has been sitting for %s days' % (
days_since_last_changed))
Expand All @@ -176,6 +182,10 @@ def determine_if_mergeable():
if len(approvals) < required_approvals:
raise Exception('Insufficient approval')

# Don't allow PRs to be merged the day they're created unless they pass unanimously
if (len(approvals) < len(users)) and (days_since_pr_created(pr_json) < 1):
raise Exception('PR created within last 24 hours does not have unanimous approval.')

print('\nPASS')

def determine_if_winner():
Expand Down