incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [28/41] git commit: [#6535] ticket:424 Import events
Date Thu, 19 Sep 2013 16:22:00 GMT
[#6535] ticket:424 Import events


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

Branch: refs/heads/db/5822
Commit: ae6b9e1f0811a0f21541cb1fd6d093c66f9b793c
Parents: 2c831e3
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Tue Sep 17 14:54:34 2013 +0300
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Thu Sep 19 14:46:51 2013 +0000

----------------------------------------------------------------------
 ForgeImporters/forgeimporters/github/tracker.py | 30 ++++++++++++++
 .../forgeimporters/tests/github/test_tracker.py | 41 +++++++++++++++++++-
 2 files changed, 70 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ae6b9e1f/ForgeImporters/forgeimporters/github/tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tracker.py b/ForgeImporters/forgeimporters/github/tracker.py
index 36014be..6c7cf73 100644
--- a/ForgeImporters/forgeimporters/github/tracker.py
+++ b/ForgeImporters/forgeimporters/github/tracker.py
@@ -105,6 +105,7 @@ class GitHubTrackerImporter(ToolImporter):
                         ticket_num=ticket_num)
                     self.process_fields(ticket, issue)
                     self.process_comments(extractor, ticket, issue)
+                    self.process_events(extractor, ticket, issue)
                     self.process_milestones(ticket, issue)
                     session(ticket).flush(ticket)
                     session(ticket).expunge(ticket)
@@ -117,6 +118,12 @@ class GitHubTrackerImporter(ToolImporter):
         finally:
             M.session.artifact_orm_session._get().skip_mod_date = False
 
+    def parse_datetime(self, datetime_string):
+        return datetime.strptime(datetime_string, '%Y-%m-%dT%H:%M:%SZ')
+
+    def get_user_link(self, user):
+        return u'[{0}](https://github.com/{0})'.format(user)
+
     def process_fields(self, ticket, issue):
         ticket.summary = issue['title']
         ticket.status = issue['state']
@@ -155,6 +162,29 @@ class GitHubTrackerImporter(ToolImporter):
                 )
             p.add_multiple_attachments(attachments)
 
+    def process_events(self, extractor, ticket, issue):
+        for event in extractor.iter_events(issue):
+            prefix = text = ''
+            if event['event'] in ('reopened', 'closed'):
+                prefix = '*Ticket changed by: {}*\n\n'.format(
+                        self.get_user_link(event['actor']['login']))
+            if event['event'] == 'reopened':
+                text = '- **status**: closed --> open'
+            elif event['event'] == 'closed':
+                text = '- **status**: open --> closed'
+            elif event['event'] == 'assigned':
+                text = '- **assigned_to**: {}'.format(
+                        self.get_user_link(event['actor']['login']))
+
+            text = prefix + text
+            if not text:
+                continue
+            ticket.discussion_thread.add_post(
+                text = text,
+                ignore_security = True,
+                timestamp = self.parse_datetime(event['created_at'])
+            )
+
     def process_milestones(self, ticket, issue):
         if issue['milestone']:
             title = issue['milestone']['title']

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ae6b9e1f/ForgeImporters/forgeimporters/tests/github/test_tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/github/test_tracker.py b/ForgeImporters/forgeimporters/tests/github/test_tracker.py
index 9059a99..1376e55 100644
--- a/ForgeImporters/forgeimporters/tests/github/test_tracker.py
+++ b/ForgeImporters/forgeimporters/tests/github/test_tracker.py
@@ -130,4 +130,43 @@ class TestTrackerImporter(TestCase):
                 text='*Originally posted by: [me](https://github.com/me)*\nhello',
                 timestamp=datetime(2013, 8, 26, 16, 57, 53),
                 ignore_security=True,
-            ))
\ No newline at end of file
+            ))
+
+    def test_process_events(self):
+        ticket = mock.Mock()
+        extractor = mock.Mock()
+        issue = {'events_url': '/events'}
+        extractor.iter_events.return_value = [
+            {
+                'actor': {'login': 'darth'},
+                'created_at': '2013-09-12T09:58:49Z',
+                'event': 'closed',
+            },
+            {
+                'actor': {'login': 'yoda'},
+                'created_at': '2013-09-12T10:13:20Z',
+                'event': 'reopened',
+            },
+            {
+                'actor': {'login': 'luke'},
+                'created_at': '2013-09-12T10:14:00Z',
+                'event': 'assigned',
+            },
+        ]
+        importer = tracker.GitHubTrackerImporter()
+        importer.process_events(extractor, ticket, issue)
+        args = ticket.discussion_thread.add_post.call_args_list
+        self.assertEqual(args[0], mock.call(
+            text='*Ticket changed by: [darth](https://github.com/darth)*\n\n'
+                 '- **status**: open --> closed',
+            timestamp=datetime(2013, 9, 12, 9, 58, 49),
+            ignore_security=True))
+        self.assertEqual(args[1], mock.call(
+            text='*Ticket changed by: [yoda](https://github.com/yoda)*\n\n'
+                 '- **status**: closed --> open',
+            timestamp=datetime(2013, 9, 12, 10, 13, 20),
+            ignore_security=True))
+        self.assertEqual(args[2], mock.call(
+            text='- **assigned_to**: [luke](https://github.com/luke)',
+            timestamp=datetime(2013, 9, 12, 10, 14, 0),
+            ignore_security=True))


Mime
View raw message