Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resync valid webhook for project manually imported #3935

Merged
merged 1 commit into from Apr 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 16 additions & 3 deletions readthedocs/oauth/utils.py
Expand Up @@ -12,6 +12,7 @@
from readthedocs.integrations.models import Integration
from readthedocs.oauth.services import (
BitbucketService, GitHubService, GitLabService, registry)
from readthedocs.projects.models import Project

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -74,9 +75,21 @@ def update_webhook(project, integration, request=None):
service_cls = SERVICE_MAP.get(integration.integration_type)
if service_cls is None:
return None
account = project.remote_repository.account
service = service_cls(request.user, account)
updated, __ = service.update_webhook(project, integration)

try:
account = project.remote_repository.account
service = service_cls(request.user, account)
updated, __ = service.update_webhook(project, integration)
except Project.remote_repository.RelatedObjectDoesNotExist:
# The project was imported manually and doesn't have a RemoteRepository
# attached. We do brute force over all the accounts registered for this
# service
service_accounts = service_cls.for_user(request.user)
for service in service_accounts:
updated, __ = service.update_webhook(project, integration)
if updated:
break

if updated:
messages.success(request, _('Webhook activated'))
project.has_valid_webhook = True
Expand Down