Skip to content

Commit

Permalink
merging PR Chaosthebot#500: Fix meritocracy mentions and extended vot…
Browse files Browse the repository at this point in the history
…ing window

Chaosthebot#500: Fix meritocracy mentions and extended voting window

Description:
Now it must be running in production, and it will not mention the author of the PR (as they cannot review their own PR).

Edit: in addition, the PR must not be in the base voting window.

:white_check_mark: PR passed with a vote of 11 for and 0 against, a weighted total of 11.0 and a threshold of 6.5, and a current meritocracy review.

Vote record:
@MUCHZER: 1
@PlasmaPower: 1
@Swizz: 1
@andrewda: 1
@e-beach: 1
@ike709: 1
@JustynC7: 1
@mark-i-m: 1
@rhengles: 1
@rudehn: 1
@xyproto: 1
  • Loading branch information
PlasmaPower authored and chaosbot committed Jun 4, 2017
1 parent b950705 commit 331c5b4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 27 deletions.
28 changes: 17 additions & 11 deletions cron/poll_pull_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def poll_pull_requests(api):
__log.exception("Failed to create meritocracy mentioned DB table")

# get voting window
voting_window = gh.voting.get_initial_voting_window()
base_voting_window = gh.voting.get_initial_voting_window()

# get all ready prs (disregarding of the voting window)
prs = gh.prs.get_ready_prs(api, settings.URN, 0)
Expand Down Expand Up @@ -76,30 +76,36 @@ def poll_pull_requests(api):
threshold = gh.voting.get_approval_threshold(api, settings.URN)
is_approved = vote_total >= threshold and meritocracy_satisfied

seconds_since_updated = gh.prs.seconds_since_updated(api, pr)

voting_window = base_voting_window
# the PR is mitigated or the threshold is not reached ?
if variance >= threshold or not is_approved:
voting_window = gh.voting.get_extended_voting_window(api, settings.URN)
if vote_total >= threshold / 2:
if (settings.IN_PRODUCTION and vote_total >= threshold / 2 and
seconds_since_updated > base_voting_window and not meritocracy_satisfied):
# check if we need to mention the meritocracy
try:
commit = pr["head"]["sha"]
if not db.query("SELECT * FROM meritocracy_mentioned WHERE commit_hash=?",
(commit,)):
meritocracy_mentions = meritocracy - {pr["user"]["login"].lower(),
"chaosbot"}
db.query("INSERT INTO meritocracy_mentioned (commit_hash) VALUES (?)",
(commit,))
gh.comments.leave_meritocracy_comment(api, settings.URN, pr["number"],
meritocracy)
meritocracy_mentions)
except:
__log.exception("Failed to process meritocracy mention")

# is our PR in voting window?
in_window = gh.prs.is_pr_in_voting_window(api, pr, voting_window)
in_window = seconds_since_updated > voting_window

if is_approved:
__log.info("PR %d status: will be approved", pr_num)

gh.prs.post_accepted_status(
api, settings.URN, pr, voting_window, votes, vote_total,
api, settings.URN, pr, seconds_since_updated, voting_window, votes, vote_total,
threshold, meritocracy_satisfied)

if in_window:
Expand Down Expand Up @@ -133,8 +139,8 @@ def poll_pull_requests(api):

if in_window:
gh.prs.post_rejected_status(
api, settings.URN, pr, voting_window, votes, vote_total,
threshold, meritocracy_satisfied)
api, settings.URN, pr, seconds_since_updated, voting_window, votes,
vote_total, threshold, meritocracy_satisfied)
__log.info("PR %d rejected, closing", pr_num)
gh.comments.leave_reject_comment(
api, settings.URN, pr_num, votes, vote_total, threshold,
Expand All @@ -143,12 +149,12 @@ def poll_pull_requests(api):
gh.prs.close_pr(api, settings.URN, pr)
elif vote_total < 0:
gh.prs.post_rejected_status(
api, settings.URN, pr, voting_window, votes, vote_total,
threshold, meritocracy_satisfied)
api, settings.URN, pr, seconds_since_updated, voting_window, votes,
vote_total, threshold, meritocracy_satisfied)
else:
gh.prs.post_pending_status(
api, settings.URN, pr, voting_window, votes, vote_total,
threshold, meritocracy_satisfied)
api, settings.URN, pr, seconds_since_updated, voting_window, votes,
vote_total, threshold, meritocracy_satisfied)

for user in votes:
if user in total_votes:
Expand Down
27 changes: 11 additions & 16 deletions github_api/prs.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,12 @@ def get_ready_prs(api, urn, window):
handle_broken_pr(api, urn, pr, delta, "conflicts")


def voting_window_remaining_seconds(api, pr, window):
def seconds_since_updated(api, pr):
now = arrow.utcnow()
updated = get_pr_last_updated(api, pr)
if updated is None:
return math.inf
delta = (now - updated).total_seconds()
return window - delta


def is_pr_in_voting_window(api, pr, window):
return voting_window_remaining_seconds(api, pr, window) <= 0
return (now - updated).total_seconds()


def get_pr_reviews(api, urn, pr_num):
Expand Down Expand Up @@ -337,35 +332,35 @@ def get_patch(api, urn, pr_num, raw=False):
return PatchSet.from_string(data)


def post_accepted_status(api, urn, pr, voting_window, votes, total, threshold,
meritocracy_satisfied):
def post_accepted_status(api, urn, pr, seconds_since_updated, voting_window, votes, total,
threshold, meritocracy_satisfied):
sha = pr["head"]["sha"]

remaining_seconds = voting_window_remaining_seconds(api, pr, voting_window)
remaining_seconds = voting_window - seconds_since_updated
remaining_human = misc.seconds_to_human(remaining_seconds)
votes_summary = formatted_votes_short_summary(votes, total, threshold, meritocracy_satisfied)

post_status(api, urn, sha, "success",
"remaining: {time}, {summary}".format(time=remaining_human, summary=votes_summary))


def post_rejected_status(api, urn, pr, voting_window, votes, total, threshold,
meritocracy_satisfied):
def post_rejected_status(api, urn, pr, seconds_since_updated, voting_window, votes, total,
threshold, meritocracy_satisfied):
sha = pr["head"]["sha"]

remaining_seconds = voting_window_remaining_seconds(api, pr, voting_window)
remaining_seconds = voting_window - seconds_since_updated
remaining_human = misc.seconds_to_human(remaining_seconds)
votes_summary = formatted_votes_short_summary(votes, total, threshold, meritocracy_satisfied)

post_status(api, urn, sha, "failure",
"remaining: {time}, {summary}".format(time=remaining_human, summary=votes_summary))


def post_pending_status(api, urn, pr, voting_window, votes, total, threshold,
meritocracy_satisfied):
def post_pending_status(api, urn, pr, seconds_since_updated, voting_window, votes, total,
threshold, meritocracy_satisfied):
sha = pr["head"]["sha"]

remaining_seconds = voting_window_remaining_seconds(api, pr, voting_window)
remaining_seconds = voting_window - seconds_since_updated
remaining_human = misc.seconds_to_human(remaining_seconds)
votes_summary = formatted_votes_short_summary(votes, total, threshold, meritocracy_satisfied)

Expand Down
4 changes: 4 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
URN = misc.get_self_urn()
GITHUB_USER, GITHUB_REPO = URN.split("/")

# if we are running in production
# if we switch to an org this will need changing
IN_PRODUCTION = GITHUB_USER == "chaosbot"

HOMEPAGE = "http://chaosthebot.com"

# TEST SETTING PLEASE IGNORE
Expand Down

0 comments on commit 331c5b4

Please sign in to comment.