63
63
from readthedocs .doc_builder .loader import get_builder_class
64
64
from readthedocs .doc_builder .python_environments import Conda , Virtualenv
65
65
from readthedocs .oauth .models import RemoteRepository
66
+ from readthedocs .oauth .services import registry
66
67
from readthedocs .oauth .services .github import GitHubService
67
68
from readthedocs .projects .models import APIProject , Feature
68
69
from readthedocs .search .utils import index_new_files , remove_indexed_files
@@ -1867,6 +1868,7 @@ def send_build_status(build_pk, status):
1867
1868
:param status: build status failed, pending, or success to be sent.
1868
1869
"""
1869
1870
build = Build .objects .get (pk = build_pk )
1871
+
1870
1872
try :
1871
1873
if build .project .remote_repository .account .provider == 'github' :
1872
1874
service = GitHubService (
@@ -1878,10 +1880,35 @@ def send_build_status(build_pk, status):
1878
1880
service .send_build_status (build , status )
1879
1881
1880
1882
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
1882
1908
1883
1909
except Exception :
1884
1910
log .exception ('Send build status task failed for %s' , build .project )
1911
+ return False
1885
1912
1886
1913
# TODO: Send build status for other providers.
1887
1914
0 commit comments