You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2015/02/16 22:16:07 UTC

[17/23] allura git commit: [#4542] ticket:728 Add ref to webhook payload

[#4542] ticket:728 Add ref to webhook payload


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

Branch: refs/heads/master
Commit: 3fc560e566c1dbd850514e368b109b2c621dabb0
Parents: a22f6f6
Author: Igor Bondarenko <je...@gmail.com>
Authored: Fri Feb 13 15:19:49 2015 +0000
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Mon Feb 16 10:17:41 2015 +0000

----------------------------------------------------------------------
 Allura/allura/model/repo_refresh.py | 26 +++++++++++++++++++++++++-
 Allura/allura/webhooks.py           | 22 +++++++++++++++++++++-
 2 files changed, 46 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/3fc560e5/Allura/allura/model/repo_refresh.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repo_refresh.py b/Allura/allura/model/repo_refresh.py
index 86953cc..38ea295 100644
--- a/Allura/allura/model/repo_refresh.py
+++ b/Allura/allura/model/repo_refresh.py
@@ -134,6 +134,10 @@ def refresh_repo(repo, all_commits=False, notify=True, new_clone=False):
                 log.info('Compute last commit info %d: %s', (i + 1), ci._id)
 
     if not all_commits and not new_clone:
+        commits_by_branches = {}
+        commits_by_tags = {}
+        current_branches = []
+        current_tags = []
         for commit in commit_ids:
             new = repo.commit(commit)
             user = User.by_email_address(new.committed.email)
@@ -146,8 +150,28 @@ def refresh_repo(repo, all_commits=False, notify=True, new_clone=False):
             g.director.create_activity(actor, 'committed', new,
                                        related_nodes=[repo.app_config.project],
                                        tags=['commit', repo.tool.lower()])
+
+            branches, tags = repo.symbolics_for_commit(new)
+            if branches:
+                current_branches = branches
+            if tags:
+                current_tags = tags
+            for b in current_branches:
+                if b not in commits_by_branches.keys():
+                    commits_by_branches[b] = []
+                commits_by_branches[b].append(commit)
+            for t in current_tags:
+                if t not in commits_by_tags.keys():
+                    commits_by_tags[t] = []
+                commits_by_tags[t].append(commit)
+
         from allura.webhooks import RepoPushWebhookSender
-        RepoPushWebhookSender().send(commit_ids=commit_ids)
+        for b, commits in commits_by_branches.iteritems():
+            ref = u'refs/heads/{}'.format(b)
+            RepoPushWebhookSender().send(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)
 
     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/3fc560e5/Allura/allura/webhooks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/webhooks.py b/Allura/allura/webhooks.py
index 233c3d5..d2302d8 100644
--- a/Allura/allura/webhooks.py
+++ b/Allura/allura/webhooks.py
@@ -36,7 +36,6 @@ from paste.deploy.converters import asint, aslist
 
 from allura.controllers import BaseController
 from allura.lib import helpers as h
-from allura.lib import validators as av
 from allura.lib.decorators import require_post, task
 from allura.lib.utils import DateJSONEncoder
 from allura import model as M
@@ -318,16 +317,37 @@ class RepoPushWebhookSender(WebhookSender):
     type = 'repo-push'
     triggered_by = ['git', 'hg', 'svn']
 
+    def _before(self, repo, commit_ids):
+        if len(commit_ids) > 0:
+            ci = commit_ids[-1]
+            parents = repo.commit(ci).parent_ids
+            if len(parents) > 0:
+                # Merge commit will have multiple parents. As far as I can tell
+                # the last one will be the branch head before merge
+                return parents[-1]
+        return u''
+
+    def _after(self, repo, commit_ids):
+        if len(commit_ids) > 0:
+            return commit_ids[0]
+        return u''
+
     def get_payload(self, commit_ids, **kw):
         app = kw.get('app') or c.app
         commits = [app.repo.commit(ci).webhook_info for ci in commit_ids]
+        before = self._before(app.repo, commit_ids)
+        after = self._after(app.repo, commit_ids)
         payload = {
             'size': len(commits),
             'commits': commits,
+            'before': before,
+            'after': after,
             'repository': {
                 'name': app.config.options.mount_label,
                 'full_name': app.url,
                 'url': h.absurl(app.url),
             },
         }
+        if kw.get('ref'):
+            payload['ref'] = kw['ref']
         return payload