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/09 00:12:20 UTC
git commit: [#6845] Handle issue X and rX references in GC tracker
importer
Updated Branches:
refs/heads/cj/6845 [created] cec98fd28
[#6845] Handle issue X and rX references in GC tracker importer
Signed-off-by: Cory Johns <cj...@slashdotmedia.com>
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/cec98fd2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/cec98fd2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/cec98fd2
Branch: refs/heads/cj/6845
Commit: cec98fd2871d29b99576bdf5f5665ab230ae34f9
Parents: 35eeee5
Author: Cory Johns <cj...@slashdotmedia.com>
Authored: Fri Nov 8 23:11:59 2013 +0000
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Fri Nov 8 23:11:59 2013 +0000
----------------------------------------------------------------------
.../forgeimporters/google/__init__.py | 25 ++++++++++++++---
ForgeImporters/forgeimporters/google/tracker.py | 2 +-
.../tests/data/google/test-issue.html | 4 ++-
.../tests/google/functional/test_tracker.py | 6 ++++-
.../tests/google/test_extractor.py | 28 +++++++++++---------
.../forgeimporters/tests/google/test_tracker.py | 2 +-
6 files changed, 47 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/cec98fd2/ForgeImporters/forgeimporters/google/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/google/__init__.py b/ForgeImporters/forgeimporters/google/__init__.py
index ae595e8..261b9f9 100644
--- a/ForgeImporters/forgeimporters/google/__init__.py
+++ b/ForgeImporters/forgeimporters/google/__init__.py
@@ -52,6 +52,25 @@ def _as_text(node, chunks=None):
_as_text(n, chunks)
return ''.join(chunks)
+def _as_markdown(tag):
+ fragments = []
+ for fragment in tag:
+ if getattr(fragment, 'name', None) == 'a':
+ href = urlparse(fragment['href'])
+ qs = parse_qs(href.query)
+ if not href.netloc and 'id' in qs:
+ fragment = '[%s](#%s)' % (fragment.text, qs['id'][0])
+ elif not href.netloc and 'r' in qs:
+ fragment = '[r%s]' % qs['r'][0]
+ else:
+ fragment = h.plain2markdown(fragment.text, preserve_multiple_spaces=True, has_html_entities=True)
+ elif getattr(fragment, 'name', None) == 'i':
+ fragment = '*%s*' % h.plain2markdown(fragment.text, preserve_multiple_spaces=True, has_html_entities=True)
+ else:
+ fragment = h.plain2markdown(str(fragment), preserve_multiple_spaces=True, has_html_entities=True)
+ fragments.append(fragment)
+ return ''.join(fragments).strip()
+
def csv_parser(page):
lines = page.readlines()
if not lines:
@@ -184,7 +203,7 @@ class GoogleCodeProjectExtractor(ProjectExtractor):
return bs.text
def get_issue_description(self):
- return _as_text(self.page.find(id='hc0').pre).strip()
+ return _as_markdown(self.page.find(id='hc0').pre)
def get_issue_created_date(self):
return self.page.find(id='hc0').find('span', 'date').get('title')
@@ -267,7 +286,7 @@ class Comment(object):
def __init__(self, tag):
self.author = UserLink(tag.find('span', 'author').find(True, 'userlink'))
self.created_date = tag.find('span', 'date').get('title')
- self.body = _as_text(tag.find('pre')).strip()
+ self.body = _as_markdown(tag.find('pre'))
self._get_updates(tag)
self.attachments = _get_attachments(tag)
@@ -287,7 +306,7 @@ class Comment(object):
u'{updates}'
).format(
author=self.author,
- body=h.plain2markdown(self.body, preserve_multiple_spaces=True, has_html_entities=True),
+ body=self.body,
updates='\n'.join(
'**%s** %s' % (k,v)
for k,v in self.updates.items()
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/cec98fd2/ForgeImporters/forgeimporters/google/tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/google/tracker.py b/ForgeImporters/forgeimporters/google/tracker.py
index 59b50bc..080ea90 100644
--- a/ForgeImporters/forgeimporters/google/tracker.py
+++ b/ForgeImporters/forgeimporters/google/tracker.py
@@ -184,7 +184,7 @@ class GoogleCodeTrackerImporter(ToolImporter):
u'{body}').format(
creator=issue.get_issue_creator(),
owner=owner_line,
- body=h.plain2markdown(issue.get_issue_description(), preserve_multiple_spaces=True, has_html_entities=True),
+ body=issue.get_issue_description(),
)
ticket.add_multiple_attachments(issue.get_issue_attachments())
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/cec98fd2/ForgeImporters/forgeimporters/tests/data/google/test-issue.html
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/data/google/test-issue.html b/ForgeImporters/forgeimporters/tests/data/google/test-issue.html
index 693ca1d..374c0e8 100644
--- a/ForgeImporters/forgeimporters/tests/data/google/test-issue.html
+++ b/ForgeImporters/forgeimporters/tests/data/google/test-issue.html
@@ -280,6 +280,8 @@ Test *Issue* for testing
if p.count > 5:
print "Not < 5 & != 5"
+References: <a href="/p/allura-google-importer/issues/detail?id=1">issue 1</a>, <a href="/p/allura-google-importer/source/detail?r=2">r2</a>
+
That's all
@@ -384,7 +386,7 @@ Test *comment* is a comment
<a name="c2" href="/p/allura-google-importer/issues/detail?id=6#c2">#2</a>
<a class="userlink" href="/u/101557263855536553789/">john...@gmail.com</a></span>
<pre>
-Another comment
+Another comment with references: <a href="/p/allura-google-importer/issues/detail?id=2">issue 2</a>, <a href="/p/allura-google-importer/source/detail?r=1">r1</a>
</pre>
</div>
<div class="cursor_off vt issuecomment" id="hc3">
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/cec98fd2/ForgeImporters/forgeimporters/tests/google/functional/test_tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/google/functional/test_tracker.py b/ForgeImporters/forgeimporters/tests/google/functional/test_tracker.py
index 528c2b6..2e52be6 100644
--- a/ForgeImporters/forgeimporters/tests/google/functional/test_tracker.py
+++ b/ForgeImporters/forgeimporters/tests/google/functional/test_tracker.py
@@ -125,6 +125,8 @@ class TestGCTrackerImporter(TestCase):
' if p\\.count > 5:\n'
' print "Not < 5 & \\!= 5"\n'
'\n'
+ 'References: [issue 1](#1), [r2]\n'
+ '\n'
'That\'s all'
)
self.assertEqual(ticket.status, 'Started')
@@ -178,6 +180,8 @@ class TestGCTrackerImporter(TestCase):
' if p.count > 5:\n'
' print "Not < 5 & \\!= 5"\n'
'\n'
+ 'References: [issue 1](#1), [r2]\n'
+ '\n'
'That\'s all'
)
@@ -217,7 +221,7 @@ class TestGCTrackerImporter(TestCase):
'text': (
'*Originally posted by:* [john...@gmail.com](http://code.google.com/u/101557263855536553789/)\n'
'\n'
- 'Another comment\n\n'
+ 'Another comment with references: [issue 2](#2), [r1]\n\n'
),
},
{
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/cec98fd2/ForgeImporters/forgeimporters/tests/google/test_extractor.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/google/test_extractor.py b/ForgeImporters/forgeimporters/tests/google/test_extractor.py
index c2c800a..032e122 100644
--- a/ForgeImporters/forgeimporters/tests/google/test_extractor.py
+++ b/ForgeImporters/forgeimporters/tests/google/test_extractor.py
@@ -170,22 +170,24 @@ class TestGoogleCodeProjectExtractor(TestCase):
self._p_soup.stop()
self.assertEqual(gpe.get_issue_summary(), 'Test "Issue"')
assert_equal(gpe.get_issue_description(),
- 'Test *Issue* for testing\n'
+ 'Test \\*Issue\\* for testing\n'
'\n'
- ' 1. Test List\n'
- ' 2. Item\n'
+ ' 1. Test List\n'
+ ' 2. Item\n'
'\n'
- '**Testing**\n'
+ '\\*\\*Testing\\*\\*\n'
'\n'
- ' * Test list 2\n'
- ' * Item\n'
+ ' \\* Test list 2\n'
+ ' \\* Item\n'
'\n'
- '# Test Section\n'
+ '\\# Test Section\n'
'\n'
- ' p = source.test_issue.post()\n'
- ' p.count = p.count *5 #* 6\n'
- ' if p.count > 5:\n'
- ' print "Not < 5 & != 5"\n'
+ ' p = source.test\\_issue.post\\(\\)\n'
+ ' p.count = p.count \\*5 \\#\\* 6\n'
+ ' if p.count > 5:\n'
+ ' print "Not < 5 & \\!= 5"\n'
+ '\n'
+ 'References: [issue 1](#1), [r2]\n'
'\n'
'That\'s all'
)
@@ -252,7 +254,7 @@ class TestGoogleCodeProjectExtractor(TestCase):
'author.name': 'john...@gmail.com',
'author.url': 'http://code.google.com/u/101557263855536553789/',
'created_date': 'Thu Aug 8 15:35:15 2013',
- 'body': 'Test *comment* is a comment',
+ 'body': 'Test \\*comment\\* is a comment',
'updates': {'Status:': 'Started', 'Labels:': '-OpSys-Linux OpSys-Windows'},
'attachments': ['at2.txt'],
},
@@ -260,7 +262,7 @@ class TestGoogleCodeProjectExtractor(TestCase):
'author.name': 'john...@gmail.com',
'author.url': 'http://code.google.com/u/101557263855536553789/',
'created_date': 'Thu Aug 8 15:35:34 2013',
- 'body': 'Another comment',
+ 'body': 'Another comment with references: [issue 2](#2), [r1]',
'updates': {},
'attachments': [],
},
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/cec98fd2/ForgeImporters/forgeimporters/tests/google/test_tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/google/test_tracker.py b/ForgeImporters/forgeimporters/tests/google/test_tracker.py
index 6e877f6..604eafd 100644
--- a/ForgeImporters/forgeimporters/tests/google/test_tracker.py
+++ b/ForgeImporters/forgeimporters/tests/google/test_tracker.py
@@ -166,7 +166,7 @@ class TestTrackerImporter(TestCase):
dt.strptime.side_effect = lambda s,f: s
importer.process_fields(ticket, issue)
self.assertEqual(ticket.summary, 'summary')
- self.assertEqual(ticket.description, '*Originally created by:* creator\n*Originally owned by:* owner\n\nmy \*description\* fool')
+ self.assertEqual(ticket.description, '*Originally created by:* creator\n*Originally owned by:* owner\n\nmy *description* fool')
self.assertEqual(ticket.status, 'status')
self.assertEqual(ticket.created_date, 'created_date')
self.assertEqual(ticket.mod_date, 'mod_date')