Skip to content

Commit 3324f4f

Browse files
committed
Fix issues around remote repository for sending Build status reports
1 parent f20e659 commit 3324f4f

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

readthedocs/projects/tasks.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
from readthedocs.doc_builder.loader import get_builder_class
6464
from readthedocs.doc_builder.python_environments import Conda, Virtualenv
6565
from readthedocs.oauth.models import RemoteRepository
66+
from readthedocs.oauth.services import registry
6667
from readthedocs.oauth.services.github import GitHubService
6768
from readthedocs.projects.models import APIProject, Feature
6869
from readthedocs.search.utils import index_new_files, remove_indexed_files
@@ -1867,6 +1868,7 @@ def send_build_status(build_pk, status):
18671868
:param status: build status failed, pending, or success to be sent.
18681869
"""
18691870
build = Build.objects.get(pk=build_pk)
1871+
18701872
try:
18711873
if build.project.remote_repository.account.provider == 'github':
18721874
service = GitHubService(
@@ -1878,10 +1880,35 @@ def send_build_status(build_pk, status):
18781880
service.send_build_status(build, status)
18791881

18801882
except RemoteRepository.DoesNotExist:
1881-
log.info('Remote repository does not exist for %s', build.project)
1883+
# Get the service provider for the project
1884+
for service_cls in registry:
1885+
if service_cls.is_project_service(build.project):
1886+
service = service_cls
1887+
break
1888+
else:
1889+
log.warning('There are no registered services in the application.')
1890+
return False
1891+
1892+
# Try to loop through all project users to get their social accounts
1893+
for user in build.project.users.all():
1894+
user_accounts = service.for_user(user)
1895+
# Try to loop through users all social accounts to send a successful request
1896+
for account in user_accounts:
1897+
# Currently we only support GitHub Status API
1898+
if account.provider_name == 'GitHub':
1899+
success = account.send_build_status(build, status)
1900+
if success:
1901+
return True
1902+
1903+
log.info(
1904+
'No social account or repository permission available for %s',
1905+
build.project
1906+
)
1907+
return False
18821908

18831909
except Exception:
18841910
log.exception('Send build status task failed for %s', build.project)
1911+
return False
18851912

18861913
# TODO: Send build status for other providers.
18871914

0 commit comments

Comments
 (0)