incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [26/50] git commit: [#6535] ticket:424 Fetch issue events from github
Date Tue, 24 Sep 2013 17:08:05 GMT
[#6535] ticket:424 Fetch issue events from github


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

Branch: refs/heads/cj/6422
Commit: 2c831e3156c91d135156c4d219952d7af4757522
Parents: 961b141
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Tue Sep 17 14:03:52 2013 +0300
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Thu Sep 19 14:46:51 2013 +0000

----------------------------------------------------------------------
 ForgeImporters/forgeimporters/github/__init__.py  |  8 ++++++++
 .../forgeimporters/tests/github/test_extractor.py | 18 ++++++++++++++++++
 2 files changed, 26 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2c831e31/ForgeImporters/forgeimporters/github/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/__init__.py b/ForgeImporters/forgeimporters/github/__init__.py
index 35bbff7..3d3caac 100644
--- a/ForgeImporters/forgeimporters/github/__init__.py
+++ b/ForgeImporters/forgeimporters/github/__init__.py
@@ -32,6 +32,7 @@ class GitHubProjectExtractor(base.ProjectExtractor):
             'issues': 'https://api.github.com/repos/{project_name}/issues',
         }
     POSSIBLE_STATES = ('opened', 'closed')
+    SUPPORTED_ISSUE_EVENTS = ('closed', 'reopened', 'assigned')
     NEXT_PAGE_URL_RE = re.compile(r'<([^>]*)>; rel="next"')
 
     def get_next_page_url(self, link):
@@ -83,3 +84,10 @@ class GitHubProjectExtractor(base.ProjectExtractor):
         comments = self.get_page(comments_url)
         for comment in comments:
             yield comment
+
+    def iter_events(self, issue):
+        events_url = issue['events_url']
+        events = self.get_page(events_url)
+        for event in events:
+            if event.get('event') in self.SUPPORTED_ISSUE_EVENTS:
+                yield event

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2c831e31/ForgeImporters/forgeimporters/tests/github/test_extractor.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/github/test_extractor.py b/ForgeImporters/forgeimporters/tests/github/test_extractor.py
index c7734fa..e29a533 100644
--- a/ForgeImporters/forgeimporters/tests/github/test_extractor.py
+++ b/ForgeImporters/forgeimporters/tests/github/test_extractor.py
@@ -46,6 +46,14 @@ class TestGitHubProjectExtractor(TestCase):
     ]
     ISSUE_COMMENTS = [u'hello', u'mocked_comment']
     ISSUE_COMMENTS_PAGE2 = [u'hello2', u'mocked_comment2']
+    ISSUE_EVENTS = [
+        {u'event': u'closed'},
+        {u'event': u'reopened'},
+    ]
+    ISSUE_EVENTS_PAGE2 = [
+        {u'event': u'assigned'},
+        {u'event': u'not-supported-event'},
+    ]
 
     def mocked_urlopen(self, url):
         headers = {}
@@ -63,6 +71,11 @@ class TestGitHubProjectExtractor(TestCase):
             headers = {'Link': '</comments?page=2>; rel="next"'}
         elif url.endswith('/comments?page=2'):
             response = StringIO(json.dumps(self.ISSUE_COMMENTS_PAGE2))
+        elif url.endswith('/events'):
+            response = StringIO(json.dumps(self.ISSUE_EVENTS))
+            headers = {'Link': '</events?page=2>; rel="next"'}
+        elif url.endswith('/events?page=2'):
+            response = StringIO(json.dumps(self.ISSUE_EVENTS_PAGE2))
 
         response.info = lambda: headers
         return response
@@ -95,3 +108,8 @@ class TestGitHubProjectExtractor(TestCase):
         mock_issue = {'comments_url': '/issues/1/comments'}
         comments = list(self.extractor.iter_comments(mock_issue))
         self.assertEqual(comments, self.ISSUE_COMMENTS + self.ISSUE_COMMENTS_PAGE2)
+
+    def test_iter_events(self):
+        mock_issue = {'events_url': '/issues/1/events'}
+        events = list(self.extractor.iter_events(mock_issue))
+        self.assertEqual(events, self.ISSUE_EVENTS + self.ISSUE_EVENTS_PAGE2[:1])


Mime
View raw message