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:22 UTC
[03/21] git commit: [#6622] ticket:435 Fix ticket regexs
[#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)