allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [4/4] git commit: [#7381] adjust intra-project linking logic for GC hosted domains
Date Thu, 29 May 2014 21:08:12 GMT
[#7381] adjust intra-project linking logic for GC hosted domains


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

Branch: refs/heads/db/7381
Commit: 8b66467bfbccb7ebb35ced9e1a14891fbe1e8d7b
Parents: d66024b
Author: Dave Brondsema <dbrondsema@slashdotmedia.com>
Authored: Thu May 29 21:07:59 2014 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Thu May 29 21:07:59 2014 +0000

----------------------------------------------------------------------
 .../forgeimporters/google/__init__.py           | 10 ++++--
 .../forgeimporters/google/tests/test_init.py    | 36 ++++++++++++++++++++
 2 files changed, 44 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/8b66467b/ForgeImporters/forgeimporters/google/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/google/__init__.py b/ForgeImporters/forgeimporters/google/__init__.py
index 8c9081e..b848151 100644
--- a/ForgeImporters/forgeimporters/google/__init__.py
+++ b/ForgeImporters/forgeimporters/google/__init__.py
@@ -61,8 +61,12 @@ def _as_markdown(tag, project_name):
             qs = parse_qs(href.query)
             gc_link = not href.netloc or href.netloc == 'code.google.com'
             path_parts = href.path.split('/')
-            target_project = path_parts[
-                2] if gc_link and len(path_parts) >= 3 else ''
+            target_project = None
+            if gc_link:
+                if len(path_parts) >= 5 and path_parts[1] == 'a':
+                    target_project = '/'.join(path_parts[1:5])
+                elif len(path_parts) >= 3:
+                    target_project = path_parts[2]
             internal_link = target_project == project_name
             if gc_link and internal_link and 'id' in qs:
                 # rewrite issue 123 project-internal issue links
@@ -76,6 +80,8 @@ def _as_markdown(tag, project_name):
                 fragment = '[%s](%s)' % (
                     h.plain2markdown(
                         fragment.text, preserve_multiple_spaces=True, has_html_entities=True),
+                    # possibly need to adjust this URL for /a/ hosted domain URLs,
+                    # but it seems fragment['href'] always starts with / so it replaces the
given path
                     urljoin('https://code.google.com/p/%s/issues/' %
                             project_name, fragment['href']),
                 )

http://git-wip-us.apache.org/repos/asf/allura/blob/8b66467b/ForgeImporters/forgeimporters/google/tests/test_init.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/google/tests/test_init.py b/ForgeImporters/forgeimporters/google/tests/test_init.py
index 8acb0e3..2c536cd 100644
--- a/ForgeImporters/forgeimporters/google/tests/test_init.py
+++ b/ForgeImporters/forgeimporters/google/tests/test_init.py
@@ -18,9 +18,11 @@
 from nose.tools import assert_equal
 from mock import patch
 from formencode.validators import Invalid
+from BeautifulSoup import BeautifulSoup
 
 from allura.tests import decorators as td
 from forgeimporters.google import GoogleCodeProjectNameValidator, GoogleCodeProjectExtractor
+from forgeimporters.google import _as_markdown
 
 
 class TestGoogleCodeProjectNameValidator(object):
@@ -81,3 +83,37 @@ class TestGoogleCodeProjectNameValidator(object):
         )
         with td.raises(Invalid):
             GoogleCodeProjectNameValidator()._to_python('http://code.google.com/a/eclipselabs.org/bogus')
+
+
+class Test_as_markdown(object):
+
+    # this is covered by functional tests (useing test-issue.html)
+    # but adding some unit tests for easier verification of hosted domain link rewriting
+
+    def test_link_within_proj(self):
+        html = BeautifulSoup('''<pre>Foo: <a href="/p/myproj/issues/detail?id=1">issue
1</a></pre>''')
+        assert_equal(
+            _as_markdown(html.first(), 'myproj'),
+            'Foo: [issue 1](#1)'
+        )
+
+    def test_link_other_proj(self):
+        html = BeautifulSoup('''<pre>Foo: <a href="/p/other-project/issues/detail?id=1">issue
other-project:1</a></pre>''')
+        assert_equal(
+            _as_markdown(html.first(), 'myproj'),
+            'Foo: [issue other-project:1](https://code.google.com/p/other-project/issues/detail?id=1)'
+        )
+
+    def test_link_hosted_domain_within_proj(self):
+        html = BeautifulSoup('''<pre>Foo: <a href="/a/eclipselabs.org/p/myproj/issues/detail?id=1">issue
1</a></pre>''')
+        assert_equal(
+            _as_markdown(html.first(), 'a/eclipselabs.org/p/myproj'),
+            'Foo: [issue 1](#1)'
+        )
+
+    def test_link_hosted_domain_other_proj(self):
+        html = BeautifulSoup('''<pre>Foo: <a href="/a/eclipselabs.org/p/other-proj/issues/detail?id=1">issue
1</a></pre>''')
+        assert_equal(
+            _as_markdown(html.first(), 'a/eclipselabs.org/p/myproj'),
+            'Foo: [issue 1](https://code.google.com/a/eclipselabs.org/p/other-proj/issues/detail?id=1)'
+        )


Mime
View raw message