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
@@ -1888,6 +1889,7 @@ def send_build_status(build_pk, commit, status):
1888
1889
:param status: build status failed, pending, or success to be sent.
1889
1890
"""
1890
1891
build = Build .objects .get (pk = build_pk )
1892
+
1891
1893
try :
1892
1894
if build .project .remote_repository .account .provider == 'github' :
1893
1895
service = GitHubService (
@@ -1899,10 +1901,35 @@ def send_build_status(build_pk, commit, status):
1899
1901
service .send_build_status (build , commit , status )
1900
1902
1901
1903
except RemoteRepository .DoesNotExist :
1902
- log .info ('Remote repository does not exist for %s' , build .project )
1904
+ # Get the service provider for the project
1905
+ for service_cls in registry :
1906
+ if service_cls .is_project_service (build .project ):
1907
+ service = service_cls
1908
+ break
1909
+ else :
1910
+ log .warning ('There are no registered services in the application.' )
1911
+ return False
1912
+
1913
+ # Try to loop through all project users to get their social accounts
1914
+ for user in build .project .users .all ():
1915
+ user_accounts = service .for_user (user )
1916
+ # Try to loop through users all social accounts to send a successful request
1917
+ for account in user_accounts :
1918
+ # Currently we only support GitHub Status API
1919
+ if account .provider_name == 'GitHub' :
1920
+ success = account .send_build_status (build , status )
1921
+ if success :
1922
+ return True
1923
+
1924
+ log .info (
1925
+ 'No social account or repository permission available for %s' ,
1926
+ build .project
1927
+ )
1928
+ return False
1903
1929
1904
1930
except Exception :
1905
1931
log .exception ('Send build status task failed for %s' , build .project )
1932
+ return False
1906
1933
1907
1934
# TODO: Send build status for other providers.
1908
1935
0 commit comments