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/11 11:29:39 UTC

[1/2] allura git commit: [#4542] ticket:723 Tweak error message

Repository: allura
Updated Branches:
  refs/heads/ib/4542 aa638e80c -> 09a2378fc


[#4542] ticket:723 Tweak error message


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

Branch: refs/heads/ib/4542
Commit: a2baef84ad83ce903f9ed732fd9e4edc7ba8a8d2
Parents: aa638e8
Author: Igor Bondarenko <je...@gmail.com>
Authored: Tue Feb 10 11:17:11 2015 +0000
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Tue Feb 10 13:00:42 2015 +0000

----------------------------------------------------------------------
 Allura/allura/tests/test_webhooks.py | 19 +++++++++++++------
 Allura/allura/webhooks.py            |  7 ++++---
 2 files changed, 17 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/a2baef84/Allura/allura/tests/test_webhooks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_webhooks.py b/Allura/allura/tests/test_webhooks.py
index ab82cb8..1879beb 100644
--- a/Allura/allura/tests/test_webhooks.py
+++ b/Allura/allura/tests/test_webhooks.py
@@ -430,9 +430,14 @@ class TestSendWebhookHelper(TestWebhookBase):
         assert_equal(
             self.h.log_msg('OK'),
             'OK: repo-push http://httpbin.org/post /adobe/adobe-1/src/')
+        response = Mock(
+            status_code=500,
+            text='that is why',
+            headers={'Content-Type': 'application/json'})
         assert_equal(
-            self.h.log_msg('Error', response=Mock(status_code=500, reason='that is why')),
-            'Error: repo-push http://httpbin.org/post /adobe/adobe-1/src/ 500 that is why')
+            self.h.log_msg('Error', response=response),
+            "Error: repo-push http://httpbin.org/post /adobe/adobe-1/src/ 500 "
+            "that is why {'Content-Type': 'application/json'}")
 
     @patch('allura.webhooks.SendWebhookHelper', autospec=True)
     def test_send_webhook_task(self, swh):
@@ -473,11 +478,12 @@ class TestSendWebhookHelper(TestWebhookBase):
             call('Retrying webhook in %s seconds', 240)])
         assert_equal(log.error.call_count, 4)
         log.error.assert_called_with(
-            'Webhook send error: %s %s %s %s %s' % (
+            'Webhook send error: %s %s %s %s %s %s' % (
                 self.wh.type, self.wh.hook_url,
                 self.wh.app_config.url(),
                 requests.post.return_value.status_code,
-                requests.post.return_value.reason))
+                requests.post.return_value.text,
+                requests.post.return_value.headers))
 
     @patch('allura.webhooks.time', autospec=True)
     @patch('allura.webhooks.requests', autospec=True)
@@ -491,11 +497,12 @@ class TestSendWebhookHelper(TestWebhookBase):
             log.info.assert_called_once_with('Retrying webhook in: %s', [])
             assert_equal(log.error.call_count, 1)
             log.error.assert_called_with(
-                'Webhook send error: %s %s %s %s %s' % (
+                'Webhook send error: %s %s %s %s %s %s' % (
                     self.wh.type, self.wh.hook_url,
                     self.wh.app_config.url(),
                     requests.post.return_value.status_code,
-                    requests.post.return_value.reason))
+                    requests.post.return_value.text,
+                    requests.post.return_value.headers))
 
 
 class TestRepoPushWebhookSender(TestWebhookBase):

http://git-wip-us.apache.org/repos/asf/allura/blob/a2baef84/Allura/allura/webhooks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/webhooks.py b/Allura/allura/webhooks.py
index ebfb3d0..0f9b54d 100644
--- a/Allura/allura/webhooks.py
+++ b/Allura/allura/webhooks.py
@@ -256,11 +256,12 @@ class SendWebhookHelper(object):
             self.webhook.type,
             self.webhook.hook_url,
             self.webhook.app_config.url())
-        if response:
-            message = '{} {} {}'.format(
+        if response is not None:
+            message = '{} {} {} {}'.format(
                 message,
                 response.status_code,
-                response.reason)
+                response.text,
+                response.headers)
         return message
 
     def send(self):


[2/2] allura git commit: [#4542] ticket:723 Change repo-push hook payload

Posted by je...@apache.org.
[#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/09a2378f
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/09a2378f
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/09a2378f

Branch: refs/heads/ib/4542
Commit: 09a2378fce36930139c62713c530712319acb327
Parents: a2baef8
Author: Igor Bondarenko <je...@gmail.com>
Authored: Tue Feb 10 13:55:28 2015 +0000
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Tue Feb 10 13:55:28 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/09a2378f/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/09a2378f/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/09a2378f/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/09a2378f/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/09a2378f/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):