← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/webhook-payload-links into lp:launchpad.

Commit message:
Add webservice links to webhook payloads.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #342729 in Launchpad itself: "Should support post-commit webhooks"
  https://bugs.launchpad.net/launchpad/+bug/342729

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/webhook-payload-links/+merge/273087

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.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/webhook-payload-links into lp:launchpad.
=== 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 @@
 from lp.services.mail.sendmail import format_address_for_person
 from lp.services.scripts import log
 from lp.services.utils import text_delta
+from lp.services.webapp.publisher import canonical_url
 from lp.services.webhooks.interfaces import IWebhookSet
 
 
@@ -227,6 +228,7 @@
             if old != new:
                 ref_changes[ref] = {"old": old, "new": new}
         return {
+            "git_repository": canonical_url(repository, force_local_path=True),
             "git_repository_path": repository.shortened_path,
             "ref_changes": ref_changes,
             }

=== 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 @@
             MatchesStructure(
                 event_type=Equals('git:push:0.1'),
                 payload=MatchesDict({
+                    'git_repository': Equals('/' + repository.unique_name),
                     'git_repository_path': Equals(repository.unique_name),
                     'ref_changes': Equals({
                         'refs/tags/1.0': {
@@ -230,7 +231,8 @@
         payload = GitRefScanJob.composeWebhookPayload(
             repository, new_refs, removed_refs)
         self.assertEqual(
-            {'git_repository_path': repository.unique_name,
+            {'git_repository': '/' + repository.unique_name,
+             'git_repository_path': repository.unique_name,
              'ref_changes': {
                 'refs/heads/master': {
                     'old': {'commit_sha1': sha1('refs/heads/master')},

=== 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 @@
     'TipChanged',
     ]
 
-
 from zope.component.interfaces import (
     IObjectEvent,
     ObjectEvent,
     )
 from zope.interface import implementer
 
+from lp.services.webapp.publisher import canonical_url
+
 
 class ScannerEvent(ObjectEvent):
     """Base scanner event."""
@@ -85,6 +86,7 @@
     @staticmethod
     def composeWebhookPayload(branch, old_revid, new_revid):
         return {
+            "bzr_branch": canonical_url(branch, force_local_path=True),
             "bzr_branch_path": branch.shortened_path,
             "old": {"revision_id": old_revid},
             "new": {"revision_id": new_revid},

=== 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 @@
             MatchesStructure(
                 event_type=Equals("bzr:push:0.1"),
                 payload=MatchesDict({
+                    "bzr_branch": Equals("/" + self.db_branch.unique_name),
                     "bzr_branch_path": Equals(self.db_branch.shortened_path),
                     "old": Equals({"revision_id": old_revid}),
                     "new": Equals({"revision_id": new_revid}),


Follow ups