Merge lp:~cjwatson/launchpad/no-logtail-only-webhooks into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18533
Proposed branch: lp:~cjwatson/launchpad/no-logtail-only-webhooks
Merge into: lp:launchpad
Diff against target: 60 lines (+21/-3)
2 files modified
lib/lp/snappy/model/snapbuild.py (+4/-2)
lib/lp/snappy/tests/test_snapbuild.py (+17/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad/no-logtail-only-webhooks
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+336479@code.launchpad.net

Commit message

Only emit snap:build:0.1 webhooks from SnapBuild.updateStatus if the status has changed.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/snappy/model/snapbuild.py'
--- lib/lp/snappy/model/snapbuild.py 2017-04-27 16:22:37 +0000
+++ lib/lp/snappy/model/snapbuild.py 2018-01-23 13:39:53 +0000
@@ -1,4 +1,4 @@
1# Copyright 2015-2017 Canonical Ltd. This software is licensed under the1# Copyright 2015-2018 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4__metaclass__ = type4__metaclass__ = type
@@ -335,6 +335,7 @@
335 date_started=None, date_finished=None,335 date_started=None, date_finished=None,
336 force_invalid_transition=False):336 force_invalid_transition=False):
337 """See `IBuildFarmJob`."""337 """See `IBuildFarmJob`."""
338 old_status = self.status
338 super(SnapBuild, self).updateStatus(339 super(SnapBuild, self).updateStatus(
339 status, builder=builder, slave_status=slave_status,340 status, builder=builder, slave_status=slave_status,
340 date_started=date_started, date_finished=date_finished,341 date_started=date_started, date_finished=date_finished,
@@ -343,7 +344,8 @@
343 revision_id = slave_status.get("revision_id")344 revision_id = slave_status.get("revision_id")
344 if revision_id is not None:345 if revision_id is not None:
345 self.revision_id = unicode(revision_id)346 self.revision_id = unicode(revision_id)
346 notify(SnapBuildStatusChangedEvent(self))347 if status != old_status:
348 notify(SnapBuildStatusChangedEvent(self))
347349
348 def notify(self, extra_info=None):350 def notify(self, extra_info=None):
349 """See `IPackageBuild`."""351 """See `IPackageBuild`."""
350352
=== modified file 'lib/lp/snappy/tests/test_snapbuild.py'
--- lib/lp/snappy/tests/test_snapbuild.py 2017-10-20 13:35:42 +0000
+++ lib/lp/snappy/tests/test_snapbuild.py 2018-01-23 13:39:53 +0000
@@ -1,4 +1,4 @@
1# Copyright 2015-2017 Canonical Ltd. This software is licensed under the1# Copyright 2015-2018 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""Test snap package build features."""4"""Test snap package build features."""
@@ -255,6 +255,22 @@
255 hook.id, hook.target),255 hook.id, hook.target),
256 repr(delivery))256 repr(delivery))
257257
258 def test_updateStatus_no_change_does_not_trigger_webhooks(self):
259 # An updateStatus call that changes details such as the revision_id
260 # but that doesn't change the build's status attribute does not
261 # trigger webhooks.
262 hook = self.factory.makeWebhook(
263 target=self.build.snap, event_types=["snap:build:0.1"])
264 builder = self.factory.makeBuilder()
265 self.build.updateStatus(BuildStatus.BUILDING)
266 self.assertEqual(1, hook.deliveries.count())
267 self.build.updateStatus(
268 BuildStatus.BUILDING, builder=builder,
269 slave_status={"revision_id": "1"})
270 self.assertEqual(1, hook.deliveries.count())
271 self.build.updateStatus(BuildStatus.UPLOADING)
272 self.assertEqual(2, hook.deliveries.count())
273
258 def test_updateStatus_failure_does_not_trigger_store_uploads(self):274 def test_updateStatus_failure_does_not_trigger_store_uploads(self):
259 # A failed SnapBuild does not trigger store uploads.275 # A failed SnapBuild does not trigger store uploads.
260 self.build.snap.store_series = self.factory.makeSnappySeries()276 self.build.snap.store_series = self.factory.makeSnappySeries()