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

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2019-02-14 04:35:05 UTC
  • mfrom: (7268.8.2 credentials-error)
  • Revision ID: breezy.the.bot@gmail.com-20190214043505-rhoijzdtilj8pcq5
Raise a clearer error when not logged into e.g. GitHub.

Merged from https://code.launchpad.net/~jelmer/brz/credentials-error/+merge/362950

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
from .propose import (
24
24
    Hoster,
 
25
    HosterLoginRequired,
25
26
    MergeProposal,
26
27
    MergeProposalBuilder,
27
28
    MergeProposalExists,
74
75
        self.url = url
75
76
 
76
77
 
 
78
class GitHubLoginRequired(HosterLoginRequired):
 
79
 
 
80
    _fmt = "Action requires GitHub login."
 
81
 
 
82
 
77
83
def connect_github():
78
84
    """Connect to GitHub.
79
85
    """
145
151
        git_url_to_bzr_url(url), {"branch": branch_name})
146
152
 
147
153
 
 
154
def convert_github_error(fn):
 
155
    def convert(self, *args, **kwargs):
 
156
        import github
 
157
        try:
 
158
            return fn(self, *args, **kwargs)
 
159
        except github.GithubException as e:
 
160
            if e.args[0] == 401:
 
161
                raise GitHubLoginRequired(self)
 
162
            raise
 
163
    return convert
 
164
 
 
165
 
148
166
class GitHub(Hoster):
149
167
 
150
168
    name = 'github'
163
181
    def __init__(self):
164
182
        self.gh = connect_github()
165
183
 
 
184
    @convert_github_error
166
185
    def publish_derived(self, local_branch, base_branch, name, project=None,
167
186
                        owner=None, revision_id=None, overwrite=False,
168
187
                        allow_lossy=True):
201
220
        return push_result.target_branch, github_url_to_bzr_url(
202
221
            remote_repo.html_url, name)
203
222
 
 
223
    @convert_github_error
204
224
    def get_push_url(self, branch):
205
225
        owner, project, branch_name = parse_github_url(branch)
206
226
        repo = self.gh.get_repo('%s/%s' % (owner, project))
207
227
        return github_url_to_bzr_url(repo.ssh_url, branch_name)
208
228
 
 
229
    @convert_github_error
209
230
    def get_derived_branch(self, base_branch, name, project=None, owner=None):
210
231
        import github
211
232
        base_owner, base_project, base_branch_name = parse_github_url(base_branch)
221
242
        except github.UnknownObjectException:
222
243
            raise errors.NotBranchError('https://github.com/%s/%s' % (owner, project))
223
244
 
 
245
    @convert_github_error
224
246
    def get_proposer(self, source_branch, target_branch):
225
247
        return GitHubMergeProposalBuilder(self.gh, source_branch, target_branch)
226
248
 
 
249
    @convert_github_error
227
250
    def iter_proposals(self, source_branch, target_branch, status='open'):
228
251
        (source_owner, source_repo_name, source_branch_name) = (
229
252
            parse_github_url(source_branch))
272
295
    def iter_instances(cls):
273
296
        yield cls()
274
297
 
 
298
    @convert_github_error
275
299
    def iter_my_proposals(self, status='open'):
276
300
        query = ['is:pr']
277
301
        if status == 'open':