diff --git a/readthedocs/builds/tasks.py b/readthedocs/builds/tasks.py index f1abb11f202..e66cacdf388 100644 --- a/readthedocs/builds/tasks.py +++ b/readthedocs/builds/tasks.py @@ -431,9 +431,9 @@ def send_build_status(build_pk, commit, status): service = service_class(relation.user, relation.account) # Send status report using the API. success = service.send_build_status( - build=build, - commit=commit, - state=status, + build, + commit, + status, ) if success: diff --git a/readthedocs/oauth/services/base.py b/readthedocs/oauth/services/base.py index 812aef60cae..1539fbccb01 100644 --- a/readthedocs/oauth/services/base.py +++ b/readthedocs/oauth/services/base.py @@ -293,7 +293,7 @@ def update_webhook(self, project, integration): """ raise NotImplementedError - def send_build_status(self, build, commit, state): + def send_build_status(self, build, commit, status): """ Create commit status for project. @@ -301,8 +301,8 @@ def send_build_status(self, build, commit, state): :type build: Build :param commit: commit sha of the pull/merge request :type commit: str - :param state: build state failure, pending, or success. - :type state: str + :param status: build state failure, pending, or success. + :type status: str :returns: boolean based on commit status creation was successful or not. :rtype: Bool """ diff --git a/readthedocs/oauth/services/github.py b/readthedocs/oauth/services/github.py index e49a500ee96..572f6e6fdba 100644 --- a/readthedocs/oauth/services/github.py +++ b/readthedocs/oauth/services/github.py @@ -11,7 +11,7 @@ from requests.exceptions import RequestException from readthedocs.builds import utils as build_utils -from readthedocs.builds.constants import BUILD_FINAL_STATES, SELECT_BUILD_STATUS +from readthedocs.builds.constants import BUILD_STATUS_SUCCESS, SELECT_BUILD_STATUS from readthedocs.integrations.models import Integration from ..constants import GITHUB @@ -429,14 +429,14 @@ def update_webhook(self, project, integration): integration.remove_secret() return (False, resp) - def send_build_status(self, build, commit, state): + def send_build_status(self, build, commit, status): """ Create GitHub commit status for project. :param build: Build to set up commit status for :type build: Build - :param state: build state failure, pending, or success. - :type state: str + :param status: build state failure, pending, or success. + :type status: str :param commit: commit sha of the pull request :type commit: str :returns: boolean based on commit status creation was successful or not. @@ -447,11 +447,11 @@ def send_build_status(self, build, commit, state): owner, repo = build_utils.get_github_username_repo(url=project.repo) # select the correct state and description. - github_build_state = SELECT_BUILD_STATUS[state]['github'] - description = SELECT_BUILD_STATUS[state]['description'] - statuses_url = f'https://api.github.com/repos/{owner}/{repo}/statuses/{commit}' + github_build_state = SELECT_BUILD_STATUS[status]["github"] + description = SELECT_BUILD_STATUS[status]["description"] + statuses_url = f"https://api.github.com/repos/{owner}/{repo}/statuses/{commit}" - if build.state in BUILD_FINAL_STATES and build.success: + if status == BUILD_STATUS_SUCCESS: # Link to the documentation for this version target_url = build.version.get_absolute_url() else: diff --git a/readthedocs/oauth/services/gitlab.py b/readthedocs/oauth/services/gitlab.py index 95d1f6247c5..d5cbe91f783 100644 --- a/readthedocs/oauth/services/gitlab.py +++ b/readthedocs/oauth/services/gitlab.py @@ -12,7 +12,7 @@ from requests.exceptions import RequestException from readthedocs.builds import utils as build_utils -from readthedocs.builds.constants import BUILD_FINAL_STATES, SELECT_BUILD_STATUS +from readthedocs.builds.constants import BUILD_STATUS_SUCCESS, SELECT_BUILD_STATUS from readthedocs.integrations.models import Integration from ..constants import GITLAB @@ -519,14 +519,14 @@ def update_webhook(self, project, integration): integration.remove_secret() return (False, resp) - def send_build_status(self, build, commit, state): + def send_build_status(self, build, commit, status): """ Create GitLab commit status for project. :param build: Build to set up commit status for :type build: Build - :param state: build state failure, pending, or success. - :type state: str + :param status: build status failure, pending, or success. + :type status: str :param commit: commit sha of the pull request :type commit: str :returns: boolean based on commit status creation was successful or not. @@ -541,11 +541,11 @@ def send_build_status(self, build, commit, state): if repo_id is None: return (False, resp) - # select the correct state and description. - gitlab_build_state = SELECT_BUILD_STATUS[state]['gitlab'] - description = SELECT_BUILD_STATUS[state]['description'] + # select the correct status and description. + gitlab_build_state = SELECT_BUILD_STATUS[status]["gitlab"] + description = SELECT_BUILD_STATUS[status]["description"] - if build.state in BUILD_FINAL_STATES and build.success: + if status == BUILD_STATUS_SUCCESS: # Link to the documentation for this version target_url = build.version.get_absolute_url() else: diff --git a/readthedocs/rtd_tests/tests/test_celery.py b/readthedocs/rtd_tests/tests/test_celery.py index cde5d76ee5e..b3fd0384de8 100644 --- a/readthedocs/rtd_tests/tests/test_celery.py +++ b/readthedocs/rtd_tests/tests/test_celery.py @@ -98,9 +98,9 @@ def test_send_build_status_with_remote_repo_github(self, send_build_status): ) send_build_status.assert_called_once_with( - build=external_build, - commit=external_build.commit, - state=BUILD_STATUS_SUCCESS, + external_build, + external_build.commit, + BUILD_STATUS_SUCCESS, ) self.assertEqual(Message.objects.filter(user=self.eric).count(), 0) @@ -165,9 +165,9 @@ def test_send_build_status_with_remote_repo_gitlab(self, send_build_status): ) send_build_status.assert_called_once_with( - build=external_build, - commit=external_build.commit, - state=BUILD_STATUS_SUCCESS, + external_build, + external_build.commit, + BUILD_STATUS_SUCCESS, ) self.assertEqual(Message.objects.filter(user=self.eric).count(), 0)