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 2014/03/26 22:57:27 UTC

[4/5] git commit: [#7134] Added option to allow overriding repo clone URL

[#7134] Added option to allow overriding repo clone URL

Signed-off-by: Cory Johns <cj...@slashdotmedia.com>


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

Branch: refs/heads/cj/7134
Commit: 7ce36bfa0707cba117b7bd1ef65c5e80e0213fcb
Parents: 8e88e3a
Author: Cory Johns <cj...@slashdotmedia.com>
Authored: Thu Mar 20 21:27:05 2014 +0000
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Wed Mar 26 18:58:16 2014 +0000

----------------------------------------------------------------------
 Allura/allura/lib/repository.py                 | 19 ++++++++++--
 Allura/allura/model/repository.py               |  7 +++--
 Allura/allura/templates/repo/admin_options.html | 32 ++++++++++++++++++++
 ForgeGit/forgegit/model/git_repo.py             |  5 ++-
 .../forgegit/tests/model/test_repository.py     | 12 ++++++++
 ForgeGit/forgegit/tests/test_git_app.py         |  2 +-
 .../forgesvn/tests/model/test_repository.py     |  4 +++
 ForgeSVN/forgesvn/tests/test_svn_app.py         |  2 +-
 8 files changed, 75 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/7ce36bfa/Allura/allura/lib/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/repository.py b/Allura/allura/lib/repository.py
index 6e073d9..4e956bf 100644
--- a/Allura/allura/lib/repository.py
+++ b/Allura/allura/lib/repository.py
@@ -20,7 +20,7 @@ from urllib import quote
 
 from pylons import tmpl_context as c, app_globals as g
 from pylons import request
-from tg import expose, redirect
+from tg import expose, redirect, flash
 from tg.decorators import with_trailing_slash, without_trailing_slash
 from bson import ObjectId
 
@@ -54,7 +54,8 @@ class RepositoryApp(Application):
     config_options = Application.config_options + [
         ConfigOption('cloned_from_project_id', ObjectId, None),
         ConfigOption('cloned_from_repo_id', ObjectId, None),
-        ConfigOption('init_from_url', str, None)
+        ConfigOption('init_from_url', str, None),
+        ConfigOption('clone_url', str, None)
     ]
     tool_label = 'Repository'
     default_mount_label = 'Code'
@@ -101,7 +102,6 @@ class RepositoryApp(Application):
                                   '/refresh',
                                   ))
         links += super(RepositoryApp, self).admin_menu()
-        [links.remove(l) for l in links[:] if l.label == 'Options']
         return links
 
     @h.exceptionless([], log)
@@ -246,3 +246,16 @@ class RepoAdminController(DefaultAdminController):
         else:
             return dict(app=self.app,
                         default_branch_name=self.app.default_branch_name)
+
+    @without_trailing_slash
+    @expose('jinja:allura:templates/repo/admin_options.html')
+    def options(self):
+        return dict(app=self.app)
+
+    @without_trailing_slash
+    @expose()
+    @require_post()
+    def set_options(self, clone_url=None, **kw):
+        self.app.config.options.clone_url = clone_url or None
+        flash('Repo options updated')
+        redirect(c.project.url() + 'admin/tools')

http://git-wip-us.apache.org/repos/asf/allura/blob/7ce36bfa/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 2c08017..12661a9 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -555,8 +555,11 @@ class Repository(Artifact, ActivityObject):
         '''Return a URL string suitable for copy/paste that describes _this_ repo,
            e.g., for use in a clone/checkout command
         '''
-        tpl = string.Template(
-            tg.config.get('scm.host.%s.%s' % (category, self.tool)))
+        if self.app.config.options.clone_url:
+            tpl = string.Template(self.app.config.options.clone_url)
+        else:
+            tpl = string.Template(
+                tg.config.get('scm.host.%s.%s' % (category, self.tool)))
         return tpl.substitute(dict(username=username, path=self.url_path + self.name))
 
     def clone_command(self, category, username=''):

http://git-wip-us.apache.org/repos/asf/allura/blob/7ce36bfa/Allura/allura/templates/repo/admin_options.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/repo/admin_options.html b/Allura/allura/templates/repo/admin_options.html
new file mode 100644
index 0000000..2b2c0b7
--- /dev/null
+++ b/Allura/allura/templates/repo/admin_options.html
@@ -0,0 +1,32 @@
+{#-
+       Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License.
+-#}
+<!DOCTYPE html>
+<form action="{{c.project.url()}}admin/{{app.config.options.mount_point}}/set_options" method="post">
+    <label class="grid-4">Clone / checkout URL:</label>
+    <div class="grid-9">
+        <input type="text" name="clone_url" id="clone_url" value="{{app.config.options.clone_url or ''}}"/>
+    </div>
+    <div class="grid-13">&nbsp;</div>
+    <hr>
+    <div class="grid-13">&nbsp;</div>
+    <div class="grid-13">
+	<input type="submit" value="Save"/>
+        <a href="#" class="close">Cancel</a>
+    </div>
+</form>

http://git-wip-us.apache.org/repos/asf/allura/blob/7ce36bfa/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index 8b9d1f8..1cb771b 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -71,7 +71,10 @@ class Repository(M.Repository):
         return super(Repository, self).suggested_clone_dest_path()[:-4]
 
     def clone_url(self, category, username=''):
-        return super(Repository, self).clone_url(category, username)[:-4]
+        clone_url = super(Repository, self).clone_url(category, username)
+        if clone_url.endswith('.git'):
+            clone_url = clone_url[:-4]
+        return clone_url
 
     def merge_command(self, merge_request):
         '''Return the command to merge a given commit to a given target branch'''

http://git-wip-us.apache.org/repos/asf/allura/blob/7ce36bfa/ForgeGit/forgegit/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/model/test_repository.py b/ForgeGit/forgegit/tests/model/test_repository.py
index 215ba0b..106c63e 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -470,6 +470,18 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
             ThreadLocalORMSession.flush_all()
             assert repo2.is_empty()
 
+    def test_clone_url(self):
+        assert_equal(
+            self.repo.clone_url('rw', 'nobody'),
+            'ssh://nobody@localhost:8022/scm-repo/test/testgit')
+        assert_equal(
+            self.repo.clone_url('https', 'nobody'),
+            'https://nobody@localhost:8022/scm-repo/test/testgit')
+        with h.push_config(self.repo.app.config.options, clone_url='https://$username@foo.com/'):
+            assert_equal(
+                self.repo.clone_url('https', 'user'),
+                'https://user@foo.com/')
+
 
 class TestGitImplementation(unittest.TestCase):
 

http://git-wip-us.apache.org/repos/asf/allura/blob/7ce36bfa/ForgeGit/forgegit/tests/test_git_app.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/test_git_app.py b/ForgeGit/forgegit/tests/test_git_app.py
index 0b59396..44ce991 100644
--- a/ForgeGit/forgegit/tests/test_git_app.py
+++ b/ForgeGit/forgegit/tests/test_git_app.py
@@ -40,7 +40,7 @@ class TestGitApp(unittest.TestCase):
         ThreadLocalORMSession.close_all()
 
     def test_admin_menu(self):
-        assert_equals(len(c.app.admin_menu()), 5)
+        assert_equals(len(c.app.admin_menu()), 6)
 
     def test_default_branch(self):
         assert c.app.default_branch_name == 'master'

http://git-wip-us.apache.org/repos/asf/allura/blob/7ce36bfa/ForgeSVN/forgesvn/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/tests/model/test_repository.py b/ForgeSVN/forgesvn/tests/model/test_repository.py
index 7dc2177..2fb7207 100644
--- a/ForgeSVN/forgesvn/tests/model/test_repository.py
+++ b/ForgeSVN/forgesvn/tests/model/test_repository.py
@@ -784,6 +784,10 @@ class TestRepo(_TestWithRepo):
             self.repo.clone_url('https', 'nobody')
             == 'https://nobody@localhost:8022/scm-repo/p/test/test1/'),\
             self.repo.clone_url('https', 'nobody')
+        with h.push_config(self.repo.app.config.options, clone_url='https://$username@foo.com/'):
+            assert_equal(
+                self.repo.clone_url('https', 'user'),
+                'https://user@foo.com/')
 
     def test_merge_request(self):
         M.MergeRequest.upsert(app_config_id=c.app.config._id, status='open')

http://git-wip-us.apache.org/repos/asf/allura/blob/7ce36bfa/ForgeSVN/forgesvn/tests/test_svn_app.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/tests/test_svn_app.py b/ForgeSVN/forgesvn/tests/test_svn_app.py
index 7fd8545..6ea576a 100644
--- a/ForgeSVN/forgesvn/tests/test_svn_app.py
+++ b/ForgeSVN/forgesvn/tests/test_svn_app.py
@@ -40,7 +40,7 @@ class TestSVNApp(unittest.TestCase):
         ThreadLocalORMSession.close_all()
 
     def test_admin_menu(self):
-        assert_equals(len(c.app.admin_menu()), 6)
+        assert_equals(len(c.app.admin_menu()), 7)
         assert_equals(c.app.admin_menu()[0].label, 'Checkout URL')
 
     def test_uninstall(self):