/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: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2012 Canonical Ltd
 
1
# Copyright (C) 2006-2017 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
16
16
 
17
17
"""Launchpad plugin commands."""
18
18
 
19
 
from __future__ import absolute_import
20
 
 
21
 
from bzrlib import (
 
19
from ... import (
22
20
    branch as _mod_branch,
23
21
    controldir,
24
22
    trace,
25
23
    )
26
 
from bzrlib.commands import (
 
24
from ...commands import (
27
25
    Command,
28
26
    )
29
 
from bzrlib.errors import (
30
 
    BzrCommandError,
31
 
    InvalidURL,
32
 
    NoPublicBranch,
 
27
from ...errors import (
 
28
    CommandError,
33
29
    NotBranchError,
34
30
    )
35
 
from bzrlib.i18n import gettext
36
 
from bzrlib.option import (
 
31
from ...i18n import gettext
 
32
from ...option import (
37
33
    Option,
38
34
    ListOption,
39
35
    )
40
36
 
41
37
 
42
 
class cmd_register_branch(Command):
43
 
    __doc__ = """Register a branch with launchpad.net.
44
 
 
45
 
    This command lists a bzr branch in the directory of branches on
46
 
    launchpad.net.  Registration allows the branch to be associated with
47
 
    bugs or specifications.
48
 
 
49
 
    Before using this command you must register the project to which the
50
 
    branch belongs, and create an account for yourself on launchpad.net.
51
 
 
52
 
    arguments:
53
 
        public_url: The publicly visible url for the branch to register.
54
 
                    This must be an http or https url (which Launchpad can read
55
 
                    from to access the branch). Local file urls, SFTP urls, and
56
 
                    bzr+ssh urls will not work.
57
 
                    If no public_url is provided, bzr will use the configured
58
 
                    public_url if there is one for the current branch, and
59
 
                    otherwise error.
60
 
 
61
 
    example:
62
 
        bzr register-branch http://foo.com/bzr/fooproject.mine \\
63
 
                --project fooproject
64
 
    """
65
 
    takes_args = ['public_url?']
66
 
    takes_options = [
67
 
         Option('project',
68
 
                'Launchpad project short name to associate with the branch.',
69
 
                unicode),
70
 
         Option('product',
71
 
                'Launchpad product short name to associate with the branch.',
72
 
                unicode,
73
 
                hidden=True),
74
 
         Option('branch-name',
75
 
                'Short name for the branch; '
76
 
                'by default taken from the last component of the url.',
77
 
                unicode),
78
 
         Option('branch-title',
79
 
                'One-sentence description of the branch.',
80
 
                unicode),
81
 
         Option('branch-description',
82
 
                'Longer description of the purpose or contents of the branch.',
83
 
                unicode),
84
 
         Option('author',
85
 
                "Branch author's email address, if not yourself.",
86
 
                unicode),
87
 
         Option('link-bug',
88
 
                'The bug this branch fixes.',
89
 
                int),
90
 
         Option('dry-run',
91
 
                'Prepare the request but don\'t actually send it.')
92
 
        ]
93
 
 
94
 
 
95
 
    def run(self,
96
 
            public_url=None,
97
 
            project='',
98
 
            product=None,
99
 
            branch_name='',
100
 
            branch_title='',
101
 
            branch_description='',
102
 
            author='',
103
 
            link_bug=None,
104
 
            dry_run=False):
105
 
        from bzrlib.plugins.launchpad.lp_registration import (
106
 
            BranchRegistrationRequest, BranchBugLinkRequest,
107
 
            DryRunLaunchpadService, LaunchpadService)
108
 
        if public_url is None:
109
 
            try:
110
 
                b = _mod_branch.Branch.open_containing('.')[0]
111
 
            except NotBranchError:
112
 
                raise BzrCommandError(gettext(
113
 
                            'register-branch requires a public '
114
 
                            'branch url - see bzr help register-branch.'))
115
 
            public_url = b.get_public_branch()
116
 
            if public_url is None:
117
 
                raise NoPublicBranch(b)
118
 
        if product is not None:
119
 
            project = product
120
 
            trace.note(gettext(
121
 
                '--product is deprecated; please use --project.'))
122
 
 
123
 
 
124
 
        rego = BranchRegistrationRequest(branch_url=public_url,
125
 
                                         branch_name=branch_name,
126
 
                                         branch_title=branch_title,
127
 
                                         branch_description=branch_description,
128
 
                                         product_name=project,
129
 
                                         author_email=author,
130
 
                                         )
131
 
        linko = BranchBugLinkRequest(branch_url=public_url,
132
 
                                     bug_id=link_bug)
133
 
        if not dry_run:
134
 
            service = LaunchpadService()
135
 
            # This gives back the xmlrpc url that can be used for future
136
 
            # operations on the branch.  It's not so useful to print to the
137
 
            # user since they can't do anything with it from a web browser; it
138
 
            # might be nice for the server to tell us about an html url as
139
 
            # well.
140
 
        else:
141
 
            # Run on service entirely in memory
142
 
            service = DryRunLaunchpadService()
143
 
        service.gather_user_credentials()
144
 
        rego.submit(service)
145
 
        if link_bug:
146
 
            linko.submit(service)
147
 
        self.outf.write('Branch registered.\n')
148
 
 
149
 
 
150
38
class cmd_launchpad_open(Command):
151
39
    __doc__ = """Open a Launchpad branch page in your web browser."""
152
40
 
173
61
            yield branch_url
174
62
 
175
63
    def _get_web_url(self, service, location):
176
 
        from bzrlib.plugins.launchpad.lp_registration import (
 
64
        from .lp_registration import (
 
65
            InvalidURL,
177
66
            NotLaunchpadBranch)
178
67
        for branch_url in self._possible_locations(location):
179
68
            try:
183
72
        raise NotLaunchpadBranch(branch_url)
184
73
 
185
74
    def run(self, location=None, dry_run=False):
186
 
        from bzrlib.plugins.launchpad.lp_registration import (
 
75
        from .lp_registration import (
187
76
            LaunchpadService)
188
77
        if location is None:
189
78
            location = u'.'
191
80
        trace.note(gettext('Opening %s in web browser') % web_url)
192
81
        if not dry_run:
193
82
            import webbrowser   # this import should not be lazy
194
 
                                # otherwise bzr.exe lacks this module
 
83
            # otherwise brz.exe lacks this module
195
84
            webbrowser.open(web_url)
196
85
 
197
86
 
205
94
    :Examples:
206
95
      Show the Launchpad ID of the current user::
207
96
 
208
 
          bzr launchpad-login
 
97
          brz launchpad-login
209
98
 
210
99
      Set the Launchpad ID of the current user to 'bob'::
211
100
 
212
 
          bzr launchpad-login bob
 
101
          brz launchpad-login bob
213
102
    """
214
103
    aliases = ['lp-login']
215
104
    takes_args = ['name?']
221
110
 
222
111
    def run(self, name=None, no_check=False, verbose=False):
223
112
        # This is totally separate from any launchpadlib login system.
224
 
        from bzrlib.plugins.launchpad import account
 
113
        from . import account
225
114
        check_account = not no_check
226
115
 
227
116
        if name is None:
246
135
            account.set_lp_login(name)
247
136
            if verbose:
248
137
                self.outf.write(gettext("Launchpad user ID set to '%s'.\n") %
249
 
                                                                        (name,))
250
 
 
251
 
 
252
 
# XXX: cmd_launchpad_mirror is untested
253
 
class cmd_launchpad_mirror(Command):
254
 
    __doc__ = """Ask Launchpad to mirror a branch now."""
255
 
 
256
 
    aliases = ['lp-mirror']
257
 
    takes_args = ['location?']
258
 
 
259
 
    def run(self, location='.'):
260
 
        from bzrlib.plugins.launchpad import lp_api
261
 
        from bzrlib.plugins.launchpad.lp_registration import LaunchpadService
262
 
        branch, _ = _mod_branch.Branch.open_containing(location)
263
 
        service = LaunchpadService()
264
 
        launchpad = lp_api.login(service)
265
 
        lp_branch = lp_api.LaunchpadBranch.from_bzr(launchpad, branch,
266
 
                create_missing=False)
267
 
        lp_branch.lp.requestMirror()
268
 
 
269
 
 
270
 
class cmd_lp_propose_merge(Command):
271
 
    __doc__ = """Propose merging a branch on Launchpad.
272
 
 
273
 
    This will open your usual editor to provide the initial comment.  When it
274
 
    has created the proposal, it will open it in your default web browser.
275
 
 
276
 
    The branch will be proposed to merge into SUBMIT_BRANCH.  If SUBMIT_BRANCH
277
 
    is not supplied, the remembered submit branch will be used.  If no submit
278
 
    branch is remembered, the development focus will be used.
279
 
 
280
 
    By default, the SUBMIT_BRANCH's review team will be requested to review
281
 
    the merge proposal.  This can be overriden by specifying --review (-R).
282
 
    The parameter the launchpad account name of the desired reviewer.  This
283
 
    may optionally be followed by '=' and the review type.  For example:
284
 
 
285
 
      bzr lp-propose-merge --review jrandom --review review-team=qa
286
 
 
287
 
    This will propose a merge,  request "jrandom" to perform a review of
288
 
    unspecified type, and request "review-team" to perform a "qa" review.
 
138
                                (name,))
 
139
 
 
140
 
 
141
class cmd_launchpad_logout(Command):
 
142
    __doc__ = """Unset the Launchpad user ID.
 
143
 
 
144
    When communicating with Launchpad, some commands need to know your
 
145
    Launchpad user ID.  This command will log you out from Launchpad.
 
146
    This means that communication with Launchpad will happen over
 
147
    HTTPS, and will not require one of your SSH keys to be available.
289
148
    """
290
 
 
291
 
    takes_options = [Option('staging',
292
 
                            help='Propose the merge on staging.'),
293
 
                     Option('message', short_name='m', type=unicode,
294
 
                            help='Commit message.'),
295
 
                     Option('approve',
296
 
                            help=('Mark the proposal as approved immediately, '
297
 
                                  'setting the approved revision to tip.')),
298
 
                     Option('fixes', 'The bug this proposal fixes.', str),
299
 
                     ListOption('review', short_name='R', type=unicode,
300
 
                            help='Requested reviewer and optional type.')]
301
 
 
302
 
    takes_args = ['submit_branch?']
303
 
 
304
 
    aliases = ['lp-submit', 'lp-propose']
305
 
 
306
 
    def run(self, submit_branch=None, review=None, staging=False,
307
 
            message=None, approve=False, fixes=None):
308
 
        from bzrlib.plugins.launchpad import lp_propose
309
 
        tree, branch, relpath = controldir.ControlDir.open_containing_tree_or_branch(
310
 
            '.')
311
 
        if review is None:
312
 
            reviews = None
313
 
        else:
314
 
            reviews = []
315
 
            for review in review:
316
 
                if '=' in review:
317
 
                    reviews.append(review.split('=', 2))
318
 
                else:
319
 
                    reviews.append((review, ''))
320
 
            if submit_branch is None:
321
 
                submit_branch = branch.get_submit_branch()
322
 
        if submit_branch is None:
323
 
            target = None
324
 
        else:
325
 
            target = _mod_branch.Branch.open(submit_branch)
326
 
        proposer = lp_propose.Proposer(tree, branch, target, message,
327
 
                                       reviews, staging, approve=approve,
328
 
                                       fixes=fixes)
329
 
        proposer.check_proposal()
330
 
        proposer.create_proposal()
 
149
    aliases = ['lp-logout']
 
150
    takes_options = ['verbose']
 
151
 
 
152
    def run(self, verbose=False):
 
153
        from . import account
 
154
        old_username = account.get_lp_login()
 
155
        if old_username is None:
 
156
            self.outf.write(gettext('Not logged into Launchpad.\n'))
 
157
            return 1
 
158
        account.set_lp_login(None)
 
159
        if verbose:
 
160
            self.outf.write(gettext(
 
161
                "Launchpad user ID %s logged out.\n") %
 
162
                old_username)
331
163
 
332
164
 
333
165
class cmd_lp_find_proposal(Command):
343
175
 
344
176
    So, to find the merge proposal that reviewed line 1 of README::
345
177
 
346
 
      bzr lp-find-proposal -r mainline:annotate:README:1
 
178
      brz lp-find-proposal -r mainline:annotate:README:1
347
179
    """
348
180
 
349
181
    takes_options = ['revision']
350
182
 
351
183
    def run(self, revision=None):
352
 
        from bzrlib import ui
353
 
        from bzrlib.plugins.launchpad import lp_api
 
184
        from ... import ui
 
185
        from . import lp_api
354
186
        import webbrowser
355
187
        b = _mod_branch.Branch.open_containing('.')[0]
356
 
        pb = ui.ui_factory.nested_progress_bar()
357
 
        b.lock_read()
358
 
        try:
 
188
        with ui.ui_factory.nested_progress_bar() as pb, b.lock_read():
359
189
            if revision is None:
360
190
                revision_id = b.last_revision()
361
191
            else:
362
192
                revision_id = revision[0].as_revision_id(b)
363
193
            merged = self._find_proposals(revision_id, pb)
364
194
            if len(merged) == 0:
365
 
                raise BzrCommandError(gettext('No review found.'))
 
195
                raise CommandError(gettext('No review found.'))
366
196
            trace.note(gettext('%d proposals(s) found.') % len(merged))
367
197
            for mp in merged:
368
198
                webbrowser.open(lp_api.canonical_url(mp))
369
 
        finally:
370
 
            b.unlock()
371
 
            pb.finished()
372
199
 
373
200
    def _find_proposals(self, revision_id, pb):
374
 
        from bzrlib.plugins.launchpad import (lp_api, lp_registration)
 
201
        from launchpadlib import uris
 
202
        from . import lp_api
375
203
        # "devel" because branches.getMergeProposals is not part of 1.0 API.
376
 
        launchpad = lp_api.login(lp_registration.LaunchpadService(),
377
 
                                 version='devel')
 
204
        lp_base_url = uris.LPNET_SERVICE_ROOT
 
205
        launchpad = lp_api.connect_launchpad(lp_base_url, version='devel')
378
206
        pb.update(gettext('Finding proposals'))
379
207
        return list(launchpad.branches.getMergeProposals(
380
 
                    merged_revision=revision_id))
 
208
                    merged_revision=revision_id.decode('utf-8')))