Merge lp:~cjwatson/launchpad/webhook-payload-links into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 17788
Proposed branch: lp:~cjwatson/launchpad/webhook-payload-links
Merge into: lp:launchpad
Diff against target: 81 lines (+9/-2)
4 files modified
lib/lp/code/model/gitjob.py (+2/-0)
lib/lp/code/model/tests/test_gitjob.py (+3/-1)
lib/lp/codehosting/scanner/events.py (+3/-1)
lib/lp/codehosting/scanner/tests/test_bzrsync.py (+1/-0)
To merge this branch: bzr merge lp:~cjwatson/launchpad/webhook-payload-links
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+273087@code.launchpad.net

Commit message

Add webservice links to webhook payloads.

Description of the change

Add webservice links to webhook payloads. This makes it easier to write webhooks that respond by making webservice queries without always having to look up the object first; it also gives us a better pattern for adding webhook support to other objects that don't necessarily have an obvious equivalent of shortened_path, such as merge proposals.

The links lack host name and API version since at least the API version may vary depending on the client, but they're suitable for passing to lp.load.

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/code/model/gitjob.py'
--- lib/lp/code/model/gitjob.py 2015-09-01 17:10:46 +0000
+++ lib/lp/code/model/gitjob.py 2015-10-01 15:07:28 +0000
@@ -65,6 +65,7 @@
65from lp.services.mail.sendmail import format_address_for_person65from lp.services.mail.sendmail import format_address_for_person
66from lp.services.scripts import log66from lp.services.scripts import log
67from lp.services.utils import text_delta67from lp.services.utils import text_delta
68from lp.services.webapp.publisher import canonical_url
68from lp.services.webhooks.interfaces import IWebhookSet69from lp.services.webhooks.interfaces import IWebhookSet
6970
7071
@@ -227,6 +228,7 @@
227 if old != new:228 if old != new:
228 ref_changes[ref] = {"old": old, "new": new}229 ref_changes[ref] = {"old": old, "new": new}
229 return {230 return {
231 "git_repository": canonical_url(repository, force_local_path=True),
230 "git_repository_path": repository.shortened_path,232 "git_repository_path": repository.shortened_path,
231 "ref_changes": ref_changes,233 "ref_changes": ref_changes,
232 }234 }
233235
=== modified file 'lib/lp/code/model/tests/test_gitjob.py'
--- lib/lp/code/model/tests/test_gitjob.py 2015-08-10 12:49:08 +0000
+++ lib/lp/code/model/tests/test_gitjob.py 2015-10-01 15:07:28 +0000
@@ -202,6 +202,7 @@
202 MatchesStructure(202 MatchesStructure(
203 event_type=Equals('git:push:0.1'),203 event_type=Equals('git:push:0.1'),
204 payload=MatchesDict({204 payload=MatchesDict({
205 'git_repository': Equals('/' + repository.unique_name),
205 'git_repository_path': Equals(repository.unique_name),206 'git_repository_path': Equals(repository.unique_name),
206 'ref_changes': Equals({207 'ref_changes': Equals({
207 'refs/tags/1.0': {208 'refs/tags/1.0': {
@@ -230,7 +231,8 @@
230 payload = GitRefScanJob.composeWebhookPayload(231 payload = GitRefScanJob.composeWebhookPayload(
231 repository, new_refs, removed_refs)232 repository, new_refs, removed_refs)
232 self.assertEqual(233 self.assertEqual(
233 {'git_repository_path': repository.unique_name,234 {'git_repository': '/' + repository.unique_name,
235 'git_repository_path': repository.unique_name,
234 'ref_changes': {236 'ref_changes': {
235 'refs/heads/master': {237 'refs/heads/master': {
236 'old': {'commit_sha1': sha1('refs/heads/master')},238 'old': {'commit_sha1': sha1('refs/heads/master')},
237239
=== modified file 'lib/lp/codehosting/scanner/events.py'
--- lib/lp/codehosting/scanner/events.py 2015-09-29 00:24:29 +0000
+++ lib/lp/codehosting/scanner/events.py 2015-10-01 15:07:28 +0000
@@ -10,13 +10,14 @@
10 'TipChanged',10 'TipChanged',
11 ]11 ]
1212
13
14from zope.component.interfaces import (13from zope.component.interfaces import (
15 IObjectEvent,14 IObjectEvent,
16 ObjectEvent,15 ObjectEvent,
17 )16 )
18from zope.interface import implementer17from zope.interface import implementer
1918
19from lp.services.webapp.publisher import canonical_url
20
2021
21class ScannerEvent(ObjectEvent):22class ScannerEvent(ObjectEvent):
22 """Base scanner event."""23 """Base scanner event."""
@@ -85,6 +86,7 @@
85 @staticmethod86 @staticmethod
86 def composeWebhookPayload(branch, old_revid, new_revid):87 def composeWebhookPayload(branch, old_revid, new_revid):
87 return {88 return {
89 "bzr_branch": canonical_url(branch, force_local_path=True),
88 "bzr_branch_path": branch.shortened_path,90 "bzr_branch_path": branch.shortened_path,
89 "old": {"revision_id": old_revid},91 "old": {"revision_id": old_revid},
90 "new": {"revision_id": new_revid},92 "new": {"revision_id": new_revid},
9193
=== modified file 'lib/lp/codehosting/scanner/tests/test_bzrsync.py'
--- lib/lp/codehosting/scanner/tests/test_bzrsync.py 2015-09-29 00:24:29 +0000
+++ lib/lp/codehosting/scanner/tests/test_bzrsync.py 2015-10-01 15:07:28 +0000
@@ -769,6 +769,7 @@
769 MatchesStructure(769 MatchesStructure(
770 event_type=Equals("bzr:push:0.1"),770 event_type=Equals("bzr:push:0.1"),
771 payload=MatchesDict({771 payload=MatchesDict({
772 "bzr_branch": Equals("/" + self.db_branch.unique_name),
772 "bzr_branch_path": Equals(self.db_branch.shortened_path),773 "bzr_branch_path": Equals(self.db_branch.shortened_path),
773 "old": Equals({"revision_id": old_revid}),774 "old": Equals({"revision_id": old_revid}),
774 "new": Equals({"revision_id": new_revid}),775 "new": Equals({"revision_id": new_revid}),