/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to launchpad.py

  • Committer: Jelmer Vernooij
  • Date: 2018-09-09 15:56:12 UTC
  • mto: (0.431.8 trunk)
  • mto: This revision was merged to the branch mainline in revision 7233.
  • Revision ID: jelmer@jelmer.uk-20180909155612-xuh0eqx3xzrjs34e
Publish command sort of works.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
from __future__ import absolute_import
18
18
 
19
19
from .propose import (
 
20
    Hoster,
20
21
    MergeProposal,
21
 
    MergeProposer,
 
22
    MergeProposalBuilder,
22
23
    MergeProposalExists,
23
24
    )
24
25
 
25
26
from ... import (
 
27
    branch as _mod_branch,
 
28
    controldir,
26
29
    errors,
27
30
    hooks,
28
31
    urlutils,
34
37
    lp_registration,
35
38
    )
36
39
""")
 
40
from ...transport import get_transport
37
41
 
38
42
 
39
43
# TODO(jelmer): Make selection of launchpad staging a configuration option.
40
44
 
41
 
 
42
45
class Launchpad(Hoster):
43
46
    """The Launchpad hosting service."""
44
47
 
45
 
 
46
 
class LaunchpadMergeProposer(MergeProposer):
 
48
    @classmethod
 
49
    def is_compatible(cls, branch):
 
50
        return lp_api.LaunchpadBranch.plausible_launchpad_url(branch.user_url)
 
51
 
 
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.
 
55
 
 
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
 
62
        """
 
63
        # TODO(jelmer): Prevent publishing to development focus
 
64
        launchpad = connect_launchpad()
 
65
        base_branch = lp_api.LaunchpadBranch.from_bzr(
 
66
            launchpad, base_branch)
 
67
        if project is None:
 
68
            project = base_branch.lp.project.name
 
69
        if owner is None:
 
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))
 
73
        try:
 
74
            dir_to = controldir.ControlDir.open_from_transport(to_transport)
 
75
        except errors.NotBranchError:
 
76
            # Didn't find anything
 
77
            dir_to = None
 
78
 
 
79
        if dir_to is None:
 
80
            br_to = local_branch.create_clone_on_transport(to_transport, revision_id=revision_id)
 
81
        else:
 
82
            try:
 
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))
 
89
 
 
90
    def get_proposer(self, source_branch, target_branch):
 
91
        return LaunchpadMergeProposalBuilder(source_branch, target_branch)
 
92
 
 
93
 
 
94
def connect_launchpad(lp_instance='production'):
 
95
    service = lp_registration.LaunchpadService(lp_instance=lp_instance)
 
96
    return lp_api.login(service)
 
97
 
 
98
 
 
99
class LaunchpadMergeProposalBuilder(MergeProposalBuilder):
47
100
 
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):
50
103
        """Constructor.
51
104
 
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
57
109
            production.
58
110
        :param approve: If True, mark the new proposal as approved immediately.
64
116
            lp_instance = 'staging'
65
117
        else:
66
118
            lp_instance = 'production'
67
 
        service = lp_registration.LaunchpadService(lp_instance=lp_instance)
68
 
        self.launchpad = lp_api.login(service)
 
119
        self.launchpad = connect_launchpad(lp_instance=lp_instance)
69
120
        self.source_branch = lp_api.LaunchpadBranch.from_bzr(
70
121
            self.launchpad, source_branch)
71
122
        if target_branch is None:
78
129
        self.approve = approve
79
130
        self.fixes = fixes
80
131
 
81
 
    @classmethod
82
 
    def is_compatible(cls, target_branch, source_branch):
83
 
        (scheme, user, password, host, port, path) = urlutils.parse_url(
84
 
            target_branch.user_url)
85
 
        return host in ('bazaar.launchpad.net', 'bazaar.staging.launchpad.net')
86
 
 
87
132
    def get_infotext(self):
88
133
        """Determine the initial comment for the merge proposal."""
89
134
        if self.commit_message is not None: