/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 breezy/plugins/launchpad/cmds.py

  • Committer: Jelmer Vernooij
  • Date: 2020-03-22 01:35:14 UTC
  • mfrom: (7490.7.6 work)
  • mto: This revision was merged to the branch mainline in revision 7499.
  • Revision ID: jelmer@jelmer.uk-20200322013514-7vw1ntwho04rcuj3
merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Launchpad plugin commands."""
18
18
 
19
 
from __future__ import absolute_import
20
 
 
21
19
from ... import (
22
20
    branch as _mod_branch,
23
21
    controldir,
35
33
    Option,
36
34
    ListOption,
37
35
    )
38
 
from ...sixish import (
39
 
    text_type,
40
 
    )
41
36
 
42
37
 
43
38
class cmd_launchpad_open(Command):
85
80
        trace.note(gettext('Opening %s in web browser') % web_url)
86
81
        if not dry_run:
87
82
            import webbrowser   # this import should not be lazy
88
 
                                # otherwise brz.exe lacks this module
 
83
            # otherwise brz.exe lacks this module
89
84
            webbrowser.open(web_url)
90
85
 
91
86
 
140
135
            account.set_lp_login(name)
141
136
            if verbose:
142
137
                self.outf.write(gettext("Launchpad user ID set to '%s'.\n") %
143
 
                                                                        (name,))
 
138
                                (name,))
144
139
 
145
140
 
146
141
class cmd_launchpad_logout(Command):
167
162
                old_username)
168
163
 
169
164
 
170
 
# XXX: cmd_launchpad_mirror is untested
171
 
class cmd_launchpad_mirror(Command):
172
 
    __doc__ = """Ask Launchpad to mirror a branch now."""
173
 
 
174
 
    aliases = ['lp-mirror']
175
 
    takes_args = ['location?']
176
 
 
177
 
    def run(self, location='.'):
178
 
        from . import lp_api
179
 
        from .lp_registration import LaunchpadService
180
 
        branch, _ = _mod_branch.Branch.open_containing(location)
181
 
        service = LaunchpadService()
182
 
        launchpad = lp_api.login(service)
183
 
        lp_branch = lp_api.LaunchpadBranch.from_bzr(launchpad, branch,
184
 
                create_missing=False)
185
 
        lp_branch.lp.requestMirror()
186
 
 
187
 
 
188
 
class cmd_lp_propose_merge(Command):
189
 
    __doc__ = """Propose merging a branch on Launchpad.
190
 
 
191
 
    This will open your usual editor to provide the initial comment.  When it
192
 
    has created the proposal, it will open it in your default web browser.
193
 
 
194
 
    The branch will be proposed to merge into SUBMIT_BRANCH.  If SUBMIT_BRANCH
195
 
    is not supplied, the remembered submit branch will be used.  If no submit
196
 
    branch is remembered, the development focus will be used.
197
 
 
198
 
    By default, the SUBMIT_BRANCH's review team will be requested to review
199
 
    the merge proposal.  This can be overriden by specifying --review (-R).
200
 
    The parameter the launchpad account name of the desired reviewer.  This
201
 
    may optionally be followed by '=' and the review type.  For example:
202
 
 
203
 
      brz lp-propose-merge --review jrandom --review review-team=qa
204
 
 
205
 
    This will propose a merge,  request "jrandom" to perform a review of
206
 
    unspecified type, and request "review-team" to perform a "qa" review.
207
 
    """
208
 
 
209
 
    takes_options = [Option('staging',
210
 
                            help='Propose the merge on staging.'),
211
 
                     Option('message', short_name='m', type=text_type,
212
 
                            help='Commit message.'),
213
 
                     Option('approve',
214
 
                            help=('Mark the proposal as approved immediately, '
215
 
                                  'setting the approved revision to tip.')),
216
 
                     Option('fixes', 'The bug this proposal fixes.', str),
217
 
                     ListOption('review', short_name='R', type=text_type,
218
 
                            help='Requested reviewer and optional type.')]
219
 
 
220
 
    takes_args = ['submit_branch?']
221
 
 
222
 
    aliases = ['lp-submit', 'lp-propose']
223
 
 
224
 
    def run(self, submit_branch=None, review=None, staging=False,
225
 
            message=None, approve=False, fixes=None):
226
 
        from . import lp_propose
227
 
        tree, branch, relpath = controldir.ControlDir.open_containing_tree_or_branch(
228
 
            '.')
229
 
        if review is None:
230
 
            reviews = None
231
 
        else:
232
 
            reviews = []
233
 
            for review in review:
234
 
                if '=' in review:
235
 
                    reviews.append(review.split('=', 2))
236
 
                else:
237
 
                    reviews.append((review, ''))
238
 
            if submit_branch is None:
239
 
                submit_branch = branch.get_submit_branch()
240
 
        if submit_branch is None:
241
 
            target = None
242
 
        else:
243
 
            target = _mod_branch.Branch.open(submit_branch)
244
 
        proposer = lp_propose.Proposer(tree, branch, target, message,
245
 
                                       reviews, staging, approve=approve,
246
 
                                       fixes=fixes)
247
 
        proposer.check_proposal()
248
 
        proposer.create_proposal()
249
 
 
250
 
 
251
165
class cmd_lp_find_proposal(Command):
252
166
 
253
167
    __doc__ = """Find the proposal to merge this revision.
271
185
        from . import lp_api
272
186
        import webbrowser
273
187
        b = _mod_branch.Branch.open_containing('.')[0]
274
 
        pb = ui.ui_factory.nested_progress_bar()
275
 
        b.lock_read()
276
 
        try:
 
188
        with ui.ui_factory.nested_progress_bar() as pb, b.lock_read():
277
189
            if revision is None:
278
190
                revision_id = b.last_revision()
279
191
            else:
284
196
            trace.note(gettext('%d proposals(s) found.') % len(merged))
285
197
            for mp in merged:
286
198
                webbrowser.open(lp_api.canonical_url(mp))
287
 
        finally:
288
 
            b.unlock()
289
 
            pb.finished()
290
199
 
291
200
    def _find_proposals(self, revision_id, pb):
292
 
        from . import (lp_api, lp_registration)
 
201
        from launchpadlib import uris
 
202
        from . import lp_api
293
203
        # "devel" because branches.getMergeProposals is not part of 1.0 API.
294
 
        launchpad = lp_api.login(lp_registration.LaunchpadService(),
295
 
                                 version='devel')
 
204
        lp_base_url = uris.LPNET_SERVICE_ROOT
 
205
        launchpad = lp_api.connect_launchpad(lp_base_url, version='devel')
296
206
        pb.update(gettext('Finding proposals'))
297
207
        return list(launchpad.branches.getMergeProposals(
298
 
                    merged_revision=revision_id))
 
208
                    merged_revision=revision_id.decode('utf-8')))