Skip to content

Commit

Permalink
Resync webhooks from Admin
Browse files Browse the repository at this point in the history
If the user delete the RTD webhook integration for whatever reason
from the project under the external service (GitHub, etc) when the
Resync button is pressed we re-create / setup the webhook as it was
never existed.
  • Loading branch information
humitos committed Apr 10, 2018
1 parent 4dc9e94 commit 65ee5da
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions readthedocs/oauth/services/bitbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions readthedocs/oauth/services/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions readthedocs/oauth/services/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 65ee5da

Please sign in to comment.