incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [05/43] git commit: [#6622] ticket:435 Convert github mardown in tickets & comments
Date Thu, 14 Nov 2013 17:36:26 GMT
[#6622] ticket:435 Convert github mardown in tickets & comments


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

Branch: refs/heads/cj/6836
Commit: b6f29e90a3c187eea388dfd776a472b489e11a76
Parents: 44a7d0a
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Mon Oct 14 14:30:29 2013 +0300
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Wed Nov 13 17:16:55 2013 +0000

----------------------------------------------------------------------
 ForgeImporters/forgeimporters/github/tracker.py |  5 +-
 ForgeImporters/forgeimporters/github/utils.py   |  2 +-
 .../forgeimporters/tests/github/test_tracker.py | 65 ++++++++++++++++++++
 3 files changed, 69 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b6f29e90/ForgeImporters/forgeimporters/github/tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tracker.py b/ForgeImporters/forgeimporters/github/tracker.py
index ebed4ed..c3c7ab4 100644
--- a/ForgeImporters/forgeimporters/github/tracker.py
+++ b/ForgeImporters/forgeimporters/github/tracker.py
@@ -49,6 +49,7 @@ from ..base import ToolImporter
 from forgetracker.tracker_main import ForgeTrackerApp
 from forgetracker import model as TM
 from forgeimporters.base import ToolImportForm
+from forgeimporters.github.utils import GitHubMarkdownConverter
 
 
 class GitHubTrackerImportForm(ToolImportForm):
@@ -169,7 +170,7 @@ class GitHubTrackerImporter(ToolImporter):
                 u'{body}').format(
                     creator=self.get_user_link(issue['user']['login']),
                     owner=owner_line,
-                    body=body,
+                    body=GitHubMarkdownConverter().convert(body),
                 )
         ticket.labels = [label['name'] for label in issue['labels']]
 
@@ -181,7 +182,7 @@ class GitHubTrackerImporter(ToolImporter):
                     self.get_user_link(comment['user']['login']))
                 body = posted_by + body
             p = ticket.discussion_thread.add_post(
-                    text = body,
+                    text = GitHubMarkdownConverter().convert(body),
                     ignore_security = True,
                     timestamp = self.parse_datetime(comment['created_at']),
                 )

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b6f29e90/ForgeImporters/forgeimporters/github/utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/utils.py b/ForgeImporters/forgeimporters/github/utils.py
index c095f81..ab66157 100644
--- a/ForgeImporters/forgeimporters/github/utils.py
+++ b/ForgeImporters/forgeimporters/github/utils.py
@@ -44,4 +44,4 @@ class GitHubMarkdownConverter(object):
 
     @classmethod
     def _convert_codeblock(cls, match):
-        return '\n~~~~%s~~~~\n'% match.group(1)
+        return '~~~~%s~~~~'% match.group(1)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b6f29e90/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 262ff1e..7cd3c90 100644
--- a/ForgeImporters/forgeimporters/tests/github/test_tracker.py
+++ b/ForgeImporters/forgeimporters/tests/github/test_tracker.py
@@ -179,3 +179,68 @@ class TestTrackerImporter(TestCase):
             text='- **assigned_to**: [luke](https://github.com/luke)',
             timestamp=datetime(2013, 9, 12, 10, 14, 0),
             ignore_security=True))
+
+    def test_github_markdown_converted_in_description(self):
+        ticket = mock.Mock()
+        body = '''Hello
+
+```python
+def hello(name):
+    print "Hello, " + name
+```'''
+        body_converted = '''*Originally created by:* [creator](https://github.com/creator)
+*Originally owned by:* [owner](https://github.com/owner)
+
+Hello
+
+~~~~
+def hello(name):
+    print "Hello, " + name
+~~~~'''
+        issue = {
+            'body': body,
+            'title': 'title',
+            'state': 'New',
+            'created_at': 'created_at',
+            'updated_at': 'updated_at',
+            'assignee': {'login': 'owner'},
+            'user': {'login': 'creator'},
+            'labels': [{'name': 'first'}, {'name': 'second'}],
+        }
+        importer = tracker.GitHubTrackerImporter()
+        with mock.patch.object(tracker, 'datetime') as dt:
+            dt.strptime.side_effect = lambda s,f: s
+            importer.process_fields(ticket, issue)
+        self.assertEqual(ticket.description.strip(), body_converted.strip())
+
+    def test_github_markdown_converted_in_comments(self):
+        ticket = mock.Mock()
+        extractor = mock.Mock()
+        body = '''Hello
+
+```python
+def hello(name):
+    print "Hello, " + name
+```'''
+        body_converted = '''*Originally posted by:* [me](https://github.com/me)
+Hello
+
+~~~~
+def hello(name):
+    print "Hello, " + name
+~~~~'''
+        issue = {'comments_url': '/comments'}
+        extractor.iter_comments.return_value = [
+                {
+                    'body': body,
+                    'created_at': '2013-08-26T16:57:53Z',
+                    'user': {'login': 'me'},
+                }
+            ]
+        importer = tracker.GitHubTrackerImporter()
+        importer.process_comments(extractor, ticket, issue)
+        self.assertEqual(ticket.discussion_thread.add_post.call_args_list[0], mock.call(
+                text=body_converted,
+                timestamp=datetime(2013, 8, 26, 16, 57, 53),
+                ignore_security=True,
+            ))


Mime
View raw message