diff --git a/readthedocs/oauth/services/bitbucket.py b/readthedocs/oauth/services/bitbucket.py index b14d1de84e1..1d93b99593f 100644 --- a/readthedocs/oauth/services/bitbucket.py +++ b/readthedocs/oauth/services/bitbucket.py @@ -274,6 +274,12 @@ def update_webhook(self, project, integration): project, ) return (True, resp) + + # Bitbucket returns 404 when the webhook doesn't exist. In this + # case, we call ``setup_webhook`` to re-configure it from scratch + if resp.status_code == 404: + return self.setup_webhook(project) + # Catch exceptions with request or deserializing JSON except (KeyError, RequestException, ValueError): log.exception( diff --git a/readthedocs/oauth/services/github.py b/readthedocs/oauth/services/github.py index 609332bf4af..654adca4da4 100644 --- a/readthedocs/oauth/services/github.py +++ b/readthedocs/oauth/services/github.py @@ -261,6 +261,12 @@ def update_webhook(self, project, integration): project, ) return (True, resp) + + # GitHub returns 404 when the webhook doesn't exist. In this case, + # we call ``setup_webhook`` to re-configure it from scratch + if resp.status_code == 404: + return self.setup_webhook(project) + # Catch exceptions with request or deserializing JSON except (RequestException, ValueError): log.exception( diff --git a/readthedocs/oauth/services/gitlab.py b/readthedocs/oauth/services/gitlab.py index 62313c89d66..aef754c46e1 100644 --- a/readthedocs/oauth/services/gitlab.py +++ b/readthedocs/oauth/services/gitlab.py @@ -331,6 +331,12 @@ def update_webhook(self, project, integration): log.info( 'GitLab webhook update successful for project: %s', project) return (True, resp) + + # GitLab returns 404 when the webhook doesn't exist. In this case, + # we call ``setup_webhook`` to re-configure it from scratch + if resp.status_code == 404: + return self.setup_webhook(project) + # Catch exceptions with request or deserializing JSON except (RequestException, ValueError): log.exception(