Skip to content

Commit 1a16b40

Browse files
committed
Extend webhook notifications with build status
1 parent 152ea2d commit 1a16b40

File tree

5 files changed

+31
-25
lines changed

5 files changed

+31
-25
lines changed

readthedocs/core/utils/__init__.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def prepare_build(
8484
# Avoid circular import
8585
from readthedocs.builds.models import Build
8686
from readthedocs.projects.models import Project
87-
from readthedocs.projects.tasks import update_docs_task
87+
from readthedocs.projects.tasks import update_docs_task, send_notifications
8888

8989
build = None
9090

@@ -115,6 +115,13 @@ def prepare_build(
115115
)
116116
kwargs['build_pk'] = build.pk
117117

118+
# Send only Webhook notification for build `triggered`
119+
send_notifications.delay(
120+
version.pk,
121+
build_pk=build.pk,
122+
send_email=False
123+
)
124+
118125
options = {}
119126
if project.build_queue:
120127
options['queue'] = project.build_queue

readthedocs/projects/tasks.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,6 @@ def run(
382382
self.build_force = force
383383
self.config = None
384384

385-
# send Webhook notification for build `triggered`
386-
self.send_notifications(send_email=False)
387-
388385
setup_successful = self.run_setup(record=record)
389386
if not setup_successful:
390387
return False
@@ -567,8 +564,9 @@ def run_build(self, docker, record):
567564
# TODO the build object should have an idea of these states,
568565
# extend the model to include an idea of these outcomes
569566
outcomes = self.build_docs()
570-
# send Webhook notification for build status `building`
567+
# Send only Webhook notification for build status `building`
571568
self.send_notifications(send_email=False)
569+
572570
build_id = self.build.get('id')
573571
except vcs_support_utils.LockTimeout as e:
574572
self.task.retry(exc=e, throw=False)
@@ -592,7 +590,7 @@ def run_build(self, docker, record):
592590
if self.build_env.failed:
593591
self.send_notifications()
594592

595-
# send Webhook notification for build `successful`
593+
# Send only Webhook notification for build `successful`
596594
if self.build_env.successful:
597595
self.send_notifications(send_email=False)
598596

@@ -834,6 +832,7 @@ def build_docs(self):
834832
:rtype: dict
835833
"""
836834
self.build_env.update_build(state=BUILD_STATE_BUILDING)
835+
837836
before_build.send(sender=self.version)
838837

839838
outcomes = defaultdict(lambda: False)
@@ -1455,6 +1454,7 @@ def webhook_notification(version, build, hook_url):
14551454
'slug': project.slug,
14561455
'build': {
14571456
'id': build.id,
1457+
'commit': build.commit,
14581458
'state': build.state,
14591459
'success': build.success,
14601460
'date': build.date.strftime('%Y-%m-%d %H:%M:%S'),

readthedocs/rtd_tests/tests/test_celery.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def test_update_docs_unexpected_build_exception(self, mock_build_docs):
136136
@patch('readthedocs.projects.tasks.UpdateDocsTaskStep.build_docs', new=MagicMock)
137137
@patch('readthedocs.projects.tasks.UpdateDocsTaskStep.send_notifications')
138138
@patch('readthedocs.projects.tasks.UpdateDocsTaskStep.setup_vcs')
139-
def test_only_triggered_build_notification_on_version_locked_error(self, mock_setup_vcs, mock_send_notifications):
139+
def test_no_notification_on_version_locked_error(self, mock_setup_vcs, mock_send_notifications):
140140
mock_setup_vcs.side_effect = VersionLockedError()
141141

142142
build = get(
@@ -151,8 +151,7 @@ def test_only_triggered_build_notification_on_version_locked_error(self, mock_se
151151
intersphinx=False,
152152
)
153153

154-
# only called when build is triggered
155-
mock_send_notifications.assert_called_once()
154+
mock_send_notifications.assert_not_called()
156155
self.assertTrue(result.successful())
157156

158157
def test_sync_repository(self):

readthedocs/settings/dev.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@ def LOGGING(self): # noqa - avoid pep8 N802
5959
logging['disable_existing_loggers'] = False
6060
return logging
6161

62-
@property
63-
def INSTALLED_APPS(self):
64-
apps = super().INSTALLED_APPS
65-
apps.append('debug_toolbar')
66-
return apps
67-
68-
@property
69-
def MIDDLEWARE(self):
70-
middlewares = list(super().MIDDLEWARE)
71-
middlewares.insert(0, 'debug_toolbar.middleware.DebugToolbarMiddleware')
72-
return middlewares
62+
# @property
63+
# def INSTALLED_APPS(self):
64+
# apps = super().INSTALLED_APPS
65+
# apps.append('debug_toolbar')
66+
# return apps
67+
#
68+
# @property
69+
# def MIDDLEWARE(self):
70+
# middlewares = list(super().MIDDLEWARE)
71+
# middlewares.insert(0, 'debug_toolbar.middleware.DebugToolbarMiddleware')
72+
# return middlewares
7373

7474

7575
CommunityDevSettings.load_settings(__name__)

readthedocs/urls.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@
133133
if getattr(settings, 'ALLOW_ADMIN', True):
134134
groups.append(admin_urls)
135135
if getattr(settings, 'DEBUG', False):
136-
import debug_toolbar
137-
138-
debug_urls += [
139-
url(r'^__debug__/', include(debug_toolbar.urls)),
140-
]
136+
# import debug_toolbar
137+
#
138+
# debug_urls += [
139+
# url(r'^__debug__/', include(debug_toolbar.urls)),
140+
# ]
141141
groups.append(debug_urls)
142142

143143
urlpatterns = reduce(add, groups)

0 commit comments

Comments
 (0)