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

time: refactor, add notion of days a PR has been sitting #37

Merged
merged 4 commits into from Jan 11, 2019
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 28 additions & 9 deletions validate.py
Expand Up @@ -47,9 +47,8 @@ def base_pr_url():
return 'https://www.jefftk.com/nomic-github/repos/%s/pulls/%s' % (
get_repo(), get_pr())

def get_author():
response = request(base_pr_url())
return response.json()['user']['login']
def get_author(pr_json):
return pr_json['user']['login']

def get_reviews():
target_commit = get_commit()
Expand Down Expand Up @@ -85,6 +84,19 @@ def get_reviews():
def get_users():
return list(sorted(os.listdir('players/')))

def iso8601_to_ts(iso8601):
return int(time.mktime(time.strptime(iso8601, "%Y-%m-%dT%H:%M:%SZ")))

def pr_created_at_ts(pr_json):
return iso8601_to_ts(pr_json['created_at'])

def pr_pushed_at_ts(pr_json):
return iso8601_to_ts(pr_json['head']['repo']['pushed_at'])

def pr_last_changed_ts(pr_json):
return max(pr_created_at_ts(pr_json),
pr_pushed_at_ts(pr_json))

def last_commit_ts():
# When was the last commit on master?
cmd = ['git', 'log', 'master', '-1', '--format=%ct']
Expand All @@ -94,19 +106,20 @@ def last_commit_ts():

return int(completed_process.stdout)

def seconds_since_last_commit():
return int(time.time() - last_commit_ts())
def seconds_since(ts):
return int(time.time() - ts)

def days_since_last_commit():
return int(seconds_since_last_commit() / 60 / 60 / 24)
def seconds_to_days(seconds):
return int(seconds / 60 / 60 / 24)

def determine_if_mergeable():
users = get_users()
print('Users:')
for user in users:
print(' %s' % user)

author = get_author()
pr_json = request(base_pr_url()).json()
author = get_author(pr_json)
print('\nAuthor: %s' % author)

reviews = get_reviews()
Expand All @@ -130,11 +143,17 @@ 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)))

print('FYI: this PR has been sitting for %s days' % (
days_since_last_changed))

required_approvals = len(users)

# Allow three days to go by with no commits, but if longer happens then start
# lowering the threshold for allowing a commit.
approvals_to_skip = days_since_last_commit() - 3
approvals_to_skip = seconds_to_days(seconds_since(last_commit_ts())) - 3
if approvals_to_skip > 0:
print("Skipping up to %s approvals, because it's been %s days"
" since the last commit." % (approvals_to_skip,
Expand Down