allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jetm...@apache.org
Subject [16/50] [abbrv] allura git commit: [#4542] ticket:723 Change repo-push hook payload
Date Tue, 24 Feb 2015 11:48:10 GMT
[#4542] ticket:723 Change repo-push hook payload


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

Branch: refs/heads/ib/7827
Commit: 13a8a607ac69ef602ed0ef9992af310a58f92051
Parents: 1b1dcfd
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Tue Feb 10 13:55:28 2015 +0000
Committer: Igor Bondarenko <jetmind2@gmail.com>
Committed: Mon Feb 16 10:17:39 2015 +0000

----------------------------------------------------------------------
 Allura/allura/model/repository.py               | 35 +++++++-
 Allura/allura/tests/test_webhooks.py            | 12 ++-
 Allura/allura/webhooks.py                       | 11 ++-
 .../forgegit/tests/model/test_repository.py     | 88 ++++++++++++++++----
 .../forgesvn/tests/model/test_repository.py     | 73 ++++++++++++----
 5 files changed, 174 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/13a8a607/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 5650d35..0030aa5 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -939,14 +939,22 @@ class Commit(RepoObject, ActivityObject):
         self.repo = repo
 
     @LazyProperty
+    def authored_user(self):
+        return User.by_email_address(self.authored.email)
+
+    @LazyProperty
+    def committed_user(self):
+        return User.by_email_address(self.committed.email)
+
+    @LazyProperty
     def author_url(self):
-        u = User.by_email_address(self.authored.email)
+        u = self.authored_user
         if u:
             return u.url()
 
     @LazyProperty
     def committer_url(self):
-        u = User.by_email_address(self.committed.email)
+        u = self.committed_user
         if u:
             return u.url()
 
@@ -1222,6 +1230,29 @@ class Commit(RepoObject, ActivityObject):
             summary=self.summary
         )
 
+    @LazyProperty
+    def webhook_info(self):
+        return {
+            'id': self._id,
+            'url': h.absurl(self.url()),
+            'timestamp': self.authored.date,
+            'message': self.summary,
+            'author': {
+                'name': self.authored.name,
+                'email': self.authored.email,
+                'username': self.authored_user.username if self.authored_user else u'',
+            },
+            'committer': {
+                'name': self.committed.name,
+                'email': self.committed.email,
+                'username': self.committed_user.username if self.committed_user else u'',
+            },
+            'added': self.diffs.added,
+            'removed': self.diffs.removed,
+            'modified': self.diffs.changed,
+            'copied': self.diffs.copied,
+        }
+
 
 class Tree(RepoObject):
     # Ephemeral attrs

http://git-wip-us.apache.org/repos/asf/allura/blob/13a8a607/Allura/allura/tests/test_webhooks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_webhooks.py b/Allura/allura/tests/test_webhooks.py
index 1879beb..5362da7 100644
--- a/Allura/allura/tests/test_webhooks.py
+++ b/Allura/allura/tests/test_webhooks.py
@@ -541,14 +541,18 @@ class TestRepoPushWebhookSender(TestWebhookBase):
     def test_get_payload(self):
         sender = RepoPushWebhookSender()
         _ci = list(range(1, 4))
-        _se = [Mock(info=str(x)) for x in _ci]
+        _se = [Mock(webhook_info=str(x)) for x in _ci]
         with patch.object(self.git.repo, 'commit', autospec=True, side_effect=_se):
             with h.push_config(c, app=self.git):
                 result = sender.get_payload(commit_ids=_ci)
         expected_result = {
-            'url': 'http://localhost/adobe/adobe-1/src/',
-            'count': 3,
-            'revisions': ['1', '2', '3'],
+            'size': 3,
+            'commits': ['1', '2', '3'],
+            'repository': {
+                'full_name': u'/adobe/adobe-1/src/',
+                'name': u'Git',
+                'url': u'http://localhost/adobe/adobe-1/src/',
+            },
         }
         assert_equal(result, expected_result)
 

http://git-wip-us.apache.org/repos/asf/allura/blob/13a8a607/Allura/allura/webhooks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/webhooks.py b/Allura/allura/webhooks.py
index 0f9b54d..17d7ebf 100644
--- a/Allura/allura/webhooks.py
+++ b/Allura/allura/webhooks.py
@@ -356,9 +356,14 @@ class RepoPushWebhookSender(WebhookSender):
 
     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]
         payload = {
-            'url': h.absurl(app.url),
-            'count': len(commit_ids),
-            'revisions': [app.repo.commit(ci).info for ci in commit_ids],
+            'size': len(commits),
+            'commits': commits,
+            'repository': {
+                'name': app.config.options.mount_label,
+                'full_name': app.url,
+                'url': h.absurl(app.url),
+            },
         }
         return payload

http://git-wip-us.apache.org/repos/asf/allura/blob/13a8a607/ForgeGit/forgegit/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/model/test_repository.py b/ForgeGit/forgegit/tests/model/test_repository.py
index 5e86ab0..b67a7ae 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -113,6 +113,20 @@ class TestNewGit(unittest.TestCase):
                 '/p/test/src-git/ci/'
                 '1e146e67985dcd71c74de79613719bef7bddca4a/')
 
+        assert_equal(self.rev.authored_user, None)
+        assert_equal(self.rev.committed_user, None)
+        user = M.User.upsert('rick')
+        email = user.claim_address('rcopeland@geek.net')
+        email.confirmed = True
+        session(email).flush(email)
+        rev = self.repo.commit(self.rev._id)  # to update cached values of LazyProperty
+        assert_equal(rev.authored_user, user)
+        assert_equal(rev.committed_user, user)
+        assert_equal(
+            sorted(rev.webhook_info.keys()),
+            sorted(['id', 'url', 'timestamp', 'message', 'author',
+                    'committer', 'added', 'removed', 'modified', 'copied']))
+
 
 class TestGitRepo(unittest.TestCase, RepoImplTestBase):
 
@@ -521,28 +535,66 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
                 'https://user@foo.com/')
 
     def test_webhook_payload(self):
+        user = M.User.upsert('cory')
+        email = user.claim_address('cjohns@slashdotmedia.com')
+        email.confirmed = True
+        session(email).flush(email)
+        user = M.User.upsert('rick')
+        email = user.claim_address('rcopeland@geek.net')
+        email.confirmed = True
+        session(email).flush(email)
+
         sender = RepoPushWebhookSender()
         cids = list(self.repo.all_commit_ids())[:2]
         payload = sender.get_payload(commit_ids=cids)
         expected_payload = {
-            'url': 'http://localhost/p/test/src-git/',
-            'count': 2,
-            'revisions': [
-                {'author': u'Cory Johns',
-                 'author_email': u'cjohns@slashdotmedia.com',
-                 'author_url': None,
-                 'date': datetime.datetime(2013, 3, 28, 18, 54, 16),
-                 'id': u'5c47243c8e424136fd5cdd18cd94d34c66d1955c',
-                 'shortlink': u'[5c4724]',
-                 'summary': u'Not repo root'},
-                {'author': u'Rick Copeland',
-                 'author_email': u'rcopeland@geek.net',
-                 'author_url': None,
-                 'date': datetime.datetime(2010, 10, 7, 18, 44, 11),
-                 'id': u'1e146e67985dcd71c74de79613719bef7bddca4a',
-                 'shortlink': u'[1e146e]',
-                 'summary': u'Change README'}]}
-        assert_equal(payload, expected_payload)
+            'size': 2,
+            'commits': [{
+                'id': u'5c47243c8e424136fd5cdd18cd94d34c66d1955c',
+                'url': u'http://localhost/p/test/src-git/ci/5c47243c8e424136fd5cdd18cd94d34c66d1955c/',
+                'timestamp': datetime.datetime(2013, 3, 28, 18, 54, 16),
+                'message': u'Not repo root',
+                'author': {'name': u'Cory Johns',
+                           'email': u'cjohns@slashdotmedia.com',
+                           'username': 'cory'},
+                'committer': {'name': u'Cory Johns',
+                              'email': u'cjohns@slashdotmedia.com',
+                              'username': 'cory'},
+                'added': [u'bad'],
+                'removed': [],
+                'modified': [],
+                'copied': []
+            }, {
+                'id': u'1e146e67985dcd71c74de79613719bef7bddca4a',
+                'url': u'http://localhost/p/test/src-git/ci/1e146e67985dcd71c74de79613719bef7bddca4a/',
+                'timestamp': datetime.datetime(2010, 10, 7, 18, 44, 11),
+                'message': u'Change README',
+                'author': {'name': u'Rick Copeland',
+                           'email': u'rcopeland@geek.net',
+                           'username': 'rick'},
+                'committer': {'name': u'Rick Copeland',
+                              'email': u'rcopeland@geek.net',
+                              'username': 'rick'},
+                'added': [],
+                'removed': [],
+                'modified': [u'README'],
+                'copied': []
+            }],
+            'repository': {
+                'name': u'Git',
+                'full_name': u'/p/test/src-git/',
+                'url': u'http://localhost/p/test/src-git/',
+            },
+        }
+
+        def _diff(one, two):
+            from difflib import Differ
+            from pprint import pformat
+            one, two = pformat(one), pformat(two)
+            diff = Differ().compare(one.splitlines(), two.splitlines())
+            print '\n'.join(diff)
+
+        assert payload == expected_payload, _diff(expected_payload, payload)
 
 
 class TestGitImplementation(unittest.TestCase):

http://git-wip-us.apache.org/repos/asf/allura/blob/13a8a607/ForgeSVN/forgesvn/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/tests/model/test_repository.py b/ForgeSVN/forgesvn/tests/model/test_repository.py
index 5267614..030931a 100644
--- a/ForgeSVN/forgesvn/tests/model/test_repository.py
+++ b/ForgeSVN/forgesvn/tests/model/test_repository.py
@@ -1,3 +1,4 @@
+# coding: utf-8
 #       Licensed to the Apache Software Foundation (ASF) under one
 #       or more contributor license agreements.  See the NOTICE file
 #       distributed with this work for additional information
@@ -98,6 +99,13 @@ class TestNewRepo(unittest.TestCase):
         assert self.rev.tree['a']['b']['c'].ls() == []
         self.assertRaises(KeyError, lambda: self.rev.tree['a']['b']['d'])
 
+        assert_equal(self.rev.authored_user, None)
+        assert_equal(self.rev.committed_user, None)
+        assert_equal(
+            sorted(self.rev.webhook_info.keys()),
+            sorted(['id', 'url', 'timestamp', 'message', 'author',
+                    'committer', 'added', 'removed', 'modified', 'copied']))
+
 
 class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
 
@@ -575,24 +583,53 @@ class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
         cids = list(self.repo.all_commit_ids())[:2]
         payload = sender.get_payload(commit_ids=cids)
         expected_payload = {
-            'url': 'http://localhost/p/test/src/',
-            'count': 2,
-            'revisions': [
-                {'author': u'coldmind',
-                 'author_email': u'',
-                 'author_url': None,
-                 'date': datetime(2013, 11, 8, 13, 38, 11, 152000),
-                 'id': u'{}:6'.format(self.repo._id),
-                 'shortlink': '[r6]',
-                 'summary': ''},
-                {'author': u'rick446',
-                 'author_email': u'',
-                 'author_url': None,
-                 'date': datetime(2010, 11, 18, 20, 14, 21, 515000),
-                 'id': u'{}:5'.format(self.repo._id),
-                 'shortlink': '[r5]',
-                 'summary': u'Copied a => b'}]}
-        assert_equal(payload, expected_payload)
+            'size': 2,
+            'commits': [{
+                'id': u'{}:6'.format(self.repo._id),
+                'url': u'http://localhost/p/test/src/6/',
+                'timestamp': datetime(2013, 11, 8, 13, 38, 11, 152000),
+                'message': u'',
+                'author': {'name': u'coldmind',
+                           'email': u'',
+                           'username': u''},
+                'committer': {'name': u'coldmind',
+                              'email': u'',
+                              'username': u''},
+                'added': [u'/ЗРЯЧИЙ_ТА_ПОБАЧИТЬ'],
+                'removed': [],
+                'modified': [],
+                'copied': []
+            }, {
+                'id': u'{}:5'.format(self.repo._id),
+                'url': u'http://localhost/p/test/src/5/',
+                'timestamp': datetime(2010, 11, 18, 20, 14, 21, 515000),
+                'message': u'Copied a => b',
+                'author': {'name': u'rick446',
+                           'email': u'',
+                           'username': u''},
+                'committer': {'name': u'rick446',
+                              'email': u'',
+                              'username': u''},
+                'added': [u'/b'],
+                'removed': [],
+                'modified': [],
+                'copied': []
+            }],
+            'repository': {
+                'name': u'SVN',
+                'full_name': u'/p/test/src/',
+                'url': u'http://localhost/p/test/src/',
+            },
+        }
+
+        def _diff(one, two):
+            from difflib import Differ
+            from pprint import pformat
+            one, two = pformat(one), pformat(two)
+            diff = Differ().compare(one.splitlines(), two.splitlines())
+            print '\n'.join(diff)
+
+        assert payload == expected_payload, _diff(expected_payload, payload)
 
 
 class TestSVNRev(unittest.TestCase):


Mime
View raw message