/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-03-02 21:51:19 UTC
  • mfrom: (7268.12.3 probe-url)
  • Revision ID: breezy.the.bot@gmail.com-20190302215119-7lhcqje0t7xvkbfj
Split out a 'probe_from_url' method on Hoster.

Merged from https://code.launchpad.net/~jelmer/brz/probe-url/+merge/362951

Show diffs side-by-side

added added

removed removed

Lines of Context:
132
132
        self._pr.edit(state='closed')
133
133
 
134
134
 
135
 
def parse_github_url(branch):
136
 
    url = urlutils.split_segment_parameters(branch.user_url)[0]
 
135
def parse_github_url(url):
137
136
    (scheme, user, password, host, port, path) = urlutils.parse_url(
138
137
        url)
139
138
    if host != 'github.com':
141
140
    (owner, repo_name) = path.strip('/').split('/')
142
141
    if repo_name.endswith('.git'):
143
142
        repo_name = repo_name[:-4]
 
143
    return owner, repo_name
 
144
 
 
145
 
 
146
def parse_github_branch_url(branch):
 
147
    url = urlutils.split_segment_parameters(branch.user_url)[0]
 
148
    owner, repo_name = parse_github_url(url)
144
149
    return owner, repo_name, branch.name
145
150
 
146
151
 
186
191
                        owner=None, revision_id=None, overwrite=False,
187
192
                        allow_lossy=True):
188
193
        import github
189
 
        base_owner, base_project, base_branch_name = parse_github_url(base_branch)
 
194
        base_owner, base_project, base_branch_name = parse_github_branch_url(base_branch)
190
195
        base_repo = self.gh.get_repo('%s/%s' % (base_owner, base_project))
191
196
        if owner is None:
192
197
            owner = self.gh.get_user().login
222
227
 
223
228
    @convert_github_error
224
229
    def get_push_url(self, branch):
225
 
        owner, project, branch_name = parse_github_url(branch)
 
230
        owner, project, branch_name = parse_github_branch_url(branch)
226
231
        repo = self.gh.get_repo('%s/%s' % (owner, project))
227
232
        return github_url_to_bzr_url(repo.ssh_url, branch_name)
228
233
 
229
234
    @convert_github_error
230
235
    def get_derived_branch(self, base_branch, name, project=None, owner=None):
231
236
        import github
232
 
        base_owner, base_project, base_branch_name = parse_github_url(base_branch)
 
237
        base_owner, base_project, base_branch_name = parse_github_branch_url(base_branch)
233
238
        base_repo = self.gh.get_repo('%s/%s' % (base_owner, base_project))
234
239
        if owner is None:
235
240
            owner = self.gh.get_user().login
249
254
    @convert_github_error
250
255
    def iter_proposals(self, source_branch, target_branch, status='open'):
251
256
        (source_owner, source_repo_name, source_branch_name) = (
252
 
            parse_github_url(source_branch))
 
257
            parse_github_branch_url(source_branch))
253
258
        (target_owner, target_repo_name, target_branch_name) = (
254
 
            parse_github_url(target_branch))
 
259
            parse_github_branch_url(target_branch))
255
260
        target_repo = self.gh.get_repo(
256
261
            "%s/%s" % (target_owner, target_repo_name))
257
262
        state = {
277
282
 
278
283
    def hosts(self, branch):
279
284
        try:
280
 
            parse_github_url(branch)
 
285
            parse_github_branch_url(branch)
281
286
        except NotGitHubUrl:
282
287
            return False
283
288
        else:
284
289
            return True
285
290
 
286
291
    @classmethod
287
 
    def probe(cls, branch):
 
292
    def probe_from_url(cls, url):
288
293
        try:
289
 
            parse_github_url(branch)
 
294
            parse_github_url(url)
290
295
        except NotGitHubUrl:
291
 
            raise UnsupportedHoster(branch)
 
296
            raise UnsupportedHoster(url)
292
297
        return cls()
293
298
 
294
299
    @classmethod
319
324
        self.source_branch = source_branch
320
325
        self.target_branch = target_branch
321
326
        (self.target_owner, self.target_repo_name, self.target_branch_name) = (
322
 
            parse_github_url(self.target_branch))
 
327
            parse_github_branch_url(self.target_branch))
323
328
        (self.source_owner, self.source_repo_name, self.source_branch_name) = (
324
 
            parse_github_url(self.source_branch))
 
329
            parse_github_branch_url(self.source_branch))
325
330
 
326
331
    def get_infotext(self):
327
332
        """Determine the initial comment for the merge proposal."""