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 committed Apr 21, 2024
1 parent 7b60143 commit d240367
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion gitmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit d240367

Please sign in to comment.