Skip to content

Commit

Permalink
Add HTTP 404 handling for merge_pull_request in gitmanager.py
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jeffschaller authored Apr 21, 2024
1 parent 19da802 commit eda6fef
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions gitmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit eda6fef

Please sign in to comment.