From eda6fef510bff92e58095e96defbeb869d9cedbe Mon Sep 17 00:00:00 2001 From: Jeff Schaller <17769792+jeffschaller@users.noreply.github.com> Date: Sat, 20 Apr 2024 20:31: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 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gitmanager.py b/gitmanager.py index c6122078e8..c614d9ffa3 100644 --- a/gitmanager.py +++ b/gitmanager.py @@ -342,6 +342,9 @@ def remove_from_blacklist(cls, item, username, blacklist_type="", code_privilege 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) + # catch 404 as a special error case; otherwise, it would fall into the generic `not response` case below + if (response.status_code == 404): + raise ValueError("PR #{} was not found (HTTP 404) -- possible typo?".format(pr_id)) if not response: raise ConnectionError("Cannot connect to GitHub API") pr_info = response.json()