Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Close stale PRs with merge conflicts #218

Merged
merged 1 commit into from
May 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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