Skip to content

Commit

Permalink
merging PR #218: Close stale PRs with merge conflicts
Browse files Browse the repository at this point in the history
#218: Close stale PRs with merge conflicts

Description:
This should take care of some of the PRs rotting at the bottom of the list.

I'm looking at `updated_at` so that comments will refresh the stale timer. That way, if people are deciding how to approach the merge conflicts, the PR won't close on them.

:ok_woman: PR passed with a vote of 6 for and 0 against, with a weighted total of 6.0 and a threshold of 3.6.

Vote record:
@PlasmaPower: 1
@amoffat: 1
@ariddell: 1
@ozyx: 1
@reddraggone9: 1
@zakrid: 1
  • Loading branch information
chaosbot authored May 25, 2017
2 parents 19c6bd7 + ea4e8df commit 43050ac
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions github_api/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ def leave_accept_comment(api, urn, pr, sha, votes, total, threshold):
""".strip().format(summary=votes_summary, sha=sha)
return leave_comment(api, urn, pr, body)

def leave_stale_comment(api, urn, pr, hours):
body = """
:no_good: This PR has merge conflicts, and hasn't been touched in {hours} hours. Closing.
Open a new PR with the merge conflicts fixed to restart voting.
""".strip().format(hours=hours)
return leave_comment(api, urn, pr, body)

def leave_comment(api, urn, pr, body):
path = "/repos/{urn}/issues/{pr}/comments".format(urn=urn, pr=pr)
data = {"body": body}
Expand Down
6 changes: 6 additions & 0 deletions github_api/prs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import settings
from . import misc
from . import voting
from . import comments
from . import exceptions as exc


Expand Down Expand Up @@ -147,6 +148,11 @@ def get_ready_prs(api, urn, window):
yield pr
elif mergeable is False:
label_pr(api, urn, pr_num, ["conflicts"])
last_update = max(arrow.get(pr["updated_at"]), updated)
update_delta = (now - last_update).total_seconds()
if update_delta >= 60 * 60 * settings.PR_STALE_HOURS:
comments.leave_stale_comment(api, urn, pr["number"], round(update_delta / 60 / 60))
close_pr(api, urn, pr)
# mergeable can also be None, in which case we just skip it for now


Expand Down
4 changes: 4 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@

# used for calculating how long our voting window is
TIMEZONE = "US/Pacific"

# PRs that have merge conflicts and haven't been touched in this many hours
# will be closed
PR_STALE_HOURS = 24

0 comments on commit 43050ac

Please # to comment.