Skip to content

Fix checking of PR status #10085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions readthedocs/builds/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def send_build_status(build_pk, commit, status):
success = service.send_build_status(
build=build,
commit=commit,
state=status,
status=status,
)

if success:
Expand All @@ -451,9 +451,9 @@ def send_build_status(build_pk, commit, status):
# to send successful build status
for service in services:
success = service.send_build_status(
build,
commit,
status,
build=build,
commit=commit,
status=status,
)
if success:
log.debug(
Expand Down
6 changes: 3 additions & 3 deletions readthedocs/oauth/services/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,16 +293,16 @@ 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.

:param build: Build to set up commit status for
: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
"""
Expand Down
16 changes: 8 additions & 8 deletions readthedocs/oauth/services/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from readthedocs.api.v2.client import api
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.core.permissions import AdminPermission
from readthedocs.integrations.models import Integration

Expand Down Expand Up @@ -432,14 +432,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.
Expand All @@ -450,11 +450,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:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@humitos I think this is actually what we want? Basically just check if the status was success, then link to the built docs?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think so 😅

# Link to the documentation for this version
target_url = build.version.get_absolute_url()
else:
Expand Down
16 changes: 8 additions & 8 deletions readthedocs/oauth/services/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/projects/tasks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def send_external_build_status(version_type, build_pk, commit, status):
# Send status reports for only External (pull/merge request) Versions.
if version_type == EXTERNAL:
# call the task that actually send the build status.
send_build_status.delay(build_pk, commit, status)
send_build_status.delay(build=build_pk, commit=commit, status=status)


class BuildRequest(Request):
Expand Down