You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by je...@apache.org on 2015/02/25 16:33:18 UTC
[19/28] allura git commit: [#7832] ticket:731 Webhook GET endpoint
[#7832] ticket:731 Webhook GET endpoint
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/0e12bbec
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/0e12bbec
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/0e12bbec
Branch: refs/heads/ib/7832
Commit: 0e12bbec747c499ed382cba66faa9a2f0b8fa0e6
Parents: f9a25c4
Author: Igor Bondarenko <je...@gmail.com>
Authored: Fri Feb 20 12:14:28 2015 +0000
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Wed Feb 25 13:51:03 2015 +0000
----------------------------------------------------------------------
Allura/allura/lib/repository.py | 7 +++++++
Allura/allura/tests/test_webhooks.py | 17 +++++++++++++++++
Allura/allura/webhooks.py | 19 +++++++++++++++++++
3 files changed, 43 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/0e12bbec/Allura/allura/lib/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/repository.py b/Allura/allura/lib/repository.py
index 07b1b06..8fd414f 100644
--- a/Allura/allura/lib/repository.py
+++ b/Allura/allura/lib/repository.py
@@ -309,3 +309,10 @@ class RestWebhooksLookup(BaseController):
}
return {'webhooks': [hook.__json__() for hook in configured_hooks],
'limits': limits}
+
+ @expose()
+ def _lookup(self, name, *remainder):
+ for hook in self.app._webhooks:
+ if hook.type == name and hook.api_controller:
+ return hook.api_controller(hook, self.app), remainder
+ raise exc.HTTPNotFound, name
http://git-wip-us.apache.org/repos/asf/allura/blob/0e12bbec/Allura/allura/tests/test_webhooks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_webhooks.py b/Allura/allura/tests/test_webhooks.py
index c758df1..5bbee21 100644
--- a/Allura/allura/tests/test_webhooks.py
+++ b/Allura/allura/tests/test_webhooks.py
@@ -713,3 +713,20 @@ class TestWebhookRestController(TestRestApiBase):
'limits': {'repo-push': {'max': 3, 'used': 3}},
}
dd.assert_equal(r.json, expected)
+
+ def test_webhook_GET_404(self):
+ r = self.api_get(self.url + '/repo-push/invalid')
+ assert_equal(r.status_int, 404)
+
+ def test_webhook_GET(self):
+ webhook = self.webhooks[0]
+ r = self.api_get('{}/repo-push/{}'.format(self.url, webhook._id))
+ expected = {
+ '_id': unicode(webhook._id),
+ 'url': 'http://localhost/rest/adobe/adobe-1/admin'
+ '/src/webhooks/repo-push/{}'.format(webhook._id),
+ 'type': 'repo-push',
+ 'hook_url': 'http://httpbin.org/post/0',
+ 'mod_date': unicode(webhook.mod_date),
+ }
+ dd.assert_equal(r.json, expected)
http://git-wip-us.apache.org/repos/asf/allura/blob/0e12bbec/Allura/allura/webhooks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/webhooks.py b/Allura/allura/webhooks.py
index 2fa411f..dffaa21 100644
--- a/Allura/allura/webhooks.py
+++ b/Allura/allura/webhooks.py
@@ -191,6 +191,24 @@ class WebhookController(BaseController):
'form': form}
+class WebhookRestController(BaseController):
+ def __init__(self, sender, app):
+ super(WebhookRestController, self).__init__()
+ self.sender = sender()
+ self.app = app
+ self.create_form = WebhookController.create_form
+ self.edit_form = WebhookController.edit_form
+
+ @expose('json:')
+ def _default(self, webhook, **kw):
+ form = self.edit_form(self.sender, self.app)
+ try:
+ wh = form.fields['webhook'].to_python(webhook)
+ except Invalid:
+ raise exc.HTTPNotFound()
+ return wh.__json__()
+
+
class SendWebhookHelper(object):
def __init__(self, webhook, payload):
self.webhook = webhook
@@ -278,6 +296,7 @@ class WebhookSender(object):
type = None
triggered_by = []
controller = WebhookController
+ api_controller = WebhookRestController
def get_payload(self, **kw):
"""Return a dict with webhook payload"""