40
from ...transport import get_transport
39
43
# TODO(jelmer): Make selection of launchpad staging a configuration option.
42
45
class Launchpad(Hoster):
43
46
"""The Launchpad hosting service."""
46
class LaunchpadMergeProposer(MergeProposer):
49
def is_compatible(cls, branch):
50
return lp_api.LaunchpadBranch.plausible_launchpad_url(branch.user_url)
52
def publish(self, local_branch, base_branch, name, project=None, owner=None,
53
revision_id=None, overwrite=False):
54
"""Publish a branch to the site, derived from base_branch.
56
:param base_branch: branch to derive the new branch from
57
:param new_branch: branch to publish
58
:param name: Name of the new branch on the remote host
59
:param project: Optional project name
60
:param owner: Optional owner
61
:return: resulting branch
63
# TODO(jelmer): Prevent publishing to development focus
64
launchpad = connect_launchpad()
65
base_branch = lp_api.LaunchpadBranch.from_bzr(
66
launchpad, base_branch)
68
project = base_branch.lp.project.name
70
owner = launchpad.me.name
71
# TODO(jelmer): Surely there is a better way of creating one of these URLs?
72
to_transport = get_transport("lp:~%s/%s/%s" % (owner, project, name))
74
dir_to = controldir.ControlDir.open_from_transport(to_transport)
75
except errors.NotBranchError:
76
# Didn't find anything
80
br_to = local_branch.create_clone_on_transport(to_transport, revision_id=revision_id)
83
br_to = dir_to.push_branch(local_branch, revision_id, overwrite=overwrite).target_branch
84
except errors.DivergedBranches:
85
raise errors.BzrCommandError(gettext('These branches have diverged.'
86
' See "brz help diverged-branches"'
87
' for more information.'))
88
return br_to, ("https://code.launchpad.net/~%s/%s/%s" % (owner, project, name))
90
def get_proposer(self, source_branch, target_branch):
91
return LaunchpadMergeProposalBuilder(source_branch, target_branch)
94
def connect_launchpad(lp_instance='production'):
95
service = lp_registration.LaunchpadService(lp_instance=lp_instance)
96
return lp_api.login(service)
99
class LaunchpadMergeProposalBuilder(MergeProposalBuilder):
48
101
def __init__(self, source_branch, target_branch, message=None,
49
reviews=None, staging=None, approve=None, fixes=None):
102
staging=None, approve=None, fixes=None):
52
105
:param source_branch: The branch to propose for merging.
53
106
:param target_branch: The branch to merge into.
54
107
:param message: The commit message to use. (May be None.)
55
:param reviews: A list of tuples of reviewer, review type.
56
108
:param staging: If True, propose the merge against staging instead of
58
110
:param approve: If True, mark the new proposal as approved immediately.