|
12 | 12 | from readthedocs.integrations.models import Integration
|
13 | 13 | from readthedocs.oauth.services import (
|
14 | 14 | BitbucketService, GitHubService, GitLabService, registry)
|
| 15 | +from readthedocs.projects.models import Project |
15 | 16 |
|
16 | 17 | log = logging.getLogger(__name__)
|
17 | 18 |
|
@@ -74,9 +75,21 @@ def update_webhook(project, integration, request=None):
|
74 | 75 | service_cls = SERVICE_MAP.get(integration.integration_type)
|
75 | 76 | if service_cls is None:
|
76 | 77 | return None
|
77 |
| - account = project.remote_repository.account |
78 |
| - service = service_cls(request.user, account) |
79 |
| - updated, __ = service.update_webhook(project, integration) |
| 78 | + |
| 79 | + try: |
| 80 | + account = project.remote_repository.account |
| 81 | + service = service_cls(request.user, account) |
| 82 | + updated, __ = service.update_webhook(project, integration) |
| 83 | + except Project.remote_repository.RelatedObjectDoesNotExist: |
| 84 | + # The project was imported manually and doesn't have a RemoteRepository |
| 85 | + # attached. We do brute force over all the accounts registered for this |
| 86 | + # service |
| 87 | + service_accounts = service_cls.for_user(request.user) |
| 88 | + for service in service_accounts: |
| 89 | + updated, __ = service.update_webhook(project, integration) |
| 90 | + if updated: |
| 91 | + break |
| 92 | + |
80 | 93 | if updated:
|
81 | 94 | messages.success(request, _('Webhook activated'))
|
82 | 95 | project.has_valid_webhook = True
|
|
0 commit comments