Skip to content

Commit 0e2f770

Browse files
committed
1 parent ed16833 commit 0e2f770

File tree

7 files changed

+25
-14
lines changed

7 files changed

+25
-14
lines changed

readthedocs/builds/tasks.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ def send_build_status(build_pk, commit, status, link_to_build=False):
389389
:param build_pk: Build primary key
390390
:param commit: commit sha of the pull/merge request
391391
:param status: build status failed, pending, or success to be sent.
392+
:param link_to_build: When True, link to the built HTML
392393
"""
393394
# TODO: Send build status for BitBucket.
394395
build = Build.objects.filter(pk=build_pk).first()
@@ -449,7 +450,9 @@ def send_build_status(build_pk, commit, status, link_to_build=False):
449450
# Try to loop through services for users all social accounts
450451
# to send successful build status
451452
for service in services:
452-
success = service.send_build_status(build, commit, status)
453+
success = service.send_build_status(
454+
build, commit, status, link_to_build=link_to_build
455+
)
453456
if success:
454457
log.debug(
455458
'Build status report sent correctly using an user account.',

readthedocs/core/utils/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ def prepare_build(
106106
version_type=version.type,
107107
build_pk=build.id,
108108
commit=commit,
109-
status=BUILD_STATUS_PENDING
109+
status=BUILD_STATUS_PENDING,
110+
link_to_build=False,
110111
)
111112

112113
if version.type != EXTERNAL:

readthedocs/projects/tasks/builds.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ def on_failure(self, exc, task_id, args, kwargs, einfo):
482482
)
483483

484484
# NOTE: why we wouldn't have `self.data.build_commit` here?
485-
# This attribute is set when we get it after clonning the repository
485+
# This attribute is set when we get it after cloning the repository
486486
#
487487
# Oh, I think this is to differentiate a task triggered with
488488
# `Build.commit` than a one triggered just with the `Version` to build
@@ -508,6 +508,10 @@ def on_failure(self, exc, task_id, args, kwargs, einfo):
508508
build_pk=self.data.build['id'],
509509
commit=self.data.build_commit,
510510
status=status,
511+
# Fix bug where we were generating relative links to the version
512+
# with ``get_absolute_url``.
513+
# https://github.com/readthedocs/readthedocs.org/issues/9791
514+
link_to_build=True,
511515
)
512516

513517
# Update build object
@@ -578,6 +582,7 @@ def on_success(self, retval, task_id, args, kwargs):
578582
build_pk=self.data.build['id'],
579583
commit=self.data.build_commit,
580584
status=BUILD_STATUS_SUCCESS,
585+
link_to_build=True,
581586
)
582587

583588
# Update build object

readthedocs/projects/tasks/utils.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,21 @@ def finish_inactive_builds():
134134
)
135135

136136

137-
def send_external_build_status(version_type, build_pk, commit, status):
137+
def send_external_build_status(version_type, build_pk, commit, status, link_to_build):
138138
"""
139139
Check if build is external and Send Build Status for project external versions.
140140
141141
:param version_type: Version type e.g EXTERNAL, BRANCH, TAG
142142
:param build_pk: Build pk
143143
:param commit: commit sha of the pull/merge request
144144
:param status: build status failed, pending, or success to be sent.
145+
:param link_to_build: When True, link to the built HTML
145146
"""
146147

147148
# Send status reports for only External (pull/merge request) Versions.
148149
if version_type == EXTERNAL:
149150
# call the task that actually send the build status.
150-
send_build_status.delay(build_pk, commit, status)
151+
send_build_status.delay(build_pk, commit, status, link_to_build=link_to_build)
151152

152153

153154
class BuildRequest(Request):

readthedocs/projects/tests/test_build_tasks.py

+2
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ def test_successful_build(
333333
build_pk=self.build.pk,
334334
commit=self.build.commit,
335335
status=BUILD_STATUS_SUCCESS,
336+
link_to_build=True,
336337
)
337338

338339
build_complete.send.assert_called_once_with(
@@ -501,6 +502,7 @@ def test_failed_build(
501502
build_pk=self.build.pk,
502503
commit=self.build.commit,
503504
status=BUILD_STATUS_FAILURE,
505+
link_to_build=True,
504506
)
505507

506508
build_complete.send.assert_called_once_with(

readthedocs/rtd_tests/tests/test_celery.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
from messages_extends.models import Message
99

1010
from readthedocs.builds import tasks as build_tasks
11-
from readthedocs.builds.constants import (
12-
BUILD_STATUS_SUCCESS,
13-
EXTERNAL,
14-
LATEST,
15-
)
11+
from readthedocs.builds.constants import BUILD_STATUS_SUCCESS, EXTERNAL, LATEST
1612
from readthedocs.builds.models import Build, Version
1713
from readthedocs.oauth.models import RemoteRepository, RemoteRepositoryRelation
1814
from readthedocs.projects.models import Project
@@ -209,4 +205,3 @@ def test_send_build_status_no_remote_repo_or_social_account_gitlab(self, send_bu
209205

210206
send_build_status.assert_not_called()
211207
self.assertEqual(Message.objects.filter(user=self.eric).count(), 1)
212-

readthedocs/rtd_tests/tests/test_projects_tasks.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,18 @@ def setUp(self):
2121
@patch('readthedocs.projects.tasks.utils.send_build_status')
2222
def test_send_external_build_status_with_external_version(self, send_build_status):
2323
send_external_build_status(
24-
self.external_version.type, self.external_build.id,
25-
self.external_build.commit, BUILD_STATUS_SUCCESS
24+
self.external_version.type,
25+
self.external_build.id,
26+
self.external_build.commit,
27+
BUILD_STATUS_SUCCESS,
28+
link_to_build=True,
2629
)
2730

2831
send_build_status.delay.assert_called_once_with(
2932
self.external_build.id,
3033
self.external_build.commit,
31-
BUILD_STATUS_SUCCESS
34+
BUILD_STATUS_SUCCESS,
35+
link_to_build=False,
3236
)
3337

3438
@patch('readthedocs.projects.tasks.utils.send_build_status')

0 commit comments

Comments
 (0)