Skip to content

Commit 579e29b

Browse files
authored
Build: handle 422 response on send build status (#9347)
GitHub return 422 with "No commit found for SHA" when the commit does not exist anymore. This could be because the user force-pushed and/or rewrite the history. On these cases, we don't want to log the response as a WARNING/ERROR, we just want to ignore it.
1 parent 87b689d commit 579e29b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

readthedocs/oauth/services/github.py

+12
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,18 @@ def send_build_status(self, build, commit, state, link_to_build=False):
475475
log.info('GitHub project does not exist or user does not have permissions.')
476476
return False
477477

478+
if (
479+
resp.status_code == 422
480+
and "No commit found for SHA" in resp.json()["message"]
481+
):
482+
# This happens when the user force-push a branch or similar
483+
# that changes the Git history and SHA does not exist anymore.
484+
#
485+
# We return ``True`` here because otherwise our logic will try
486+
# with different users. However, all of them will fail since
487+
# it's not a permission issue.
488+
return True
489+
478490
try:
479491
debug_data = resp.json()
480492
except ValueError:

0 commit comments

Comments
 (0)