/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/propose/cmds.py

  • Committer: Jelmer Vernooij
  • Date: 2020-07-05 12:50:01 UTC
  • mfrom: (7490.40.46 work)
  • mto: (7490.40.48 work)
  • mto: This revision was merged to the branch mainline in revision 7519.
  • Revision ID: jelmer@jelmer.uk-20200705125001-7s3vo0p55szbbws7
Merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Propose command implementations."""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
from io import StringIO
20
22
 
21
23
from ... import (
34
36
    Option,
35
37
    RegistryOption,
36
38
    )
37
 
from ...trace import note, warning
 
39
from ...sixish import text_type
 
40
from ...trace import note
38
41
from ... import (
39
42
    propose as _mod_propose,
40
43
    )
143
146
        RegistryOption(
144
147
            'hoster',
145
148
            help='Use the hoster.',
146
 
            lazy_registry=('breezy.propose', 'hosters')),
147
 
        ListOption('reviewers', short_name='R', type=str,
 
149
            lazy_registry=('breezy.plugins.propose.propose', 'hosters')),
 
150
        ListOption('reviewers', short_name='R', type=text_type,
148
151
                   help='Requested reviewers.'),
149
152
        Option('name', help='Name of the new remote branch.', type=str),
150
153
        Option('description', help='Description of the change.', type=str),
153
156
        Option(
154
157
            'commit-message',
155
158
            help='Set commit message for merge, if supported', type=str),
156
 
        ListOption('labels', short_name='l', type=str,
 
159
        ListOption('labels', short_name='l', type=text_type,
157
160
                   help='Labels to apply.'),
158
161
        Option('no-allow-lossy',
159
162
               help='Allow fallback to lossy push, if necessary.'),
161
164
               help='Allow collaboration from target branch maintainer(s)'),
162
165
        Option('allow-empty',
163
166
               help='Do not prevent empty merge proposals.'),
164
 
        Option('overwrite', help="Overwrite existing commits."),
165
167
        ]
166
168
    takes_args = ['submit_branch?']
167
169
 
170
172
    def run(self, submit_branch=None, directory='.', hoster=None,
171
173
            reviewers=None, name=None, no_allow_lossy=False, description=None,
172
174
            labels=None, prerequisite=None, commit_message=None, wip=False,
173
 
            allow_collaboration=False, allow_empty=False, overwrite=False):
 
175
            allow_collaboration=False, allow_empty=False):
174
176
        tree, branch, relpath = (
175
177
            controldir.ControlDir.open_containing_tree_or_branch(directory))
176
178
        if submit_branch is None:
190
192
        if name is None:
191
193
            name = branch_name(branch)
192
194
        remote_branch, public_branch_url = hoster.publish_derived(
193
 
            branch, target, name=name, allow_lossy=not no_allow_lossy,
194
 
            overwrite=overwrite)
 
195
            branch, target, name=name, allow_lossy=not no_allow_lossy)
195
196
        branch.set_push_location(remote_branch.user_url)
196
197
        branch.set_submit_branch(target.user_url)
197
198
        note(gettext('Published branch to %s') % public_branch_url)
255
256
 
256
257
    hidden = True
257
258
 
258
 
    takes_args = ['base-url?']
259
259
    takes_options = [
260
260
        'verbose',
261
261
        RegistryOption.from_kwargs(
267
267
            all='All merge proposals',
268
268
            open='Open merge proposals',
269
269
            merged='Merged merge proposals',
270
 
            closed='Closed merge proposals'),
271
 
        RegistryOption(
272
 
            'hoster',
273
 
            help='Use the hoster.',
274
 
            lazy_registry=('breezy.propose', 'hosters')),
275
 
        ]
276
 
 
277
 
    def run(self, status='open', verbose=False, hoster=None, base_url=None):
278
 
 
279
 
        for instance in _mod_propose.iter_hoster_instances(hoster=hoster):
280
 
            if base_url is not None and instance.base_url != base_url:
281
 
                continue
282
 
            try:
 
270
            closed='Closed merge proposals')]
 
271
 
 
272
    def run(self, status='open', verbose=False):
 
273
        for name, hoster_cls in _mod_propose.hosters.items():
 
274
            for instance in hoster_cls.iter_instances():
283
275
                for mp in instance.iter_my_proposals(status=status):
284
276
                    self.outf.write('%s\n' % mp.url)
285
277
                    if verbose:
286
 
                        source_branch_url = mp.get_source_branch_url()
287
 
                        if source_branch_url:
288
 
                            self.outf.write(
289
 
                                '(Merging %s into %s)\n' %
290
 
                                (source_branch_url,
291
 
                                 mp.get_target_branch_url()))
292
 
                        else:
293
 
                            self.outf.write(
294
 
                                '(Merging into %s)\n' %
295
 
                                mp.get_target_branch_url())
 
278
                        self.outf.write(
 
279
                            '(Merging %s into %s)\n' %
 
280
                            (mp.get_source_branch_url(),
 
281
                             mp.get_target_branch_url()))
296
282
                        description = mp.get_description()
297
283
                        if description:
298
284
                            self.outf.writelines(
299
285
                                ['\t%s\n' % l
300
286
                                 for l in description.splitlines()])
301
287
                        self.outf.write('\n')
302
 
            except _mod_propose.HosterLoginRequired as e:
303
 
                warning('Skipping %r, login required.', instance)
304
288
 
305
289
 
306
290
class cmd_land_merge_proposal(Command):
313
297
    def run(self, url, message=None):
314
298
        proposal = _mod_propose.get_proposal_by_url(url)
315
299
        proposal.merge(commit_message=message)
316
 
 
317
 
 
318
 
class cmd_hosters(Command):
319
 
    __doc__ = """List all known hosting sites and user details."""
320
 
 
321
 
    hidden = True
322
 
 
323
 
    def run(self):
324
 
        for instance in _mod_propose.iter_hoster_instances():
325
 
            current_user = instance.get_current_user()
326
 
            if current_user is not None:
327
 
                current_user_url = instance.get_user_url(current_user)
328
 
                if current_user_url is not None:
329
 
                    self.outf.write(
330
 
                        gettext('%s (%s) - user: %s (%s)\n') % (
331
 
                            instance.name, instance.base_url,
332
 
                            current_user, current_user_url))
333
 
                else:
334
 
                    self.outf.write(
335
 
                        gettext('%s (%s) - user: %s\n') % (
336
 
                            instance.name, instance.base_url,
337
 
                            current_user))
338
 
            else:
339
 
                self.outf.write(
340
 
                    gettext('%s (%s) - not logged in\n') % (
341
 
                        instance.name, instance.base_url))