From d240367b2079e9229c3c0a42caef890c48f13c63 Mon Sep 17 00:00:00 2001 From: Jeff Schaller <17769792+jeffschaller@users.noreply.github.com> Date: Sat, 20 Apr 2024 20:54:52 -0400 Subject: [PATCH] Add HTTP 404 handling for merge_pull_request in gitmanager.py The code `if not response` catches HTTP 404 as "not OK" based on the logic in the requests module. Since PR# typos are semi-common, this change pulls out the HTTP 404 to give it a different (better?) response to the user. --- gitmanager.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gitmanager.py b/gitmanager.py index c6122078e8..18b8924711 100644 --- a/gitmanager.py +++ b/gitmanager.py @@ -343,7 +343,10 @@ def merge_pull_request(cls, pr_id, comment=""): response = requests.get("https://api.github.com/repos/{}/pulls/{}".format(GlobalVars.bot_repo_slug, pr_id), timeout=GlobalVars.default_requests_timeout) if not response: - raise ConnectionError("Cannot connect to GitHub API") + if (response.status_code == 404): + raise ValueError("PR #{} was not found (HTTP 404) -- possible typo?".format(pr_id)) + else: + raise ConnectionError("Cannot connect to GitHub API") pr_info = response.json() if pr_info["user"]["login"] != "SmokeDetector": raise ValueError("PR #{} is not created by me, so I can't approve it.".format(pr_id))