Merge lp:~cjwatson/launchpad/git-ssh-url-username into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18760
Proposed branch: lp:~cjwatson/launchpad/git-ssh-url-username
Merge into: lp:launchpad
Diff against target: 149 lines (+40/-12)
5 files modified
lib/lp/code/browser/gitref.py (+13/-1)
lib/lp/code/browser/gitrepository.py (+13/-1)
lib/lp/code/browser/tests/test_gitref.py (+4/-3)
lib/lp/code/browser/tests/test_gitrepository.py (+8/-5)
lib/lp/code/templates/git-macros.pt (+2/-2)
To merge this branch: bzr merge lp:~cjwatson/launchpad/git-ssh-url-username
Reviewer Review Type Date Requested Status
Maximiliano Bertacchini (community) Approve
Launchpad code reviewers Pending
Review via email: mp+353748@code.launchpad.net

Commit message

Include the appropriate username in git+ssh:// URLs in the UI.

To post a comment you must log in.
Revision history for this message
Maximiliano Bertacchini (maxiberta) wrote :

Looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/code/browser/gitref.py'
--- lib/lp/code/browser/gitref.py 2018-08-23 14:52:46 +0000
+++ lib/lp/code/browser/gitref.py 2018-08-25 16:24:20 +0000
@@ -12,9 +12,13 @@
12 ]12 ]
1313
14import json14import json
15from urllib import quote_plus
1615
17from lazr.restful.interface import copy_field16from lazr.restful.interface import copy_field
17from six.moves.urllib_parse import (
18 quote_plus,
19 urlsplit,
20 urlunsplit,
21 )
18from zope.component import getUtility22from zope.component import getUtility
19from zope.formlib.widgets import TextAreaWidget23from zope.formlib.widgets import TextAreaWidget
20from zope.interface import Interface24from zope.interface import Interface
@@ -106,6 +110,14 @@
106 return self.context.display_name110 return self.context.display_name
107111
108 @property112 @property
113 def git_ssh_url(self):
114 """The git+ssh:// URL for this branch, adjusted for this user."""
115 base_url = urlsplit(self.context.repository.git_ssh_url)
116 url = list(base_url)
117 url[1] = "{}@{}".format(self.user.name, base_url.hostname)
118 return urlunsplit(url)
119
120 @property
109 def user_can_push(self):121 def user_can_push(self):
110 """Whether the user can push to this branch."""122 """Whether the user can push to this branch."""
111 return (123 return (
112124
=== modified file 'lib/lp/code/browser/gitrepository.py'
--- lib/lp/code/browser/gitrepository.py 2018-06-22 10:01:34 +0000
+++ lib/lp/code/browser/gitrepository.py 2018-08-25 16:24:20 +0000
@@ -1,4 +1,4 @@
1# Copyright 2015-2016 Canonical Ltd. This software is licensed under the1# Copyright 2015-2018 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""Git repository views."""4"""Git repository views."""
@@ -26,6 +26,10 @@
26 copy_field,26 copy_field,
27 use_template,27 use_template,
28 )28 )
29from six.moves.urllib_parse import (
30 urlsplit,
31 urlunsplit,
32 )
29from zope.component import getUtility33from zope.component import getUtility
30from zope.event import notify34from zope.event import notify
31from zope.formlib import form35from zope.formlib import form
@@ -324,6 +328,14 @@
324 self.request, "launchpad.LimitedView", authorised_people)328 self.request, "launchpad.LimitedView", authorised_people)
325329
326 @property330 @property
331 def git_ssh_url(self):
332 """The git+ssh:// URL for this repository, adjusted for this user."""
333 base_url = urlsplit(self.context.git_ssh_url)
334 url = list(base_url)
335 url[1] = "{}@{}".format(self.user.name, base_url.hostname)
336 return urlunsplit(url)
337
338 @property
327 def user_can_push(self):339 def user_can_push(self):
328 """Whether the user can push to this branch."""340 """Whether the user can push to this branch."""
329 return (341 return (
330342
=== modified file 'lib/lp/code/browser/tests/test_gitref.py'
--- lib/lp/code/browser/tests/test_gitref.py 2018-08-23 14:52:46 +0000
+++ lib/lp/code/browser/tests/test_gitref.py 2018-08-25 16:24:20 +0000
@@ -134,11 +134,12 @@
134134
135 def test_clone_instructions(self):135 def test_clone_instructions(self):
136 [ref] = self.factory.makeGitRefs(paths=["refs/heads/branch"])136 [ref] = self.factory.makeGitRefs(paths=["refs/heads/branch"])
137 username = ref.owner.name
137 text = self.getMainText(ref, "+index", user=ref.owner)138 text = self.getMainText(ref, "+index", user=ref.owner)
138 self.assertTextMatchesExpressionIgnoreWhitespace(r"""139 self.assertTextMatchesExpressionIgnoreWhitespace(r"""
139 git clone -b branch https://.*140 git clone -b branch https://git.launchpad.dev/.*
140 git clone -b branch git\+ssh://.*141 git clone -b branch git\+ssh://{username}@git.launchpad.dev/.*
141 """, text)142 """.format(username=username), text)
142143
143 def makeCommitLog(self):144 def makeCommitLog(self):
144 authors = [self.factory.makePerson() for _ in range(5)]145 authors = [self.factory.makePerson() for _ in range(5)]
145146
=== modified file 'lib/lp/code/browser/tests/test_gitrepository.py'
--- lib/lp/code/browser/tests/test_gitrepository.py 2018-08-23 09:30:24 +0000
+++ lib/lp/code/browser/tests/test_gitrepository.py 2018-08-25 16:24:20 +0000
@@ -93,11 +93,12 @@
9393
94 def test_clone_instructions(self):94 def test_clone_instructions(self):
95 repository = self.factory.makeGitRepository()95 repository = self.factory.makeGitRepository()
96 username = repository.owner.name
96 text = self.getMainText(repository, "+index", user=repository.owner)97 text = self.getMainText(repository, "+index", user=repository.owner)
97 self.assertTextMatchesExpressionIgnoreWhitespace(r"""98 self.assertTextMatchesExpressionIgnoreWhitespace(r"""
98 git clone https://.*99 git clone https://git.launchpad.dev/.*
99 git clone git\+ssh://.*100 git clone git\+ssh://{username}@git.launchpad.dev/.*
100 """, text)101 """.format(username=username), text)
101102
102 def test_user_can_push(self):103 def test_user_can_push(self):
103 # A user can push if they have edit permissions.104 # A user can push if they have edit permissions.
@@ -164,13 +165,15 @@
164 # explain how to do so.165 # explain how to do so.
165 self.factory.makeSSHKey(person=self.user, send_notification=False)166 self.factory.makeSSHKey(person=self.user, send_notification=False)
166 repository = self.factory.makeGitRepository(owner=self.user)167 repository = self.factory.makeGitRepository(owner=self.user)
168 username = self.user.name
167 browser = self.getViewBrowser(repository)169 browser = self.getViewBrowser(repository)
168 directions = find_tag_by_id(browser.contents, "push-directions")170 directions = find_tag_by_id(browser.contents, "push-directions")
169 login_person(self.user)171 login_person(self.user)
170 self.assertThat(extract_text(directions), DocTestMatches(dedent("""172 self.assertThat(extract_text(directions), DocTestMatches(dedent("""
171 Update this repository:173 Update this repository:
172 git push git+ssh://git.launchpad.dev/{repository.shortened_path}174 git push
173 """).format(repository=repository),175 git+ssh://{username}@git.launchpad.dev/{repository.shortened_path}
176 """).format(username=username, repository=repository),
174 flags=doctest.NORMALIZE_WHITESPACE))177 flags=doctest.NORMALIZE_WHITESPACE))
175178
176 def test_push_directions_logged_in_can_push_no_sshkeys(self):179 def test_push_directions_logged_in_can_push_no_sshkeys(self):
177180
=== modified file 'lib/lp/code/templates/git-macros.pt'
--- lib/lp/code/templates/git-macros.pt 2016-11-17 23:16:12 +0000
+++ lib/lp/code/templates/git-macros.pt 2018-08-25 16:24:20 +0000
@@ -30,7 +30,7 @@
30 <tt class="command">30 <tt class="command">
31 git clone31 git clone
32 <tal:branch condition="branch_name|nothing" replace="string:-b ${branch_name}" />32 <tal:branch condition="branch_name|nothing" replace="string:-b ${branch_name}" />
33 <span class="ssh-url" tal:content="repository/git_ssh_url" />33 <span class="ssh-url" tal:content="view/git_ssh_url" />
34 </tt>34 </tt>
35 </tal:ssh>35 </tal:ssh>
36 </dd>36 </dd>
@@ -63,7 +63,7 @@
63 <dd>63 <dd>
64 <tt class="command">64 <tt class="command">
65 git push65 git push
66 <span class="ssh-url" tal:content="repository/git_ssh_url" />66 <span class="ssh-url" tal:content="view/git_ssh_url" />
67 <tal:branch condition="branch_name|nothing" replace="branch_name" />67 <tal:branch condition="branch_name|nothing" replace="branch_name" />
68 </tt>68 </tt>
69 </dd>69 </dd>