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 18:36:28 UTC
[07/43] git commit: [#6622] ticket:435 Fix user/repo@sha regex
[#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/cj/6836
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)