diff --git a/README.md b/README.md index b7babbf2..58b72c10 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ See the source code for more details. ## Death Counter -Chaosbot has died 3 times. This counter is incremented whenever the trunk breaks +Chaosbot has died 4 times. This counter is incremented whenever the trunk breaks and the server must be restarted manually. ## Server details diff --git a/chaos.py b/chaos.py index ec6748de..51b937de 100644 --- a/chaos.py +++ b/chaos.py @@ -68,13 +68,13 @@ def install_requirements(): if __name__ == "__main__": logging.info("starting up and entering event loop") - + os.system("pkill chaos_server") subprocess.Popen([sys.executable, "server.py"], cwd=join(THIS_DIR, "server")) - + log.info("starting http server") start_http_server() - + while True: log.info("looking for PRs") @@ -87,21 +87,35 @@ def install_requirements(): pr_num = pr["number"] logging.info("processing PR #%d", pr_num) - log.info("PR %d approved for merging!", pr_num) - try: - gh.prs.merge_pr(api, settings.URN, pr, votes, vote_total, - threshold) - # some error, like suddenly there's a merge conflict, or some - # new commits were introduced between findint this ready pr and - # merging it - except gh_exc.CouldntMerge: - log.info("couldn't merge PR %d for some reason, skipping", - pr_num) - gh.prs.label_pr(api, settings.URN, pr_num, ["can't merge"]) - continue - - gh.prs.label_pr(api, settings.URN, pr_num, ["accepted"]) - needs_update = True + votes = gh.voting.get_votes(api, settings.URN, pr) + + # is our PR approved or rejected? + vote_total = gh.voting.get_vote_sum(api, votes) + threshold = gh.voting.get_approval_threshold(api, settings.URN) + is_approved = vote_total >= threshold + + if is_approved: + log.info("PR %d approved for merging!", pr_num) + try: + gh.prs.merge_pr(api, settings.URN, pr, votes, vote_total, + threshold) + # some error, like suddenly there's a merge conflict, or some + # new commits were introduced between findint this ready pr and + # merging it + except gh_exc.CouldntMerge: + log.info("couldn't merge PR %d for some reason, skipping", + pr_num) + gh.prs.label_pr(api, settings.URN, pr_num, ["can't merge"]) + continue + + gh.prs.label_pr(api, settings.URN, pr_num, ["accepted"]) + needs_update = True + + else: + log.info("PR %d rejected, closing", pr_num) + gh.comments.leave_reject_comment(api, settings.URN, pr_num) + gh.prs.label_pr(api, settings.URN, pr_num, ["rejected"]) + gh.prs.close_pr(api, settings.URN, pr) # we approved a PR, restart