allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jetm...@apache.org
Subject [22/50] [abbrv] allura git commit: [#4542] ticket:728 Add ref to webhook payload
Date Tue, 24 Feb 2015 11:48:16 GMT
[#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/ib/7827
Commit: 3fc560e566c1dbd850514e368b109b2c621dabb0
Parents: a22f6f6
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Fri Feb 13 15:19:49 2015 +0000
Committer: Igor Bondarenko <jetmind2@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


Mime
View raw message