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

  • Committer: Jelmer Vernooij
  • Date: 2020-08-10 15:00:17 UTC
  • mfrom: (7490.40.99 work)
  • mto: This revision was merged to the branch mainline in revision 7521.
  • Revision ID: jelmer@jelmer.uk-20200810150017-vs7xnrd1vat4iktg
Merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Helper functions for proposing merges."""
18
18
 
19
 
from __future__ import absolute_import
20
 
 
21
19
from . import (
22
20
    errors,
23
21
    hooks,
99
97
        self.hoster = hoster
100
98
 
101
99
 
 
100
class SourceNotDerivedFromTarget(errors.BzrError):
 
101
    """Source branch is not derived from target branch."""
 
102
 
 
103
    _fmt = ("Source %(source_branch)r not derived from "
 
104
            "target %(target_branch)r.")
 
105
 
 
106
    def __init__(self, source_branch, target_branch):
 
107
        errors.BzrError.__init__(
 
108
            self, source_branch=source_branch,
 
109
            target_branch=target_branch)
 
110
 
 
111
 
102
112
class MergeProposal(object):
103
113
    """A merge proposal.
104
114
 
240
250
    # proposals?
241
251
    supports_merge_proposal_labels = None
242
252
 
 
253
    @property
 
254
    def name(self):
 
255
        """Name of this instance."""
 
256
        return "%s at %s" % (type(self).__name__, self.base_url)
 
257
 
243
258
    # Does this hoster support suggesting a commit message in the
244
259
    # merge proposal?
245
260
    supports_merge_proposal_commit_message = None
266
281
        :raise HosterLoginRequired: Action requires a hoster login, but none is
267
282
            known.
268
283
        """
269
 
        raise NotImplementedError(self.publish)
 
284
        raise NotImplementedError(self.publish_derived)
270
285
 
271
286
    def get_derived_branch(self, base_branch, name, project=None, owner=None):
272
287
        """Get a derived branch ('a fork').
354
369
        """
355
370
        raise NotImplementedError(cls.iter_instances)
356
371
 
 
372
    def get_current_user(self):
 
373
        """Retrieve the name of the currently logged in user.
 
374
 
 
375
        :return: Username or None if not logged in
 
376
        """
 
377
        raise NotImplementedError(self.get_current_user)
 
378
 
 
379
    def get_user_url(self, user):
 
380
        """Rerieve the web URL for a user."""
 
381
        raise NotImplementedError(self.get_user_url)
 
382
 
357
383
 
358
384
def determine_title(description):
359
385
    """Determine the title for a merge proposal based on full description."""
384
410
    raise UnsupportedHoster(branch)
385
411
 
386
412
 
 
413
def iter_hoster_instances():
 
414
    """Iterate over all known hoster instances.
 
415
 
 
416
    :return: Iterator over Hoster instances
 
417
    """
 
418
    for name, hoster_cls in hosters.items():
 
419
        for instance in hoster_cls.iter_instances():
 
420
            yield instance
 
421
 
 
422
 
387
423
def get_proposal_by_url(url):
388
424
    """Get the proposal object associated with a URL.
389
425
 
391
427
    :raise UnsupportedHoster: if there is no hoster that supports the URL
392
428
    :return: A `MergeProposal` object
393
429
    """
394
 
    for name, hoster_cls in hosters.items():
395
 
        for instance in hoster_cls.iter_instances():
396
 
            try:
397
 
                return instance.get_proposal_by_url(url)
398
 
            except UnsupportedHoster:
399
 
                pass
 
430
    for instance in iter_hoster_instances():
 
431
        try:
 
432
            return instance.get_proposal_by_url(url)
 
433
        except UnsupportedHoster:
 
434
            pass
400
435
    raise UnsupportedHoster(url)
401
436
 
402
437