You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2013/11/14 16:36:59 UTC
[07/41] git commit: [#6622] ticket:435 Fix sha regex
[#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/cj/6845
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)