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/16 12:45:07 UTC

[36/37] allura git commit: [#4542] ticket:728 Don't enforce limit if multiple branches pushed at once

[#4542] ticket:728 Don't enforce limit if multiple branches pushed at once


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/a60ccc94
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/a60ccc94
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/a60ccc94

Branch: refs/heads/ib/4542
Commit: a60ccc945e61bd0ac91ddd46e0c9abd44f2368bd
Parents: 3fc560e
Author: Igor Bondarenko <je...@gmail.com>
Authored: Fri Feb 13 16:26:31 2015 +0000
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Mon Feb 16 10:17:42 2015 +0000

----------------------------------------------------------------------
 Allura/allura/model/repo_refresh.py |  7 +++++--
 Allura/allura/webhooks.py           | 18 ++++++++++++++----
 2 files changed, 19 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/a60ccc94/Allura/allura/model/repo_refresh.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repo_refresh.py b/Allura/allura/model/repo_refresh.py
index 38ea295..1dc17ba 100644
--- a/Allura/allura/model/repo_refresh.py
+++ b/Allura/allura/model/repo_refresh.py
@@ -166,12 +166,15 @@ def refresh_repo(repo, all_commits=False, notify=True, new_clone=False):
                 commits_by_tags[t].append(commit)
 
         from allura.webhooks import RepoPushWebhookSender
+        params = []
         for b, commits in commits_by_branches.iteritems():
             ref = u'refs/heads/{}'.format(b)
-            RepoPushWebhookSender().send(commit_ids=commits, ref=ref)
+            params.append(dict(commit_ids=commits, ref=ref))
         for t, commits in commits_by_tags.iteritems():
             ref = u'refs/tags/{}'.format(t)
-            RepoPushWebhookSender().send(commit_ids=commits, ref=ref)
+            params.append(dict(commit_ids=commits, ref=ref))
+        if params:
+            RepoPushWebhookSender().send(params)
 
     log.info('Refresh complete for %s', repo.full_fs_path)
     g.post_event('repo_refreshed', len(commit_ids), all_commits, new_clone)

http://git-wip-us.apache.org/repos/asf/allura/blob/a60ccc94/Allura/allura/webhooks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/webhooks.py b/Allura/allura/webhooks.py
index d2302d8..f727b63 100644
--- a/Allura/allura/webhooks.py
+++ b/Allura/allura/webhooks.py
@@ -284,18 +284,28 @@ class WebhookSender(object):
         """Return a dict with webhook payload"""
         raise NotImplementedError('get_payload')
 
-    def send(self, **kw):
-        """Post a task that will send webhook payload"""
+    def send(self, params_or_list):
+        """Post a task that will send webhook payload
+
+        :param:`params_or_list` - dict with keyword parameters to be passed to
+        :meth:`get_payload` or a list of such dicts. If it's a list for each
+        element appropriate payload will be submitted, but limit will be
+        enforced only once for each webhook.
+        """
+        if not isinstance(params_or_list, list):
+            params_or_list = [params_or_list]
         webhooks = M.Webhook.query.find(dict(
             app_config_id=c.app.config._id,
             type=self.type,
         )).all()
         if webhooks:
-            payload = self.get_payload(**kw)
+            payloads = [self.get_payload(**params)
+                        for params in params_or_list]
             for webhook in webhooks:
                 if webhook.enforce_limit():
                     webhook.update_limit()
-                    send_webhook.post(webhook._id, payload)
+                    for payload in payloads:
+                        send_webhook.post(webhook._id, payload)
                 else:
                     log.warn('Webhook fires too often: %s. Skipping', webhook)