You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2013/11/13 18:19:20 UTC

[01/21] git commit: [#6622] ticket:435 convert github markup

Updated Branches:
  refs/heads/master a4e46b7ab -> 479c43e4c


[#6622] ticket:435  convert github markup


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

Branch: refs/heads/master
Commit: 18b4e34e9e5893ed7b92719442bc143faf7f49ce
Parents: a4e46b7
Author: Yuriy Arhipov <yu...@yandex.ru>
Authored: Thu Oct 10 12:10:34 2013 +0400
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Nov 13 17:16:54 2013 +0000

----------------------------------------------------------------------
 .../forgeimporters/github/tests/test_wiki.py    | 36 ++++++++++++++++++++
 ForgeImporters/forgeimporters/github/wiki.py    |  4 ++-
 2 files changed, 39 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/18b4e34e/ForgeImporters/forgeimporters/github/tests/test_wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tests/test_wiki.py b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
index 50c905d..bb2a383 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_wiki.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
@@ -479,6 +479,42 @@ some text and **[Tips n' Tricks]**
         result = u'<p><strong>[[this checklist|Troubleshooting]]</strong></p>'
         assert_equal(f(source, 't.textile').strip(), result)
 
+    def test_convert_sha_github_markup(self):
+        html = 'SHA: 16c999e8c71134401a78d4d46435517b2271d6ac'
+        importer = GitHubWikiImporter()
+        result = importer.convert_github_markup(html)
+        assert_equal(result, 'SHA: [16c999]')
+
+    def test_convert_user_sha_github_markup(self):
+        html = 'User@SHA: mojombo@16c999e8c71134401a78d4d46435517b2271d6ac'
+        importer = GitHubWikiImporter()
+        result = importer.convert_github_markup(html)
+        assert_equal(result, 'User@SHA:[16c999]')
+
+    def test_convert_user_repo_sha_github_markup(self):
+        html = 'User/Repository@SHA: mojombo/github-flavored-markdown@16c999e8c71134401a78d4d46435517b2271d6ac'
+        importer = GitHubWikiImporter()
+        result = importer.convert_github_markup(html)
+        assert_equal(result, 'User/Repository@SHA: [16c999]')
+
+    def test_convert_ticket_github_markup(self):
+        html = 'Ticket: #1'
+        importer = GitHubWikiImporter()
+        result = importer.convert_github_markup(html)
+        assert_equal(result, 'Ticket: [#1]')
+
+    def test_convert_username_ticket_github_markup(self):
+        html = 'User#Num: user#1'
+        importer = GitHubWikiImporter()
+        result = importer.convert_github_markup(html)
+        assert_equal(result, 'User#Num: [#1]')
+
+    def test_convert_username_repo_ticket_github_markup(self):
+        html = 'User/Repository#Num: user/repo#1'
+        importer = GitHubWikiImporter()
+        result = importer.convert_github_markup(html)
+        assert_equal(result, 'User/Repository#Num: [#1]')
+
 
 class TestGitHubWikiImportController(TestController, TestCase):
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/18b4e34e/ForgeImporters/forgeimporters/github/wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/wiki.py b/ForgeImporters/forgeimporters/github/wiki.py
index fff43ad..f95ba44 100644
--- a/ForgeImporters/forgeimporters/github/wiki.py
+++ b/ForgeImporters/forgeimporters/github/wiki.py
@@ -264,7 +264,7 @@ class GitHubWikiImporter(ToolImporter):
         """
         name, ext = os.path.splitext(filename)
         if ext in self.markdown_exts:
-            return text
+            return self.convert_github_markup(text)
 
         try:
             import html2text
@@ -394,6 +394,7 @@ class GitHubWikiImporter(ToolImporter):
                     a.setString(new_prefix + new_page)
         return unicode(soup)
 
+
     def _prepare_textile_text(self, text):
         # need to convert lists properly
         text_lines = text.splitlines()
@@ -406,3 +407,4 @@ class GitHubWikiImporter(ToolImporter):
         # so these tags will not be affected by converter
         text = text.replace('[[', '<notextile>[[').replace(']]', ']]</notextile>')
         return text
+


[11/21] git commit: [#6622] ticket:435 Fix code block regex

Posted by br...@apache.org.
[#6622] ticket:435 Fix code block regex


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

Branch: refs/heads/master
Commit: 88365c69c23f5351d944f39e0c3859bd1cfe84c7
Parents: d7ee191
Author: Igor Bondarenko <je...@gmail.com>
Authored: Mon Oct 14 16:33:15 2013 +0300
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Nov 13 17:16:56 2013 +0000

----------------------------------------------------------------------
 .../forgeimporters/github/tests/test_utils.py   | 20 +++++++++++++++++++-
 ForgeImporters/forgeimporters/github/utils.py   |  2 +-
 2 files changed, 20 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/88365c69/ForgeImporters/forgeimporters/github/tests/test_utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tests/test_utils.py b/ForgeImporters/forgeimporters/github/tests/test_utils.py
index 3ce8d29..e3ba75c 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_utils.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_utils.py
@@ -76,6 +76,24 @@ class TestGitHubMarkdownConverter(object):
     def test_convert_code_blocks(self):
         text = u'''```python
 print "Hello!"
+```
+
+Two code blocks here!
+
+```
+for (var i = 0; i < a.length; i++) {
+    console.log(i);
+}
 ```'''
-        result = u'~~~~\nprint "Hello!"\n~~~~'
+        result = u'''~~~~
+print "Hello!"
+~~~~
+
+Two code blocks here!
+
+~~~~
+for (var i = 0; i < a.length; i++) {
+    console.log(i);
+}
+~~~~'''
         assert_equal(self.conv.convert(text).strip(), result)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/88365c69/ForgeImporters/forgeimporters/github/utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/utils.py b/ForgeImporters/forgeimporters/github/utils.py
index da50c2d..f00140d 100644
--- a/ForgeImporters/forgeimporters/github/utils.py
+++ b/ForgeImporters/forgeimporters/github/utils.py
@@ -30,7 +30,7 @@ class GitHubMarkdownConverter(object):
         _re = re.compile(r'~~(.*)~~',)
         text = _re.sub(self._convert_strikethrough, text)
 
-        _re = re.compile(r'```\w*(.*)```', re.DOTALL)
+        _re = re.compile(r'```\w*(.*?)```', re.DOTALL)
         text = _re.sub(self._convert_codeblock, text)
         return text
 


[07/21] git commit: [#6622] ticket:435 Fix ticket regex

Posted by br...@apache.org.
[#6622] ticket:435 Fix ticket regex


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

Branch: refs/heads/master
Commit: 9e9b826f9ba2389f4de23166aeaaca717ae91415
Parents: ba53605
Author: Igor Bondarenko <je...@gmail.com>
Authored: Mon Oct 14 15:10:18 2013 +0300
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Nov 13 17:16:55 2013 +0000

----------------------------------------------------------------------
 ForgeImporters/forgeimporters/github/tests/test_utils.py | 6 ++++++
 ForgeImporters/forgeimporters/github/utils.py            | 4 ++--
 2 files changed, 8 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9e9b826f/ForgeImporters/forgeimporters/github/tests/test_utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tests/test_utils.py b/ForgeImporters/forgeimporters/github/tests/test_utils.py
index 44d186a..0b86623 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_utils.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_utils.py
@@ -43,6 +43,12 @@ class TestGitHubMarkdownConverter(object):
         result = self.conv.convert(text)
         assert_equal(result, 'Ticket [#1]')
 
+        # github treats '#' in the begining as a header
+        text = '#1'
+        assert_equal(self.conv.convert(text), '#1')
+        text = '  #1'
+        assert_equal(self.conv.convert(text), '  #1')
+
     def test_convert_username_ticket(self):
         text = 'user#1'
         result = self.conv.convert(text)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9e9b826f/ForgeImporters/forgeimporters/github/utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/utils.py b/ForgeImporters/forgeimporters/github/utils.py
index 282e312..f74f8eb 100644
--- a/ForgeImporters/forgeimporters/github/utils.py
+++ b/ForgeImporters/forgeimporters/github/utils.py
@@ -8,7 +8,7 @@ class GitHubMarkdownConverter(object):
         self.project = '%s:%s' % (project, mount_point)
 
     def convert(self, text):
-        _re = re.compile('\S+\s+(#\d+)')
+        _re = re.compile('(\S+\s+)(#\d+)')
         text = _re.sub(self._convert_ticket, text)
 
         _re = re.compile('\S*/\S*@([0-9a-f]{40})')
@@ -31,7 +31,7 @@ class GitHubMarkdownConverter(object):
         return '%s[%s]%s' % (match.group(1), match.group(2)[:6], match.group(3))
 
     def _convert_ticket(self, match):
-        return '[%s]' % match.group(1)
+        return '%s[%s]' % match.groups()
 
     def _convert_user_sha(self, match):
         return '[%s]' % (match.group(1)[:6])


[08/21] git commit: [#6622] ticket:435 Fix sha regex

Posted by br...@apache.org.
[#6622] ticket:435 Fix sha regex


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

Branch: refs/heads/master
Commit: ba536053652354679c45fc2e79c0cf678576aa92
Parents: b6f29e9
Author: Igor Bondarenko <je...@gmail.com>
Authored: Mon Oct 14 15:07:03 2013 +0300
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Nov 13 17:16:55 2013 +0000

----------------------------------------------------------------------
 .../forgeimporters/github/tests/test_utils.py   | 75 +++++++++++++++-----
 ForgeImporters/forgeimporters/github/utils.py   | 49 +++++++------
 2 files changed, 80 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ba536053/ForgeImporters/forgeimporters/github/tests/test_utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tests/test_utils.py b/ForgeImporters/forgeimporters/github/tests/test_utils.py
index 8711312..44d186a 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_utils.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_utils.py
@@ -6,34 +6,71 @@ from forgeimporters.github.utils import GitHubMarkdownConverter
 class TestGitHubMarkdownConverter(object):
 
     def setUp(self):
-        self.conv = GitHubMarkdownConverter
+        self.conv = GitHubMarkdownConverter('user', 'project', 'p', 'mount')
 
-    def test_convert_sha_github_markup(self):
-        text = 'SHA: 16c999e8c71134401a78d4d46435517b2271d6ac'
+    def test_convert_sha(self):
+        text = '16c999e8c71134401a78d4d46435517b2271d6ac'
         result = self.conv.convert(text)
-        assert_equal(result, 'SHA: [16c999]')
+        assert_equal(result, '[16c999]')
 
-    def test_convert_user_sha_github_markup(self):
-        text = 'User@SHA: mojombo@16c999e8c71134401a78d4d46435517b2271d6ac'
+        text = 'some context  16c999e8c71134401a78d4d46435517b2271d6ac '
         result = self.conv.convert(text)
-        assert_equal(result, 'User@SHA:[16c999]')
+        assert_equal(result, 'some context  [16c999] ')
 
-    def test_convert_user_repo_sha_github_markup(self):
-        text = 'User/Repository@SHA: mojombo/github-flavored-markdown@16c999e8c71134401a78d4d46435517b2271d6ac'
+    def test_convert_user_sha(self):
+        text = 'user@16c999e8c71134401a78d4d46435517b2271d6ac'
         result = self.conv.convert(text)
-        assert_equal(result, 'User/Repository@SHA: [16c999]')
+        assert_equal(result, '[16c999]')
 
-    def test_convert_ticket_github_markup(self):
-        text = 'Ticket: #1'
+        # Not an owner of current project
+        text = 'another-user@16c999e8c71134401a78d4d46435517b2271d6ac'
         result = self.conv.convert(text)
-        assert_equal(result, 'Ticket: [#1]')
+        assert_equal(result, text)
 
-    def test_convert_username_ticket_github_markup(self):
-        text = 'User#Num: user#1'
+    def test_convert_user_repo_sha(self):
+        text = 'user/project@16c999e8c71134401a78d4d46435517b2271d6ac'
         result = self.conv.convert(text)
-        assert_equal(result, 'User#Num: [#1]')
+        assert_equal(result, '[p:mount:16c999e8c71134401a78d4d46435517b2271d6ac]')
 
-    def test_convert_username_repo_ticket_github_markup(self):
-        text = 'User/Repository#Num: user/repo#1'
+        # Not a current project
+        text = 'user/p@16c999e8c71134401a78d4d46435517b2271d6ac'
         result = self.conv.convert(text)
-        assert_equal(result, 'User/Repository#Num: [#1]')
+        assert_equal(result, '[user/project@16c999e8c71134401a78d4d46435517b2271d6ac]'
+                             '(https://github.com/u/p/commit/16c999e8c71134401a78d4d46435517b2271d6ac)')
+
+    def test_convert_ticket(self):
+        text = 'Ticket #1'
+        result = self.conv.convert(text)
+        assert_equal(result, 'Ticket [#1]')
+
+    def test_convert_username_ticket(self):
+        text = 'user#1'
+        result = self.conv.convert(text)
+        assert_equal(result, '[#1]')
+
+        # Not an owner of current project
+        text = 'another-user#1'
+        result = self.conv.convert(text)
+        assert_equal(result, 'another-user#1')
+
+    def test_convert_username_repo_ticket(self):
+        text = 'user/project#1'
+        result = self.conv.convert(text)
+        assert_equal(result, '[p:mount:#1]')
+
+        # Not a current project
+        text = 'user/p#1'
+        result = self.conv.convert(text)
+        assert_equal(result, '[user/project@16c999e8c71134401a78d4d46435517b2271d6ac]'
+                             '(https://github.com/u/p/issues/1)')
+
+    def test_convert_strikethrough(self):
+        text = '~~mistake~~'
+        assert_equal(self.conv.convert(text), '<s>mistake</s>')
+
+    def test_convert_code_blocks(self):
+        text = u'''```python
+print "Hello!"
+```'''
+        result = u'~~~~\nprint "Hello!"\n~~~~'
+        assert_equal(self.conv.convert(text).strip(), result)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ba536053/ForgeImporters/forgeimporters/github/utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/utils.py b/ForgeImporters/forgeimporters/github/utils.py
index ab66157..282e312 100644
--- a/ForgeImporters/forgeimporters/github/utils.py
+++ b/ForgeImporters/forgeimporters/github/utils.py
@@ -3,45 +3,44 @@ import re
 
 class GitHubMarkdownConverter(object):
 
-    @classmethod
-    def convert(cls, text):
-        _re = re.compile('\S*(#\d+)')
-        text = _re.sub(cls._convert_ticket, text)
+    def __init__(self, gh_user, gh_project, project, mount_point):
+        self.gh_project = '%s/%s' % (gh_project, gh_user)
+        self.project = '%s:%s' % (project, mount_point)
 
-        _re = re.compile('\S*/\S*@(\w{40})')
-        text = _re.sub(cls._convert_user_repo_sha, text)
+    def convert(self, text):
+        _re = re.compile('\S+\s+(#\d+)')
+        text = _re.sub(self._convert_ticket, text)
 
-        _re = re.compile('\s\S*@(\w{40})')
-        text = _re.sub(cls._convert_user_sha, text)
+        _re = re.compile('\S*/\S*@([0-9a-f]{40})')
+        text = _re.sub(self._convert_user_repo_sha, text)
+
+        _re = re.compile('\s\S*@([0-9a-f]{40})')
+        text = _re.sub(self._convert_user_sha, text)
+
+        _re = re.compile('(\s|^)([0-9a-f]{40})(\s|$)')
+        text = _re.sub(self._convert_sha, text)
 
-        _re = re.compile(': (\w{40})')
-        text = _re.sub(cls._convert_sha, text)
         _re = re.compile('~~(.*)~~',)
-        text = _re.sub(cls._convert_strikethrough, text)
+        text = _re.sub(self._convert_strikethrough, text)
+
         _re = re.compile(r'```\w*(.*)```', re.DOTALL)
-        text = _re.sub(cls._convert_codeblock, text)
+        text = _re.sub(self._convert_codeblock, text)
         return text
 
-    @classmethod
-    def _convert_sha(cls, match):
-        return ': [%s]' % match.group(1)[:6]
+    def _convert_sha(self, match):
+        return '%s[%s]%s' % (match.group(1), match.group(2)[:6], match.group(3))
 
-    @classmethod
-    def _convert_ticket(cls, match):
+    def _convert_ticket(self, match):
         return '[%s]' % match.group(1)
 
-    @classmethod
-    def _convert_user_sha(cls, match):
+    def _convert_user_sha(self, match):
         return '[%s]' % (match.group(1)[:6])
 
-    @classmethod
-    def _convert_user_repo_sha(cls, match):
+    def _convert_user_repo_sha(self, match):
         return '[%s]' % (match.group(1)[:6])
 
-    @classmethod
-    def _convert_strikethrough(cls, match):
+    def _convert_strikethrough(self, match):
         return '<s>%s</s>' % match.group(1)
 
-    @classmethod
-    def _convert_codeblock(cls, match):
+    def _convert_codeblock(self, match):
         return '~~~~%s~~~~'% match.group(1)


[20/21] git commit: [#6622] ticket:469 fixed regex'es and tests

Posted by br...@apache.org.
[#6622] ticket:469 fixed regex'es and tests


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

Branch: refs/heads/master
Commit: ad1f2c335f1a51ced3250af4a39cbd97eaf9e4b3
Parents: bf301e0
Author: coldmind <so...@yandex.ru>
Authored: Thu Nov 7 13:08:11 2013 +0200
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Nov 13 17:16:57 2013 +0000

----------------------------------------------------------------------
 .../forgeimporters/github/tests/test_utils.py   | 23 +++++++-----
 .../forgeimporters/github/tests/test_wiki.py    | 11 ++++--
 ForgeImporters/forgeimporters/github/utils.py   | 37 +++++++-------------
 .../forgeimporters/tests/github/test_tracker.py | 25 ++++++++-----
 4 files changed, 53 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ad1f2c33/ForgeImporters/forgeimporters/github/tests/test_utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tests/test_utils.py b/ForgeImporters/forgeimporters/github/tests/test_utils.py
index d60cb0d..cc02e6b 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_utils.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_utils.py
@@ -85,15 +85,22 @@ for (var i = 0; i < a.length; i++) {
     console.log(i);
 }
 ```'''
-        result = u'''~~~~
-print "Hello!"
-~~~~
+        result = u'''<br>
+
+    :::python
+    print "Hello!"
+
+<br>
+
 
 Two code blocks here!
 
-~~~~
-for (var i = 0; i < a.length; i++) {
-    console.log(i);
-}
-~~~~'''
+
+<br>
+
+    for (var i = 0; i < a.length; i++) {
+        console.log(i);
+    }
+
+<br>'''
         assert_equal(self.conv.convert(text).strip(), result)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ad1f2c33/ForgeImporters/forgeimporters/github/tests/test_wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tests/test_wiki.py b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
index 818f8ee..ee37c38 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_wiki.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
@@ -318,9 +318,14 @@ Our website is <http://sf.net>.
 
 [[Escaped Tag]]
 
-~~~~
-codeblock
-~~~~
+
+<br>
+
+    :::python
+    codeblock
+
+<br>
+
 
 ticket [#1]
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ad1f2c33/ForgeImporters/forgeimporters/github/utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/utils.py b/ForgeImporters/forgeimporters/github/utils.py
index 17e28ac..5d64666 100644
--- a/ForgeImporters/forgeimporters/github/utils.py
+++ b/ForgeImporters/forgeimporters/github/utils.py
@@ -6,7 +6,7 @@ class GitHubMarkdownConverter(object):
     def __init__(self, gh_user, gh_project):
         self.gh_project = '%s/%s' % (gh_user, gh_project)
         self.gh_base_url = u'https://github.com/'
-        self.code_patterns = ['```']
+        self.code_patterns = ['```', '~~~~~']
 
     def convert(self, text):
         lines = self._parse_lines(text.split('\n'))
@@ -19,11 +19,15 @@ class GitHubMarkdownConverter(object):
             nextline = False
             for p in self.code_patterns:
                 if line.lstrip().startswith(p):
-                    _re = re.compile(r'\```(.*)')
-                    syntax = _re.findall(line)[0]
-                    if syntax and not syntax.isspace():
-                        new_lines.append(self._codeblock_syntax(syntax))
-
+                    # this is extreme, but due to display bugs
+                    # it's necessary
+                    new_lines.append('\n<br>\n')
+
+                    if p == '```':
+                        _re = re.compile(r'\```(.*)')
+                        syntax = _re.findall(line)[0]
+                        if syntax and not syntax.isspace():
+                            new_lines.append(self._codeblock_syntax(syntax))
                     in_block = not in_block
                     nextline = True
                     break
@@ -33,14 +37,9 @@ class GitHubMarkdownConverter(object):
             if in_block:
                 new_lines.append(self._handle_code(line))
             else:
-                _re = re.compile(r'`\s*(.*?)`')
-                is_inline_code = _re.findall(line)
-
                 if line.lstrip().startswith('    '):
                     # code block due to github syntax
                     continue
-                elif is_inline_code and not is_inline_code[0].isspace():
-                    new_lines.append(self._handle_inline_code(line))
                 else:
                     new_lines.append(self._handle_non_code(line))
         return new_lines
@@ -53,16 +52,6 @@ class GitHubMarkdownConverter(object):
         text = '    ' + text
         return text
 
-    def _handle_inline_code(self, text):
-        """Return a string that will replace ``text`` in the final text
-        output. ``text`` is inline code.
-
-        """
-        _re = re.compile(r'`(\s*)(.*?)`')
-        text = _re.sub(self._convert_inline_codeblock, text)
-
-        return text
-
     def _handle_non_code(self, text):
         """Return a string that will replace ``text`` in the final text
         output. ``text`` is *not* code.
@@ -83,10 +72,10 @@ class GitHubMarkdownConverter(object):
         _re = re.compile(r'(\b)(\S+)@([0-9a-f]{40})(\b)')
         text = _re.sub(self._convert_user_sha, text)
 
-        _re = re.compile(r'(\b)([0-9a-f]{40})(\b)')
+        _re = re.compile(r'(\s|^)([0-9a-f]{40})(\s|$)')
         text = _re.sub(self._convert_sha, text)
 
-        _re = re.compile(r'~~(.*)~~',)
+        _re = re.compile(r'~~(.*?)~~',)
         text = _re.sub(self._convert_strikethrough, text)
 
         return text
@@ -141,7 +130,7 @@ class GitHubMarkdownConverter(object):
         return '<s>%s</s>' % m.group(1)
 
     def _codeblock_syntax(self, text):
-        return '\n    :::%s' % text
+        return '    :::%s' % text
 
     def _convert_inline_codeblock(self, m):
         text = m.group(0)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ad1f2c33/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 bac2a1a..e305943 100644
--- a/ForgeImporters/forgeimporters/tests/github/test_tracker.py
+++ b/ForgeImporters/forgeimporters/tests/github/test_tracker.py
@@ -195,10 +195,14 @@ def hello(name):
 
 Hello
 
-~~~~
-def hello(name):
-    print "Hello, " + name
-~~~~'''
+
+<br>
+
+    :::python
+    def hello(name):
+        print "Hello, " + name
+
+<br>'''
         issue = {
             'body': body,
             'title': 'title',
@@ -229,10 +233,15 @@ def hello(name):
 
 Hello
 
-~~~~
-def hello(name):
-    print "Hello, " + name
-~~~~'''
+
+<br>
+
+    :::python
+    def hello(name):
+        print "Hello, " + name
+
+<br>
+'''
         issue = {'comments_url': '/comments'}
         extractor.iter_comments.return_value = [
                 {


[17/21] git commit: [#6622] ticket:469 improved regex

Posted by br...@apache.org.
[#6622] ticket:469 improved regex


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

Branch: refs/heads/master
Commit: bf301e006358e0a4d65d720caee8b8f20b097d5f
Parents: 43f1692
Author: coldmind <so...@yandex.ru>
Authored: Wed Nov 6 20:19:06 2013 +0200
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Nov 13 17:16:57 2013 +0000

----------------------------------------------------------------------
 ForgeImporters/forgeimporters/github/utils.py | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/bf301e00/ForgeImporters/forgeimporters/github/utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/utils.py b/ForgeImporters/forgeimporters/github/utils.py
index 292b41e..17e28ac 100644
--- a/ForgeImporters/forgeimporters/github/utils.py
+++ b/ForgeImporters/forgeimporters/github/utils.py
@@ -68,22 +68,22 @@ class GitHubMarkdownConverter(object):
         output. ``text`` is *not* code.
 
         """
-        _re = re.compile(r'(\s|^)(\S+)/(\S+)#(\d+)(\s|$)')
+        _re = re.compile(r'(\b)(\S+)/(\S+)#(\d+)(\b)')
         text = _re.sub(self._convert_user_repo_ticket, text)
 
-        _re = re.compile(r'(\s|^)(\S+)#(\d+)(\s|$)')
+        _re = re.compile(r'(\b)(\S+)#(\d+)(\b)')
         text = _re.sub(self._convert_user_ticket, text)
 
         _re = re.compile(r'(\S+\s+)(#\d+)')
         text = _re.sub(self._convert_ticket, text)
 
-        _re = re.compile(r'(\s|^)(\S+)/(\S+)@([0-9a-f]{40})(\s|$)')
+        _re = re.compile(r'(\b)(\S+)/(\S+)@([0-9a-f]{40})(\b)')
         text = _re.sub(self._convert_user_repo_sha, text)
 
-        _re = re.compile(r'(\s|^)(\S+)@([0-9a-f]{40})(\s|$)')
+        _re = re.compile(r'(\b)(\S+)@([0-9a-f]{40})(\b)')
         text = _re.sub(self._convert_user_sha, text)
 
-        _re = re.compile(r'(\s|^)([0-9a-f]{40})(\s|$)')
+        _re = re.compile(r'(\b)([0-9a-f]{40})(\b)')
         text = _re.sub(self._convert_sha, text)
 
         _re = re.compile(r'~~(.*)~~',)


[04/21] git commit: [#6622] ticket:435 Fix user/repo@sha regex

Posted by br...@apache.org.
[#6622] ticket:435 Fix user/repo@sha regex


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

Branch: refs/heads/master
Commit: 3c12029ef3e3007ee37db06633d3d1ffc5a78164
Parents: 9e9b826
Author: Igor Bondarenko <je...@gmail.com>
Authored: Mon Oct 14 15:43:10 2013 +0300
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Nov 13 17:16:55 2013 +0000

----------------------------------------------------------------------
 .../forgeimporters/github/tests/test_utils.py   |  9 ++--
 ForgeImporters/forgeimporters/github/utils.py   | 48 ++++++++++++--------
 2 files changed, 34 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3c12029e/ForgeImporters/forgeimporters/github/tests/test_utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tests/test_utils.py b/ForgeImporters/forgeimporters/github/tests/test_utils.py
index 0b86623..a0dfbcc 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_utils.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_utils.py
@@ -30,13 +30,13 @@ class TestGitHubMarkdownConverter(object):
     def test_convert_user_repo_sha(self):
         text = 'user/project@16c999e8c71134401a78d4d46435517b2271d6ac'
         result = self.conv.convert(text)
-        assert_equal(result, '[p:mount:16c999e8c71134401a78d4d46435517b2271d6ac]')
+        assert_equal(result, '[p:mount:16c999]')
 
         # Not a current project
         text = 'user/p@16c999e8c71134401a78d4d46435517b2271d6ac'
         result = self.conv.convert(text)
-        assert_equal(result, '[user/project@16c999e8c71134401a78d4d46435517b2271d6ac]'
-                             '(https://github.com/u/p/commit/16c999e8c71134401a78d4d46435517b2271d6ac)')
+        assert_equal(result, '[user/p@16c999]'
+                             '(https://github.com/user/p/commit/16c999e8c71134401a78d4d46435517b2271d6ac)')
 
     def test_convert_ticket(self):
         text = 'Ticket #1'
@@ -67,8 +67,7 @@ class TestGitHubMarkdownConverter(object):
         # Not a current project
         text = 'user/p#1'
         result = self.conv.convert(text)
-        assert_equal(result, '[user/project@16c999e8c71134401a78d4d46435517b2271d6ac]'
-                             '(https://github.com/u/p/issues/1)')
+        assert_equal(result, '[user/p#1](https://github.com/u/p/issues/1)')
 
     def test_convert_strikethrough(self):
         text = '~~mistake~~'

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3c12029e/ForgeImporters/forgeimporters/github/utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/utils.py b/ForgeImporters/forgeimporters/github/utils.py
index f74f8eb..6d22266 100644
--- a/ForgeImporters/forgeimporters/github/utils.py
+++ b/ForgeImporters/forgeimporters/github/utils.py
@@ -4,43 +4,55 @@ import re
 class GitHubMarkdownConverter(object):
 
     def __init__(self, gh_user, gh_project, project, mount_point):
-        self.gh_project = '%s/%s' % (gh_project, gh_user)
+        self.gh_project = '%s/%s' % (gh_user, gh_project)
         self.project = '%s:%s' % (project, mount_point)
+        self.gh_base_url = u'https://github.com/'
 
     def convert(self, text):
-        _re = re.compile('(\S+\s+)(#\d+)')
+        _re = re.compile(r'(\S+\s+)(#\d+)')
         text = _re.sub(self._convert_ticket, text)
 
-        _re = re.compile('\S*/\S*@([0-9a-f]{40})')
+        _re = re.compile(r'(\s|^)(.+)/(.+)@([0-9a-f]{40})(\s|$)')
         text = _re.sub(self._convert_user_repo_sha, text)
 
-        _re = re.compile('\s\S*@([0-9a-f]{40})')
+        _re = re.compile(r'\s\S*@([0-9a-f]{40})')
         text = _re.sub(self._convert_user_sha, text)
 
-        _re = re.compile('(\s|^)([0-9a-f]{40})(\s|$)')
+        _re = re.compile(r'(\s|^)([0-9a-f]{40})(\s|$)')
         text = _re.sub(self._convert_sha, text)
 
-        _re = re.compile('~~(.*)~~',)
+        _re = re.compile(r'~~(.*)~~',)
         text = _re.sub(self._convert_strikethrough, text)
 
         _re = re.compile(r'```\w*(.*)```', re.DOTALL)
         text = _re.sub(self._convert_codeblock, text)
         return text
 
-    def _convert_sha(self, match):
-        return '%s[%s]%s' % (match.group(1), match.group(2)[:6], match.group(3))
+    def _gh_commit_url(self, project, sha, title):
+        return u'[%s](%s)' % (title, self.gh_base_url + project + '/commit/' + sha)
 
-    def _convert_ticket(self, match):
-        return '%s[%s]' % match.groups()
+    def _convert_sha(self, m):
+        return '%s[%s]%s' % (m.group(1), m.group(2)[:6], m.group(3))
 
-    def _convert_user_sha(self, match):
-        return '[%s]' % (match.group(1)[:6])
+    def _convert_ticket(self, m):
+        return '%s[%s]' % m.groups()
 
-    def _convert_user_repo_sha(self, match):
-        return '[%s]' % (match.group(1)[:6])
+    def _convert_user_sha(self, m):
+        return '[%s]' % (m.group(1)[:6])
 
-    def _convert_strikethrough(self, match):
-        return '<s>%s</s>' % match.group(1)
+    def _convert_user_repo_sha(self, m):
+        project = '%s/%s' % (m.group(2), m.group(3))
+        sha = m.group(4)
+        if project == self.gh_project:
+            link = ':'.join([self.project, sha[:6]])
+            return '%s[%s]%s' % (m.group(1), link, m.group(5))
+        title = project + '@' + sha[:6]
+        return ''.join([m.group(1),
+                        self._gh_commit_url(project, sha, title),
+                        m.group(5)])
 
-    def _convert_codeblock(self, match):
-        return '~~~~%s~~~~'% match.group(1)
+    def _convert_strikethrough(self, m):
+        return '<s>%s</s>' % m.group(1)
+
+    def _convert_codeblock(self, m):
+        return '~~~~%s~~~~'% m.group(1)


[15/21] git commit: [#6622] ticket:469 use new converter now

Posted by br...@apache.org.
[#6622] ticket:469 use new converter now


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

Branch: refs/heads/master
Commit: f9db5f9d4d625cea535d4f1bdc4fcd96066cdb44
Parents: 4b7b2b0
Author: coldmind <so...@yandex.ru>
Authored: Wed Nov 6 18:29:50 2013 +0200
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Nov 13 17:16:56 2013 +0000

----------------------------------------------------------------------
 ForgeImporters/forgeimporters/github/utils.py | 50 ++++++++++++++++++++--
 1 file changed, 46 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f9db5f9d/ForgeImporters/forgeimporters/github/utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/utils.py b/ForgeImporters/forgeimporters/github/utils.py
index 63a55e4..03dfe1b 100644
--- a/ForgeImporters/forgeimporters/github/utils.py
+++ b/ForgeImporters/forgeimporters/github/utils.py
@@ -6,8 +6,52 @@ class GitHubMarkdownConverter(object):
     def __init__(self, gh_user, gh_project):
         self.gh_project = '%s/%s' % (gh_user, gh_project)
         self.gh_base_url = u'https://github.com/'
+        self.code_patterns = ['```']
 
     def convert(self, text):
+        lines = self._parse_lines(text.split('\n'))
+        return '\n'.join(lines)
+
+    def _parse_lines(self, lines):
+        in_block = False
+        new_lines = []
+        for line in lines:
+            nextline = False
+            for p in self.code_patterns:
+                if line.lstrip().startswith(p):
+                    _re = re.compile(r'\```(.*)')
+                    syntax = _re.findall(line)[0]
+                    if syntax and not syntax.isspace():
+                        new_lines.append(self._codeblock_syntax(syntax))
+
+                    in_block = not in_block
+                    nextline = True
+                    break
+            if nextline:
+                continue
+
+            if in_block:
+                new_lines.append(self._handle_code(line))
+            else:
+                if line.lstrip().startswith('    '):
+                    new_lines.append(self._handle_code(line))
+                else:
+                    new_lines.append(self._handle_non_code(line))
+        return new_lines
+
+    def _handle_code(self, text):
+        """Return a string that will replace ``text`` in the final text
+        output. ``text`` is code.
+
+        """
+        text = '    ' + text
+        return text
+
+    def _handle_non_code(self, text):
+        """Return a string that will replace ``text`` in the final text
+        output. ``text`` is *not* code.
+
+        """
         _re = re.compile(r'(\s|^)(\S+)/(\S+)#(\d+)(\s|$)')
         text = _re.sub(self._convert_user_repo_ticket, text)
 
@@ -29,8 +73,6 @@ class GitHubMarkdownConverter(object):
         _re = re.compile(r'~~(.*)~~',)
         text = _re.sub(self._convert_strikethrough, text)
 
-        _re = re.compile(r'```\w*(.*?)```', re.DOTALL)
-        text = _re.sub(self._convert_codeblock, text)
         return text
 
     def _gh_commit_url(self, project, sha, title):
@@ -82,5 +124,5 @@ class GitHubMarkdownConverter(object):
     def _convert_strikethrough(self, m):
         return '<s>%s</s>' % m.group(1)
 
-    def _convert_codeblock(self, m):
-        return '~~~~%s~~~~'% m.group(1)
+    def _codeblock_syntax(self, text):
+        return '\n    :::%s' % text
\ No newline at end of file


[21/21] git commit: [#6622] ticket:494 Fix test failing due to new ticket regex

Posted by br...@apache.org.
[#6622] ticket:494 Fix test failing due to new ticket regex


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

Branch: refs/heads/master
Commit: 9efb68969c6c12f558868529742af8595f064894
Parents: 05de134
Author: Igor Bondarenko <je...@gmail.com>
Authored: Wed Nov 13 11:33:57 2013 +0200
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Nov 13 17:16:57 2013 +0000

----------------------------------------------------------------------
 ForgeImporters/forgeimporters/github/tests/test_wiki.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/9efb6896/ForgeImporters/forgeimporters/github/tests/test_wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tests/test_wiki.py b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
index e0c83bb..b9b18bd 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_wiki.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
@@ -324,7 +324,7 @@ Our website is <http://sf.net>.
 
 ticket [#1]
 
-#1 header
+[#1] header
 
 sha [aaaaaa]'''
         assert_equal(f(source, 'test.md').strip(), result)


[13/21] git commit: [#6622] ticket:435 convert user/project references into shortlinks

Posted by br...@apache.org.
[#6622] ticket:435 convert user/project references into shortlinks

Because we don't know the proper mount point.


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

Branch: refs/heads/master
Commit: d2d337b0f74c9ace05f1c9dbbda2e2de52152f41
Parents: 3cda147
Author: Igor Bondarenko <je...@gmail.com>
Authored: Mon Oct 14 17:20:59 2013 +0300
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Nov 13 17:16:56 2013 +0000

----------------------------------------------------------------------
 ForgeImporters/forgeimporters/github/tests/test_utils.py   | 6 +++---
 ForgeImporters/forgeimporters/github/tests/test_wiki.py    | 2 +-
 ForgeImporters/forgeimporters/github/tracker.py            | 6 +-----
 ForgeImporters/forgeimporters/github/utils.py              | 9 +++------
 ForgeImporters/forgeimporters/github/wiki.py               | 6 +-----
 ForgeImporters/forgeimporters/tests/github/test_tracker.py | 8 ++++----
 6 files changed, 13 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d2d337b0/ForgeImporters/forgeimporters/github/tests/test_utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tests/test_utils.py b/ForgeImporters/forgeimporters/github/tests/test_utils.py
index e3ba75c..d60cb0d 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_utils.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_utils.py
@@ -6,7 +6,7 @@ from forgeimporters.github.utils import GitHubMarkdownConverter
 class TestGitHubMarkdownConverter(object):
 
     def setUp(self):
-        self.conv = GitHubMarkdownConverter('user', 'project', 'p', 'mount')
+        self.conv = GitHubMarkdownConverter('user', 'project')
 
     def test_convert_sha(self):
         text = '16c999e8c71134401a78d4d46435517b2271d6ac'
@@ -30,7 +30,7 @@ class TestGitHubMarkdownConverter(object):
     def test_convert_user_repo_sha(self):
         text = 'user/project@16c999e8c71134401a78d4d46435517b2271d6ac'
         result = self.conv.convert(text)
-        assert_equal(result, '[p:mount:16c999]')
+        assert_equal(result, '[16c999]')
 
         # Not a current project
         text = 'user/p@16c999e8c71134401a78d4d46435517b2271d6ac'
@@ -62,7 +62,7 @@ class TestGitHubMarkdownConverter(object):
     def test_convert_user_repo_ticket(self):
         text = 'user/project#1'
         result = self.conv.convert(text)
-        assert_equal(result, '[p:mount:#1]')
+        assert_equal(result, '[#1]')
 
         # Not a current project
         text = 'user/p#1'

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d2d337b0/ForgeImporters/forgeimporters/github/tests/test_wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tests/test_wiki.py b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
index ea54b10..818f8ee 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_wiki.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
@@ -291,7 +291,7 @@ Our website is <http://sf.net>.
         importer.github_wiki_url = 'https://github.com/a/b/wiki'
         importer.app = Mock()
         importer.app.url = '/p/test/wiki/'
-        importer.github_markdown_converter = GitHubMarkdownConverter('user', 'proj', 'p', 'mount')
+        importer.github_markdown_converter = GitHubMarkdownConverter('user', 'proj')
         f = importer.convert_markup
         source = u'''Look at [[this page|Some Page]]
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d2d337b0/ForgeImporters/forgeimporters/github/tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tracker.py b/ForgeImporters/forgeimporters/github/tracker.py
index 6dfa507..c2141ce 100644
--- a/ForgeImporters/forgeimporters/github/tracker.py
+++ b/ForgeImporters/forgeimporters/github/tracker.py
@@ -112,11 +112,7 @@ class GitHubTrackerImporter(ToolImporter):
                 }
             )
         self.github_markdown_converter = GitHubMarkdownConverter(
-            kw['user_name'],
-            project_name,
-            project.shortname,
-            app.config.options.mount_point,
-        )
+            kw['user_name'], project_name)
         ThreadLocalORMSession.flush_all()
         extractor = GitHubProjectExtractor(project_name)
         try:

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d2d337b0/ForgeImporters/forgeimporters/github/utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/utils.py b/ForgeImporters/forgeimporters/github/utils.py
index f00140d..63a55e4 100644
--- a/ForgeImporters/forgeimporters/github/utils.py
+++ b/ForgeImporters/forgeimporters/github/utils.py
@@ -3,9 +3,8 @@ import re
 
 class GitHubMarkdownConverter(object):
 
-    def __init__(self, gh_user, gh_project, project, mount_point):
+    def __init__(self, gh_user, gh_project):
         self.gh_project = '%s/%s' % (gh_user, gh_project)
-        self.project = '%s:%s' % (project, mount_point)
         self.gh_base_url = u'https://github.com/'
 
     def convert(self, text):
@@ -57,8 +56,7 @@ class GitHubMarkdownConverter(object):
         project = '%s/%s' % (m.group(2), m.group(3))
         tid = m.group(4)
         if project == self.gh_project:
-            link = ':'.join([self.project, '#' + tid])
-            return '%s[%s]%s' % (m.group(1), link, m.group(5))
+            return '%s[%s]%s' % (m.group(1), '#' + tid, m.group(5))
         title = project + '#' + tid
         return ''.join([m.group(1),
                         self._gh_ticket_url(project, tid, title),
@@ -75,8 +73,7 @@ class GitHubMarkdownConverter(object):
         project = '%s/%s' % (m.group(2), m.group(3))
         sha = m.group(4)
         if project == self.gh_project:
-            link = ':'.join([self.project, sha[:6]])
-            return '%s[%s]%s' % (m.group(1), link, m.group(5))
+            return '%s[%s]%s' % (m.group(1), sha[:6], m.group(5))
         title = project + '@' + sha[:6]
         return ''.join([m.group(1),
                         self._gh_commit_url(project, sha, title),

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d2d337b0/ForgeImporters/forgeimporters/github/wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/wiki.py b/ForgeImporters/forgeimporters/github/wiki.py
index 1290224..8fae1b1 100644
--- a/ForgeImporters/forgeimporters/github/wiki.py
+++ b/ForgeImporters/forgeimporters/github/wiki.py
@@ -156,11 +156,7 @@ class GitHubWikiImporter(ToolImporter):
         with_history = tool_option == 'import_history'
         ThreadLocalORMSession.flush_all()
         self.github_markdown_converter = GitHubMarkdownConverter(
-            user_name,
-            project_name,
-            project.shortname,
-            self.app.config.options.mount_point,
-        )
+            user_name, project_name)
         try:
             M.session.artifact_orm_session._get().skip_mod_date = True
             with h.push_config(c, app=self.app):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d2d337b0/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 6b8c736..43a3bb6 100644
--- a/ForgeImporters/forgeimporters/tests/github/test_tracker.py
+++ b/ForgeImporters/forgeimporters/tests/github/test_tracker.py
@@ -79,7 +79,7 @@ class TestTrackerImporter(TestCase):
             'labels': [{'name': 'first'}, {'name': 'second'}],
         }
         importer = tracker.GitHubTrackerImporter()
-        importer.github_markdown_converter = GitHubMarkdownConverter('user', 'project', 'p', 'mount')
+        importer.github_markdown_converter = GitHubMarkdownConverter('user', 'project')
         with mock.patch.object(tracker, 'datetime') as dt:
             dt.strptime.side_effect = lambda s,f: s
             importer.process_fields(ticket, issue)
@@ -135,7 +135,7 @@ class TestTrackerImporter(TestCase):
                 }
             ]
         importer = tracker.GitHubTrackerImporter()
-        importer.github_markdown_converter = GitHubMarkdownConverter('user', 'project', 'p', 'mount')
+        importer.github_markdown_converter = GitHubMarkdownConverter('user', 'project')
         importer.process_comments(extractor, ticket, issue)
         self.assertEqual(ticket.discussion_thread.add_post.call_args_list[0], mock.call(
                 text='*Originally posted by:* [me](https://github.com/me)\nhello',
@@ -210,7 +210,7 @@ def hello(name):
             'labels': [{'name': 'first'}, {'name': 'second'}],
         }
         importer = tracker.GitHubTrackerImporter()
-        importer.github_markdown_converter = GitHubMarkdownConverter('user', 'project', 'p', 'mount')
+        importer.github_markdown_converter = GitHubMarkdownConverter('user', 'project')
         with mock.patch.object(tracker, 'datetime') as dt:
             dt.strptime.side_effect = lambda s,f: s
             importer.process_fields(ticket, issue)
@@ -241,7 +241,7 @@ def hello(name):
                 }
             ]
         importer = tracker.GitHubTrackerImporter()
-        importer.github_markdown_converter = GitHubMarkdownConverter('user', 'project', 'p', 'mount')
+        importer.github_markdown_converter = GitHubMarkdownConverter('user', 'project')
         importer.process_comments(extractor, ticket, issue)
         self.assertEqual(ticket.discussion_thread.add_post.call_args_list[0], mock.call(
                 text=body_converted,


[19/21] git commit: [#6622] ticket:469 not handling inline blocks, fixed parser

Posted by br...@apache.org.
[#6622] ticket:469 not handling inline blocks, fixed parser


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

Branch: refs/heads/master
Commit: 11e262165802abb0506ceb85750d88a120384f7a
Parents: ad1f2c3
Author: coldmind <so...@yandex.ru>
Authored: Fri Nov 8 13:49:11 2013 +0200
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Nov 13 17:16:57 2013 +0000

----------------------------------------------------------------------
 .../forgeimporters/github/tests/test_utils.py   | 13 ++------
 .../forgeimporters/github/tests/test_wiki.py    |  5 ---
 ForgeImporters/forgeimporters/github/utils.py   | 32 +++++++++++---------
 .../forgeimporters/tests/github/test_tracker.py | 11 ++-----
 4 files changed, 22 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/11e26216/ForgeImporters/forgeimporters/github/tests/test_utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tests/test_utils.py b/ForgeImporters/forgeimporters/github/tests/test_utils.py
index cc02e6b..f426d6b 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_utils.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_utils.py
@@ -85,22 +85,13 @@ for (var i = 0; i < a.length; i++) {
     console.log(i);
 }
 ```'''
-        result = u'''<br>
-
-    :::python
+        result = u''':::python
     print "Hello!"
 
-<br>
-
-
 Two code blocks here!
 
-
-<br>
-
     for (var i = 0; i < a.length; i++) {
         console.log(i);
-    }
+    }'''
 
-<br>'''
         assert_equal(self.conv.convert(text).strip(), result)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/11e26216/ForgeImporters/forgeimporters/github/tests/test_wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tests/test_wiki.py b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
index ee37c38..e0c83bb 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_wiki.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
@@ -319,14 +319,9 @@ Our website is <http://sf.net>.
 [[Escaped Tag]]
 
 
-<br>
-
     :::python
     codeblock
 
-<br>
-
-
 ticket [#1]
 
 #1 header

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/11e26216/ForgeImporters/forgeimporters/github/utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/utils.py b/ForgeImporters/forgeimporters/github/utils.py
index 5d64666..d509aa7 100644
--- a/ForgeImporters/forgeimporters/github/utils.py
+++ b/ForgeImporters/forgeimporters/github/utils.py
@@ -19,14 +19,9 @@ class GitHubMarkdownConverter(object):
             nextline = False
             for p in self.code_patterns:
                 if line.lstrip().startswith(p):
-                    # this is extreme, but due to display bugs
-                    # it's necessary
-                    new_lines.append('\n<br>\n')
-
                     if p == '```':
-                        _re = re.compile(r'\```(.*)')
-                        syntax = _re.findall(line)[0]
-                        if syntax and not syntax.isspace():
+                        syntax = line.lstrip().lstrip('`').strip()
+                        if syntax:
                             new_lines.append(self._codeblock_syntax(syntax))
                     in_block = not in_block
                     nextline = True
@@ -37,9 +32,22 @@ class GitHubMarkdownConverter(object):
             if in_block:
                 new_lines.append(self._handle_code(line))
             else:
-                if line.lstrip().startswith('    '):
+                _re = re.compile(r'`\s*(.*?)`')
+                inline_matches = _re.findall(line)
+
+                if line.startswith('    '):
                     # code block due to github syntax
-                    continue
+                    new_lines.append(line)
+                elif inline_matches and not inline_matches[0].isspace():
+                    # need to not handle inline blocks as a text
+                    for i, m in enumerate(inline_matches):
+                        line = line.replace('`%s`' % m, '<inline_block>%s</inline_block>' % i)
+
+                    line = self._handle_non_code(line)
+                    for i, m in enumerate(inline_matches):
+                        line = line.replace('<inline_block>%s</inline_block>' % i, inline_matches[i])
+
+                    new_lines.append(line)
                 else:
                     new_lines.append(self._handle_non_code(line))
         return new_lines
@@ -130,8 +138,4 @@ class GitHubMarkdownConverter(object):
         return '<s>%s</s>' % m.group(1)
 
     def _codeblock_syntax(self, text):
-        return '    :::%s' % text
-
-    def _convert_inline_codeblock(self, m):
-        text = m.group(0)
-        return '**%s**' % text
+        return '\n    :::%s' % text

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/11e26216/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 e305943..e991382 100644
--- a/ForgeImporters/forgeimporters/tests/github/test_tracker.py
+++ b/ForgeImporters/forgeimporters/tests/github/test_tracker.py
@@ -196,13 +196,10 @@ def hello(name):
 Hello
 
 
-<br>
-
     :::python
     def hello(name):
-        print "Hello, " + name
+        print "Hello, " + name'''
 
-<br>'''
         issue = {
             'body': body,
             'title': 'title',
@@ -234,14 +231,10 @@ def hello(name):
 Hello
 
 
-<br>
-
     :::python
     def hello(name):
-        print "Hello, " + name
+        print "Hello, " + name'''
 
-<br>
-'''
         issue = {'comments_url': '/comments'}
         extractor.iter_comments.return_value = [
                 {


[03/21] git commit: [#6622] ticket:435 Fix ticket regexs

Posted by br...@apache.org.
[#6622] ticket:435 Fix ticket regexs


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

Branch: refs/heads/master
Commit: d7ee19139de1670d7295ddfc0a4bb96ec63a3927
Parents: f0e6117
Author: Igor Bondarenko <je...@gmail.com>
Authored: Mon Oct 14 16:29:07 2013 +0300
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Nov 13 17:16:55 2013 +0000

----------------------------------------------------------------------
 .../forgeimporters/github/tests/test_utils.py   |  6 ++--
 ForgeImporters/forgeimporters/github/utils.py   | 31 ++++++++++++++++++--
 2 files changed, 32 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d7ee1913/ForgeImporters/forgeimporters/github/tests/test_utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tests/test_utils.py b/ForgeImporters/forgeimporters/github/tests/test_utils.py
index a0dfbcc..3ce8d29 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_utils.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_utils.py
@@ -49,7 +49,7 @@ class TestGitHubMarkdownConverter(object):
         text = '  #1'
         assert_equal(self.conv.convert(text), '  #1')
 
-    def test_convert_username_ticket(self):
+    def test_convert_user_ticket(self):
         text = 'user#1'
         result = self.conv.convert(text)
         assert_equal(result, '[#1]')
@@ -59,7 +59,7 @@ class TestGitHubMarkdownConverter(object):
         result = self.conv.convert(text)
         assert_equal(result, 'another-user#1')
 
-    def test_convert_username_repo_ticket(self):
+    def test_convert_user_repo_ticket(self):
         text = 'user/project#1'
         result = self.conv.convert(text)
         assert_equal(result, '[p:mount:#1]')
@@ -67,7 +67,7 @@ class TestGitHubMarkdownConverter(object):
         # Not a current project
         text = 'user/p#1'
         result = self.conv.convert(text)
-        assert_equal(result, '[user/p#1](https://github.com/u/p/issues/1)')
+        assert_equal(result, '[user/p#1](https://github.com/user/p/issues/1)')
 
     def test_convert_strikethrough(self):
         text = '~~mistake~~'

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d7ee1913/ForgeImporters/forgeimporters/github/utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/utils.py b/ForgeImporters/forgeimporters/github/utils.py
index defe391..da50c2d 100644
--- a/ForgeImporters/forgeimporters/github/utils.py
+++ b/ForgeImporters/forgeimporters/github/utils.py
@@ -9,13 +9,19 @@ class GitHubMarkdownConverter(object):
         self.gh_base_url = u'https://github.com/'
 
     def convert(self, text):
+        _re = re.compile(r'(\s|^)(\S+)/(\S+)#(\d+)(\s|$)')
+        text = _re.sub(self._convert_user_repo_ticket, text)
+
+        _re = re.compile(r'(\s|^)(\S+)#(\d+)(\s|$)')
+        text = _re.sub(self._convert_user_ticket, text)
+
         _re = re.compile(r'(\S+\s+)(#\d+)')
         text = _re.sub(self._convert_ticket, text)
 
-        _re = re.compile(r'(\s|^)(.+)/(.+)@([0-9a-f]{40})(\s|$)')
+        _re = re.compile(r'(\s|^)(\S+)/(\S+)@([0-9a-f]{40})(\s|$)')
         text = _re.sub(self._convert_user_repo_sha, text)
 
-        _re = re.compile(r'(\s|^)(.+)@([0-9a-f]{40})(\s|$)')
+        _re = re.compile(r'(\s|^)(\S+)@([0-9a-f]{40})(\s|$)')
         text = _re.sub(self._convert_user_sha, text)
 
         _re = re.compile(r'(\s|^)([0-9a-f]{40})(\s|$)')
@@ -31,12 +37,33 @@ class GitHubMarkdownConverter(object):
     def _gh_commit_url(self, project, sha, title):
         return u'[%s](%s)' % (title, self.gh_base_url + project + '/commit/' + sha)
 
+    def _gh_ticket_url(self, project, tid, title):
+        return u'[%s](%s)' % (title, self.gh_base_url + project + '/issues/' + str(tid))
+
     def _convert_sha(self, m):
         return '%s[%s]%s' % (m.group(1), m.group(2)[:6], m.group(3))
 
     def _convert_ticket(self, m):
         return '%s[%s]' % m.groups()
 
+    def _convert_user_ticket(self, m):
+        user = m.group(2)
+        tid = m.group(3)
+        if self.gh_project.startswith(user + '/'):
+            return '%s[%s]%s' % (m.group(1), '#' + tid, m.group(4))
+        return m.group(0)
+
+    def _convert_user_repo_ticket(self, m):
+        project = '%s/%s' % (m.group(2), m.group(3))
+        tid = m.group(4)
+        if project == self.gh_project:
+            link = ':'.join([self.project, '#' + tid])
+            return '%s[%s]%s' % (m.group(1), link, m.group(5))
+        title = project + '#' + tid
+        return ''.join([m.group(1),
+                        self._gh_ticket_url(project, tid, title),
+                        m.group(5)])
+
     def _convert_user_sha(self, m):
         user = m.group(2)
         sha = m.group(3)


[10/21] git commit: [#6622] ticket:435 Convert markdown in wiki

Posted by br...@apache.org.
[#6622] ticket:435 Convert markdown in wiki


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

Branch: refs/heads/master
Commit: 23db53ae5e8a8fed6796ecc5529468f009985ae8
Parents: 88365c6
Author: Igor Bondarenko <je...@gmail.com>
Authored: Mon Oct 14 16:52:09 2013 +0300
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Nov 13 17:16:56 2013 +0000

----------------------------------------------------------------------
 .../forgeimporters/github/tests/test_wiki.py    | 31 +++++++++++++++++---
 ForgeImporters/forgeimporters/github/wiki.py    | 11 +++++--
 2 files changed, 35 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/23db53ae/ForgeImporters/forgeimporters/github/tests/test_wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tests/test_wiki.py b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
index 50c905d..ea54b10 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_wiki.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
@@ -28,6 +28,7 @@ from allura.tests import TestController
 from allura.tests.decorators import with_tool, without_module
 from alluratest.controller import setup_basic_test
 from forgeimporters.github.wiki import GitHubWikiImporter
+from forgeimporters.github.utils import GitHubMarkdownConverter
 
 
 # important to be distinct from 'test' which ForgeWiki uses, so that the tests can run in parallel and not clobber each other
@@ -290,6 +291,7 @@ Our website is <http://sf.net>.
         importer.github_wiki_url = 'https://github.com/a/b/wiki'
         importer.app = Mock()
         importer.app.url = '/p/test/wiki/'
+        importer.github_markdown_converter = GitHubMarkdownConverter('user', 'proj', 'p', 'mount')
         f = importer.convert_markup
         source = u'''Look at [[this page|Some Page]]
 
@@ -299,12 +301,33 @@ Our website is [[http://sf.net]].
 
 '[[Escaped Tag]]
 
-[External link to the wiki page](https://github.com/a/b/wiki/Page)
+```python
+codeblock
+```
 
-[External link](https://github.com/a/b/issues/1)'''
+ticket #1
 
-        # markdown should be untouched
-        assert_equal(f(source, 'test.md'), source)
+#1 header
+
+sha aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'''
+        result = u'''Look at [this page](Some Page)
+
+More info at: [MoreInfo] [Even More Info]
+
+Our website is <http://sf.net>.
+
+[[Escaped Tag]]
+
+~~~~
+codeblock
+~~~~
+
+ticket [#1]
+
+#1 header
+
+sha [aaaaaa]'''
+        assert_equal(f(source, 'test.md').strip(), result)
 
         assert_equal(f(u'h1. Hello', 't.textile').strip(), u'# Hello')
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/23db53ae/ForgeImporters/forgeimporters/github/wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/wiki.py b/ForgeImporters/forgeimporters/github/wiki.py
index 4bf796c..1290224 100644
--- a/ForgeImporters/forgeimporters/github/wiki.py
+++ b/ForgeImporters/forgeimporters/github/wiki.py
@@ -155,6 +155,12 @@ class GitHubWikiImporter(ToolImporter):
         )
         with_history = tool_option == 'import_history'
         ThreadLocalORMSession.flush_all()
+        self.github_markdown_converter = GitHubMarkdownConverter(
+            user_name,
+            project_name,
+            project.shortname,
+            self.app.config.options.mount_point,
+        )
         try:
             M.session.artifact_orm_session._get().skip_mod_date = True
             with h.push_config(c, app=self.app):
@@ -265,9 +271,8 @@ class GitHubWikiImporter(ToolImporter):
         """
         name, ext = os.path.splitext(filename)
         if ext in self.markdown_exts:
-            text = GitHubMarkdownConverter.convert(text)
-            return text
-            #return self.convert_gollum_tags(text)
+            text = self.github_markdown_converter.convert(text)
+            return self.convert_gollum_tags(text)
 
         try:
             import html2text


[18/21] git commit: [#6622] ticket:494 handle ``` without a blank line before it

Posted by br...@apache.org.
[#6622] ticket:494 handle ``` without a blank line before it


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

Branch: refs/heads/master
Commit: 479c43e4cb025e4751a27871e1307ab7f382c963
Parents: 9efb689
Author: Igor Bondarenko <je...@gmail.com>
Authored: Wed Nov 13 12:11:42 2013 +0200
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Nov 13 17:16:57 2013 +0000

----------------------------------------------------------------------
 .../forgeimporters/github/tests/test_utils.py   | 32 ++++++++++++++++++++
 .../forgeimporters/github/tests/test_wiki.py    |  1 -
 ForgeImporters/forgeimporters/github/utils.py   |  9 ++++--
 .../forgeimporters/tests/github/test_tracker.py |  2 --
 4 files changed, 38 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/479c43e4/ForgeImporters/forgeimporters/github/tests/test_utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tests/test_utils.py b/ForgeImporters/forgeimporters/github/tests/test_utils.py
index f31bba8..432c536 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_utils.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_utils.py
@@ -95,3 +95,35 @@ Two code blocks here!
     }'''
 
         assert_equal(self.conv.convert(text).strip(), result)
+
+    def test_code_blocks_without_newline_before(self):
+        text = u'''
+There are some code snippet:
+```
+print 'Hello'
+```
+Pretty cool, ha?'''
+
+        result = u'''
+There are some code snippet:
+
+    print 'Hello'
+Pretty cool, ha?'''
+        assert_equal(self.conv.convert(text).strip(), result.strip())
+        text = text.replace('```', '~~~')
+        assert_equal(self.conv.convert(text).strip(), result.strip())
+
+        text = u'''
+There are some code snippet:
+```python
+print 'Hello'
+```
+Pretty cool, ha?'''
+
+        result = u'''
+There are some code snippet:
+
+    :::python
+    print 'Hello'
+Pretty cool, ha?'''
+        assert_equal(self.conv.convert(text).strip(), result.strip())

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/479c43e4/ForgeImporters/forgeimporters/github/tests/test_wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tests/test_wiki.py b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
index b9b18bd..dec92a4 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_wiki.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
@@ -318,7 +318,6 @@ Our website is <http://sf.net>.
 
 [[Escaped Tag]]
 
-
     :::python
     codeblock
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/479c43e4/ForgeImporters/forgeimporters/github/utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/utils.py b/ForgeImporters/forgeimporters/github/utils.py
index cfc3a59..0beaba6 100644
--- a/ForgeImporters/forgeimporters/github/utils.py
+++ b/ForgeImporters/forgeimporters/github/utils.py
@@ -6,7 +6,7 @@ class GitHubMarkdownConverter(object):
     def __init__(self, gh_user, gh_project):
         self.gh_project = '%s/%s' % (gh_user, gh_project)
         self.gh_base_url = u'https://github.com/'
-        self.code_patterns = ['```', '~~~~~']
+        self.code_patterns = ['```', '~~~']
 
     def convert(self, text):
         lines = self._parse_lines(text.split('\n'))
@@ -15,10 +15,13 @@ class GitHubMarkdownConverter(object):
     def _parse_lines(self, lines):
         in_block = False
         new_lines = []
-        for line in lines:
+        for i, line in enumerate(lines):
             nextline = False
             for p in self.code_patterns:
                 if line.startswith(p):
+                    prev_line = lines[i-1].strip() if (i-1) >= 0 else ''
+                    if len(prev_line) > 0 and not in_block:
+                        new_lines.append('')
                     if p == '```':
                         syntax = line.lstrip('`').strip()
                         if syntax:
@@ -135,4 +138,4 @@ class GitHubMarkdownConverter(object):
         return '<s>%s</s>' % m.group(1)
 
     def _codeblock_syntax(self, text):
-        return '\n    :::%s' % text
+        return '    :::%s' % text

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/479c43e4/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 e991382..e3da3c7 100644
--- a/ForgeImporters/forgeimporters/tests/github/test_tracker.py
+++ b/ForgeImporters/forgeimporters/tests/github/test_tracker.py
@@ -195,7 +195,6 @@ def hello(name):
 
 Hello
 
-
     :::python
     def hello(name):
         print "Hello, " + name'''
@@ -230,7 +229,6 @@ def hello(name):
 
 Hello
 
-
     :::python
     def hello(name):
         print "Hello, " + name'''


[14/21] git commit: [#6622] ticket:435 Add newline at the begining of ticket comments

Posted by br...@apache.org.
[#6622] ticket:435 Add newline at the begining of ticket comments

After 'Originally posted by' in ticket comments should be extra newline.
Without it some markup doesn't properly converted (e.g. code blocks).


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

Branch: refs/heads/master
Commit: 4b7b2b0c21f6ec19170cde47ab68b8cbc3717ccb
Parents: d2d337b
Author: Igor Bondarenko <je...@gmail.com>
Authored: Mon Oct 14 17:23:31 2013 +0300
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Nov 13 17:16:56 2013 +0000

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


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/4b7b2b0c/ForgeImporters/forgeimporters/github/tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tracker.py b/ForgeImporters/forgeimporters/github/tracker.py
index c2141ce..5e3c134 100644
--- a/ForgeImporters/forgeimporters/github/tracker.py
+++ b/ForgeImporters/forgeimporters/github/tracker.py
@@ -180,7 +180,7 @@ class GitHubTrackerImporter(ToolImporter):
         for comment in extractor.iter_comments(issue):
             body, attachments = self._get_attachments(comment['body'])
             if comment['user']:
-                posted_by = u'*Originally posted by:* {}\n'.format(
+                posted_by = u'*Originally posted by:* {}\n\n'.format(
                     self.get_user_link(comment['user']['login']))
                 body = posted_by + body
             p = ticket.discussion_thread.add_post(

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/4b7b2b0c/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 43a3bb6..bac2a1a 100644
--- a/ForgeImporters/forgeimporters/tests/github/test_tracker.py
+++ b/ForgeImporters/forgeimporters/tests/github/test_tracker.py
@@ -138,7 +138,7 @@ class TestTrackerImporter(TestCase):
         importer.github_markdown_converter = GitHubMarkdownConverter('user', 'project')
         importer.process_comments(extractor, ticket, issue)
         self.assertEqual(ticket.discussion_thread.add_post.call_args_list[0], mock.call(
-                text='*Originally posted by:* [me](https://github.com/me)\nhello',
+                text='*Originally posted by:* [me](https://github.com/me)\n\nhello',
                 timestamp=datetime(2013, 8, 26, 16, 57, 53),
                 ignore_security=True,
             ))
@@ -226,6 +226,7 @@ def hello(name):
     print "Hello, " + name
 ```'''
         body_converted = '''*Originally posted by:* [me](https://github.com/me)
+
 Hello
 
 ~~~~


[02/21] git commit: [#6622] ticket:435 Fix user@sha regex

Posted by br...@apache.org.
[#6622] ticket:435 Fix user@sha regex


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

Branch: refs/heads/master
Commit: f0e61173294de836ef0b59f6954806f34e63cd21
Parents: 3c12029
Author: Igor Bondarenko <je...@gmail.com>
Authored: Mon Oct 14 16:16:29 2013 +0300
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Nov 13 17:16:55 2013 +0000

----------------------------------------------------------------------
 ForgeImporters/forgeimporters/github/utils.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f0e61173/ForgeImporters/forgeimporters/github/utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/utils.py b/ForgeImporters/forgeimporters/github/utils.py
index 6d22266..defe391 100644
--- a/ForgeImporters/forgeimporters/github/utils.py
+++ b/ForgeImporters/forgeimporters/github/utils.py
@@ -15,7 +15,7 @@ class GitHubMarkdownConverter(object):
         _re = re.compile(r'(\s|^)(.+)/(.+)@([0-9a-f]{40})(\s|$)')
         text = _re.sub(self._convert_user_repo_sha, text)
 
-        _re = re.compile(r'\s\S*@([0-9a-f]{40})')
+        _re = re.compile(r'(\s|^)(.+)@([0-9a-f]{40})(\s|$)')
         text = _re.sub(self._convert_user_sha, text)
 
         _re = re.compile(r'(\s|^)([0-9a-f]{40})(\s|$)')
@@ -38,7 +38,11 @@ class GitHubMarkdownConverter(object):
         return '%s[%s]' % m.groups()
 
     def _convert_user_sha(self, m):
-        return '[%s]' % (m.group(1)[:6])
+        user = m.group(2)
+        sha = m.group(3)
+        if self.gh_project.startswith(user + '/'):
+            return '%s[%s]%s' % (m.group(1), sha[:6], m.group(4))
+        return m.group(0)
 
     def _convert_user_repo_sha(self, m):
         project = '%s/%s' % (m.group(2), m.group(3))


[12/21] git commit: [#6622] ticket:435 Convert markdown in tracker

Posted by br...@apache.org.
[#6622] ticket:435 Convert markdown in tracker


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

Branch: refs/heads/master
Commit: 3cda147e048ce9519e3fba62e945242b79ec462f
Parents: 23db53a
Author: Igor Bondarenko <je...@gmail.com>
Authored: Mon Oct 14 17:03:07 2013 +0300
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Nov 13 17:16:56 2013 +0000

----------------------------------------------------------------------
 ForgeImporters/forgeimporters/github/tracker.py           | 10 ++++++++--
 .../forgeimporters/tests/github/test_tracker.py           |  6 +++++-
 2 files changed, 13 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3cda147e/ForgeImporters/forgeimporters/github/tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tracker.py b/ForgeImporters/forgeimporters/github/tracker.py
index c3c7ab4..6dfa507 100644
--- a/ForgeImporters/forgeimporters/github/tracker.py
+++ b/ForgeImporters/forgeimporters/github/tracker.py
@@ -111,6 +111,12 @@ class GitHubTrackerImporter(ToolImporter):
                     'project_name': project_name,
                 }
             )
+        self.github_markdown_converter = GitHubMarkdownConverter(
+            kw['user_name'],
+            project_name,
+            project.shortname,
+            app.config.options.mount_point,
+        )
         ThreadLocalORMSession.flush_all()
         extractor = GitHubProjectExtractor(project_name)
         try:
@@ -170,7 +176,7 @@ class GitHubTrackerImporter(ToolImporter):
                 u'{body}').format(
                     creator=self.get_user_link(issue['user']['login']),
                     owner=owner_line,
-                    body=GitHubMarkdownConverter().convert(body),
+                    body=self.github_markdown_converter.convert(body),
                 )
         ticket.labels = [label['name'] for label in issue['labels']]
 
@@ -182,7 +188,7 @@ class GitHubTrackerImporter(ToolImporter):
                     self.get_user_link(comment['user']['login']))
                 body = posted_by + body
             p = ticket.discussion_thread.add_post(
-                    text = GitHubMarkdownConverter().convert(body),
+                    text = self.github_markdown_converter.convert(body),
                     ignore_security = True,
                     timestamp = self.parse_datetime(comment['created_at']),
                 )

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3cda147e/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 7cd3c90..6b8c736 100644
--- a/ForgeImporters/forgeimporters/tests/github/test_tracker.py
+++ b/ForgeImporters/forgeimporters/tests/github/test_tracker.py
@@ -16,11 +16,11 @@
 #       under the License.
 
 from datetime import datetime
-from operator import itemgetter
 from unittest import TestCase
 import mock
 
 from ...github import tracker
+from forgeimporters.github.utils import GitHubMarkdownConverter
 
 
 class TestTrackerImporter(TestCase):
@@ -79,6 +79,7 @@ class TestTrackerImporter(TestCase):
             'labels': [{'name': 'first'}, {'name': 'second'}],
         }
         importer = tracker.GitHubTrackerImporter()
+        importer.github_markdown_converter = GitHubMarkdownConverter('user', 'project', 'p', 'mount')
         with mock.patch.object(tracker, 'datetime') as dt:
             dt.strptime.side_effect = lambda s,f: s
             importer.process_fields(ticket, issue)
@@ -134,6 +135,7 @@ class TestTrackerImporter(TestCase):
                 }
             ]
         importer = tracker.GitHubTrackerImporter()
+        importer.github_markdown_converter = GitHubMarkdownConverter('user', 'project', 'p', 'mount')
         importer.process_comments(extractor, ticket, issue)
         self.assertEqual(ticket.discussion_thread.add_post.call_args_list[0], mock.call(
                 text='*Originally posted by:* [me](https://github.com/me)\nhello',
@@ -208,6 +210,7 @@ def hello(name):
             'labels': [{'name': 'first'}, {'name': 'second'}],
         }
         importer = tracker.GitHubTrackerImporter()
+        importer.github_markdown_converter = GitHubMarkdownConverter('user', 'project', 'p', 'mount')
         with mock.patch.object(tracker, 'datetime') as dt:
             dt.strptime.side_effect = lambda s,f: s
             importer.process_fields(ticket, issue)
@@ -238,6 +241,7 @@ def hello(name):
                 }
             ]
         importer = tracker.GitHubTrackerImporter()
+        importer.github_markdown_converter = GitHubMarkdownConverter('user', 'project', 'p', 'mount')
         importer.process_comments(extractor, ticket, issue)
         self.assertEqual(ticket.discussion_thread.add_post.call_args_list[0], mock.call(
                 text=body_converted,


[06/21] git commit: [#6622] ticket:435 Convert github mardown in tickets & comments

Posted by br...@apache.org.
[#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/master
Commit: b6f29e90a3c187eea388dfd776a472b489e11a76
Parents: 44a7d0a
Author: Igor Bondarenko <je...@gmail.com>
Authored: Mon Oct 14 14:30:29 2013 +0300
Committer: Dave Brondsema <db...@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,
+            ))


[16/21] git commit: [#6622] ticket:469 A little refactoring and regexes fix

Posted by br...@apache.org.
[#6622] ticket:469 A little refactoring and regexes fix


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

Branch: refs/heads/master
Commit: 05de134fbe059dd5b8b6c17d04dee9127ab52aaf
Parents: 11e2621
Author: Igor Bondarenko <je...@gmail.com>
Authored: Mon Nov 11 13:07:47 2013 +0200
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Nov 13 17:16:57 2013 +0000

----------------------------------------------------------------------
 .../forgeimporters/github/tests/test_utils.py   | 12 +++++-----
 ForgeImporters/forgeimporters/github/utils.py   | 23 +++++++++-----------
 2 files changed, 16 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/05de134f/ForgeImporters/forgeimporters/github/tests/test_utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tests/test_utils.py b/ForgeImporters/forgeimporters/github/tests/test_utils.py
index f426d6b..f31bba8 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_utils.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_utils.py
@@ -42,12 +42,7 @@ class TestGitHubMarkdownConverter(object):
         text = 'Ticket #1'
         result = self.conv.convert(text)
         assert_equal(result, 'Ticket [#1]')
-
-        # github treats '#' in the begining as a header
-        text = '#1'
-        assert_equal(self.conv.convert(text), '#1')
-        text = '  #1'
-        assert_equal(self.conv.convert(text), '  #1')
+        assert_equal(self.conv.convert('#1'), '[#1]')
 
     def test_convert_user_ticket(self):
         text = 'user#1'
@@ -73,6 +68,11 @@ class TestGitHubMarkdownConverter(object):
         text = '~~mistake~~'
         assert_equal(self.conv.convert(text), '<s>mistake</s>')
 
+    def test_inline_code_block(self):
+        text = u'This `~~some text~~` converts to this ~~strike out~~.'
+        result = u'This `~~some text~~` converts to this <s>strike out</s>.'
+        assert_equal(self.conv.convert(text).strip(), result)
+
     def test_convert_code_blocks(self):
         text = u'''```python
 print "Hello!"

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/05de134f/ForgeImporters/forgeimporters/github/utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/utils.py b/ForgeImporters/forgeimporters/github/utils.py
index d509aa7..cfc3a59 100644
--- a/ForgeImporters/forgeimporters/github/utils.py
+++ b/ForgeImporters/forgeimporters/github/utils.py
@@ -18,9 +18,9 @@ class GitHubMarkdownConverter(object):
         for line in lines:
             nextline = False
             for p in self.code_patterns:
-                if line.lstrip().startswith(p):
+                if line.startswith(p):
                     if p == '```':
-                        syntax = line.lstrip().lstrip('`').strip()
+                        syntax = line.lstrip('`').strip()
                         if syntax:
                             new_lines.append(self._codeblock_syntax(syntax))
                     in_block = not in_block
@@ -31,22 +31,19 @@ class GitHubMarkdownConverter(object):
 
             if in_block:
                 new_lines.append(self._handle_code(line))
+            elif line.startswith('    '):
+                # indentation syntax code block - leave as is
+                new_lines.append(line)
             else:
-                _re = re.compile(r'`\s*(.*?)`')
+                _re = re.compile(r'`.*?`')
                 inline_matches = _re.findall(line)
-
-                if line.startswith('    '):
-                    # code block due to github syntax
-                    new_lines.append(line)
-                elif inline_matches and not inline_matches[0].isspace():
+                if inline_matches:
                     # need to not handle inline blocks as a text
                     for i, m in enumerate(inline_matches):
-                        line = line.replace('`%s`' % m, '<inline_block>%s</inline_block>' % i)
-
+                        line = line.replace(m, '<inline_block>%s</inline_block>' % i)
                     line = self._handle_non_code(line)
                     for i, m in enumerate(inline_matches):
-                        line = line.replace('<inline_block>%s</inline_block>' % i, inline_matches[i])
-
+                        line = line.replace('<inline_block>%s</inline_block>' % i, m)
                     new_lines.append(line)
                 else:
                     new_lines.append(self._handle_non_code(line))
@@ -71,7 +68,7 @@ class GitHubMarkdownConverter(object):
         _re = re.compile(r'(\b)(\S+)#(\d+)(\b)')
         text = _re.sub(self._convert_user_ticket, text)
 
-        _re = re.compile(r'(\S+\s+)(#\d+)')
+        _re = re.compile(r'(\s|^)(#\d+)')
         text = _re.sub(self._convert_ticket, text)
 
         _re = re.compile(r'(\b)(\S+)/(\S+)@([0-9a-f]{40})(\b)')


[09/21] git commit: [#6622] ticket:469 handling github inline code

Posted by br...@apache.org.
[#6622] ticket:469 handling github inline code


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

Branch: refs/heads/master
Commit: 43f16922c239d5445e455986771783d0e536ffcb
Parents: f9db5f9
Author: coldmind <so...@yandex.ru>
Authored: Wed Nov 6 19:35:57 2013 +0200
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Nov 13 17:16:56 2013 +0000

----------------------------------------------------------------------
 ForgeImporters/forgeimporters/github/utils.py | 24 ++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/43f16922/ForgeImporters/forgeimporters/github/utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/utils.py b/ForgeImporters/forgeimporters/github/utils.py
index 03dfe1b..292b41e 100644
--- a/ForgeImporters/forgeimporters/github/utils.py
+++ b/ForgeImporters/forgeimporters/github/utils.py
@@ -33,8 +33,14 @@ class GitHubMarkdownConverter(object):
             if in_block:
                 new_lines.append(self._handle_code(line))
             else:
+                _re = re.compile(r'`\s*(.*?)`')
+                is_inline_code = _re.findall(line)
+
                 if line.lstrip().startswith('    '):
-                    new_lines.append(self._handle_code(line))
+                    # code block due to github syntax
+                    continue
+                elif is_inline_code and not is_inline_code[0].isspace():
+                    new_lines.append(self._handle_inline_code(line))
                 else:
                     new_lines.append(self._handle_non_code(line))
         return new_lines
@@ -47,6 +53,16 @@ class GitHubMarkdownConverter(object):
         text = '    ' + text
         return text
 
+    def _handle_inline_code(self, text):
+        """Return a string that will replace ``text`` in the final text
+        output. ``text`` is inline code.
+
+        """
+        _re = re.compile(r'`(\s*)(.*?)`')
+        text = _re.sub(self._convert_inline_codeblock, text)
+
+        return text
+
     def _handle_non_code(self, text):
         """Return a string that will replace ``text`` in the final text
         output. ``text`` is *not* code.
@@ -125,4 +141,8 @@ class GitHubMarkdownConverter(object):
         return '<s>%s</s>' % m.group(1)
 
     def _codeblock_syntax(self, text):
-        return '\n    :::%s' % text
\ No newline at end of file
+        return '\n    :::%s' % text
+
+    def _convert_inline_codeblock(self, m):
+        text = m.group(0)
+        return '**%s**' % text


[05/21] git commit: [#6622] ticket:435 Move github-markdown conversion methods to separate class

Posted by br...@apache.org.
[#6622] ticket:435 Move github-markdown conversion methods to separate class


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

Branch: refs/heads/master
Commit: 44a7d0a11c2262fc2c46709f9f73df2a338c769b
Parents: 18b4e34
Author: Igor Bondarenko <je...@gmail.com>
Authored: Mon Oct 14 14:12:28 2013 +0300
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Nov 13 17:16:55 2013 +0000

----------------------------------------------------------------------
 .../forgeimporters/github/tests/test_utils.py   | 39 ++++++++++++++++
 .../forgeimporters/github/tests/test_wiki.py    | 36 ---------------
 ForgeImporters/forgeimporters/github/utils.py   | 47 ++++++++++++++++++++
 ForgeImporters/forgeimporters/github/wiki.py    |  6 ++-
 4 files changed, 90 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/44a7d0a1/ForgeImporters/forgeimporters/github/tests/test_utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tests/test_utils.py b/ForgeImporters/forgeimporters/github/tests/test_utils.py
new file mode 100644
index 0000000..8711312
--- /dev/null
+++ b/ForgeImporters/forgeimporters/github/tests/test_utils.py
@@ -0,0 +1,39 @@
+from nose.tools import assert_equal
+
+from forgeimporters.github.utils import GitHubMarkdownConverter
+
+
+class TestGitHubMarkdownConverter(object):
+
+    def setUp(self):
+        self.conv = GitHubMarkdownConverter
+
+    def test_convert_sha_github_markup(self):
+        text = 'SHA: 16c999e8c71134401a78d4d46435517b2271d6ac'
+        result = self.conv.convert(text)
+        assert_equal(result, 'SHA: [16c999]')
+
+    def test_convert_user_sha_github_markup(self):
+        text = 'User@SHA: mojombo@16c999e8c71134401a78d4d46435517b2271d6ac'
+        result = self.conv.convert(text)
+        assert_equal(result, 'User@SHA:[16c999]')
+
+    def test_convert_user_repo_sha_github_markup(self):
+        text = 'User/Repository@SHA: mojombo/github-flavored-markdown@16c999e8c71134401a78d4d46435517b2271d6ac'
+        result = self.conv.convert(text)
+        assert_equal(result, 'User/Repository@SHA: [16c999]')
+
+    def test_convert_ticket_github_markup(self):
+        text = 'Ticket: #1'
+        result = self.conv.convert(text)
+        assert_equal(result, 'Ticket: [#1]')
+
+    def test_convert_username_ticket_github_markup(self):
+        text = 'User#Num: user#1'
+        result = self.conv.convert(text)
+        assert_equal(result, 'User#Num: [#1]')
+
+    def test_convert_username_repo_ticket_github_markup(self):
+        text = 'User/Repository#Num: user/repo#1'
+        result = self.conv.convert(text)
+        assert_equal(result, 'User/Repository#Num: [#1]')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/44a7d0a1/ForgeImporters/forgeimporters/github/tests/test_wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tests/test_wiki.py b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
index bb2a383..50c905d 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_wiki.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
@@ -479,42 +479,6 @@ some text and **[Tips n' Tricks]**
         result = u'<p><strong>[[this checklist|Troubleshooting]]</strong></p>'
         assert_equal(f(source, 't.textile').strip(), result)
 
-    def test_convert_sha_github_markup(self):
-        html = 'SHA: 16c999e8c71134401a78d4d46435517b2271d6ac'
-        importer = GitHubWikiImporter()
-        result = importer.convert_github_markup(html)
-        assert_equal(result, 'SHA: [16c999]')
-
-    def test_convert_user_sha_github_markup(self):
-        html = 'User@SHA: mojombo@16c999e8c71134401a78d4d46435517b2271d6ac'
-        importer = GitHubWikiImporter()
-        result = importer.convert_github_markup(html)
-        assert_equal(result, 'User@SHA:[16c999]')
-
-    def test_convert_user_repo_sha_github_markup(self):
-        html = 'User/Repository@SHA: mojombo/github-flavored-markdown@16c999e8c71134401a78d4d46435517b2271d6ac'
-        importer = GitHubWikiImporter()
-        result = importer.convert_github_markup(html)
-        assert_equal(result, 'User/Repository@SHA: [16c999]')
-
-    def test_convert_ticket_github_markup(self):
-        html = 'Ticket: #1'
-        importer = GitHubWikiImporter()
-        result = importer.convert_github_markup(html)
-        assert_equal(result, 'Ticket: [#1]')
-
-    def test_convert_username_ticket_github_markup(self):
-        html = 'User#Num: user#1'
-        importer = GitHubWikiImporter()
-        result = importer.convert_github_markup(html)
-        assert_equal(result, 'User#Num: [#1]')
-
-    def test_convert_username_repo_ticket_github_markup(self):
-        html = 'User/Repository#Num: user/repo#1'
-        importer = GitHubWikiImporter()
-        result = importer.convert_github_markup(html)
-        assert_equal(result, 'User/Repository#Num: [#1]')
-
 
 class TestGitHubWikiImportController(TestController, TestCase):
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/44a7d0a1/ForgeImporters/forgeimporters/github/utils.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/utils.py b/ForgeImporters/forgeimporters/github/utils.py
new file mode 100644
index 0000000..c095f81
--- /dev/null
+++ b/ForgeImporters/forgeimporters/github/utils.py
@@ -0,0 +1,47 @@
+import re
+
+
+class GitHubMarkdownConverter(object):
+
+    @classmethod
+    def convert(cls, text):
+        _re = re.compile('\S*(#\d+)')
+        text = _re.sub(cls._convert_ticket, text)
+
+        _re = re.compile('\S*/\S*@(\w{40})')
+        text = _re.sub(cls._convert_user_repo_sha, text)
+
+        _re = re.compile('\s\S*@(\w{40})')
+        text = _re.sub(cls._convert_user_sha, text)
+
+        _re = re.compile(': (\w{40})')
+        text = _re.sub(cls._convert_sha, text)
+        _re = re.compile('~~(.*)~~',)
+        text = _re.sub(cls._convert_strikethrough, text)
+        _re = re.compile(r'```\w*(.*)```', re.DOTALL)
+        text = _re.sub(cls._convert_codeblock, text)
+        return text
+
+    @classmethod
+    def _convert_sha(cls, match):
+        return ': [%s]' % match.group(1)[:6]
+
+    @classmethod
+    def _convert_ticket(cls, match):
+        return '[%s]' % match.group(1)
+
+    @classmethod
+    def _convert_user_sha(cls, match):
+        return '[%s]' % (match.group(1)[:6])
+
+    @classmethod
+    def _convert_user_repo_sha(cls, match):
+        return '[%s]' % (match.group(1)[:6])
+
+    @classmethod
+    def _convert_strikethrough(cls, match):
+        return '<s>%s</s>' % match.group(1)
+
+    @classmethod
+    def _convert_codeblock(cls, match):
+        return '\n~~~~%s~~~~\n'% match.group(1)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/44a7d0a1/ForgeImporters/forgeimporters/github/wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/wiki.py b/ForgeImporters/forgeimporters/github/wiki.py
index f95ba44..4bf796c 100644
--- a/ForgeImporters/forgeimporters/github/wiki.py
+++ b/ForgeImporters/forgeimporters/github/wiki.py
@@ -51,6 +51,7 @@ from forgeimporters.base import (
         ToolImportForm,
         )
 from forgeimporters.github import GitHubProjectExtractor
+from forgeimporters.github.utils import GitHubMarkdownConverter
 from forgewiki import model as WM
 from forgewiki.converters import mediawiki2markdown
 
@@ -264,7 +265,9 @@ class GitHubWikiImporter(ToolImporter):
         """
         name, ext = os.path.splitext(filename)
         if ext in self.markdown_exts:
-            return self.convert_github_markup(text)
+            text = GitHubMarkdownConverter.convert(text)
+            return text
+            #return self.convert_gollum_tags(text)
 
         try:
             import html2text
@@ -394,7 +397,6 @@ class GitHubWikiImporter(ToolImporter):
                     a.setString(new_prefix + new_page)
         return unicode(soup)
 
-
     def _prepare_textile_text(self, text):
         # need to convert lists properly
         text_lines = text.splitlines()