Merge lp:~asbalderson/jenkins-launchpad-plugin/private-repo into lp:jenkins-launchpad-plugin

Proposed by Alexander Balderson
Status: Merged
Merged at revision: 145
Proposed branch: lp:~asbalderson/jenkins-launchpad-plugin/private-repo
Merge into: lp:jenkins-launchpad-plugin
Diff against target: 45 lines (+14/-6)
1 file modified
jlp/commands/autoland.py (+14/-6)
To merge this branch: bzr merge lp:~asbalderson/jenkins-launchpad-plugin/private-repo
Reviewer Review Type Date Requested Status
Joshua Powers (community) Approve
Review via email: mp+364540@code.launchpad.net

Commit message

Use git+ssh url's for all autoland operations.

When trying to autoland against repo's which are private on launchpad,
the https_url doesnt exist. Use the git+ssh url instead for those
operations. Because the user performing autoland operations has
access to push to the repo, it should also have access to clone as well.

Description of the change

I suspect the reason the https url was used originally was to ensure that the wrong repo couldnt be pushed to, but that's what automation is for. which should ensure we dont accidentally push incorrectly.

To post a comment you must log in.
Revision history for this message
Joshua Powers (powersj) :
review: Approve
145. By Joshua Powers

Use git+ssh url's for all autoland operations.

When trying to autoland against repo's which are private on launchpad,
the https_url doesnt exist. Use the git+ssh url instead for those
operations. Because the user performing autoland operations has
access to push to the repo, it should also have access to clone as well.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'jlp/commands/autoland.py'
2--- jlp/commands/autoland.py 2018-07-31 15:57:38 +0000
3+++ jlp/commands/autoland.py 2019-03-15 16:41:46 +0000
4@@ -107,6 +107,17 @@
5 return _merge_and_commit_bzr(mp, args)
6
7
8+def _get_user_and_git_ssh_url(url):
9+ """Create a git+ssh://user@git.launchpad.net/repo like url.
10+
11+ @param url: a git+ssh url without a user
12+ @return: a git+ssh with user url
13+ """
14+ return url.replace(
15+ 'ssh://', 'ssh://%s@' % get_config_option('launchpad_login')
16+ )
17+
18+
19 def _git_source_info(mp):
20 """Get the current sha, author, and email of the source branch.
21
22@@ -116,7 +127,7 @@
23 tmp_dir = tempfile.mkdtemp()
24 try:
25 proposal = git.Repo.clone_from(
26- mp.source_git_repository.git_https_url,
27+ _get_user_and_git_ssh_url(mp.source_git_repository.git_ssh_url),
28 tmp_dir, branch=get_source_branch(mp))
29 revid = proposal.head.object.hexsha
30 author = proposal.head.commit.author.name
31@@ -189,13 +200,10 @@
32 args, LaunchpadVote.NEEDS_FIXING)
33 return 1
34
35- # create a git+ssh://user@git.launchpad.net/repo like url
36- url = mp.target_git_repository.git_ssh_url.replace(
37- 'ssh://', 'ssh://%s@' % get_config_option('launchpad_login')
38- )
39+ url = _get_user_and_git_ssh_url(mp.target_git_repository.git_ssh_url)
40 target = git.Repo.clone_from(url, git_dir, branch=get_target_branch(mp))
41 source = target.create_remote(
42- 'source', mp.source_git_repository.git_https_url
43+ 'source', _get_user_and_git_ssh_url(mp.source_git_repository.git_ssh_url)
44 )
45 source.fetch()
46

Subscribers

People subscribed via source and target branches