/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-06-15 01:29:36 UTC
  • mfrom: (7490.40.4 work)
  • mto: (7490.40.19 work)
  • mto: This revision was merged to the branch mainline in revision 7516.
  • Revision ID: jelmer@jelmer.uk-20200615012936-1adqbu592y7lzmy8
Merge upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
238
238
            self.outf.write(gettext('Merge proposal: %s\n') % mp.url)
239
239
 
240
240
 
241
 
class cmd_github_login(Command):
242
 
    __doc__ = """Log into GitHub.
243
 
 
244
 
    When communicating with GitHub, some commands need to authenticate to
245
 
    GitHub.
246
 
    """
247
 
 
248
 
    takes_args = ['username?']
249
 
 
250
 
    def run(self, username=None):
251
 
        from github import Github, GithubException
252
 
        from breezy.config import AuthenticationConfig
253
 
        authconfig = AuthenticationConfig()
254
 
        if username is None:
255
 
            username = authconfig.get_user(
256
 
                'https', 'github.com', prompt=u'GitHub username', ask=True)
257
 
        password = authconfig.get_password('https', 'github.com', username)
258
 
        client = Github(username, password)
259
 
        user = client.get_user()
260
 
        try:
261
 
            authorization = user.create_authorization(
262
 
                scopes=['user', 'repo', 'delete_repo'], note='Breezy',
263
 
                note_url='https://github.com/breezy-team/breezy')
264
 
        except GithubException as e:
265
 
            errs = e.data.get('errors', [])
266
 
            if errs:
267
 
                err_code = errs[0].get('code')
268
 
                if err_code == u'already_exists':
269
 
                    raise errors.BzrCommandError('token already exists')
270
 
            raise errors.BzrCommandError(e.data['message'])
271
 
        # TODO(jelmer): This should really use something in
272
 
        # AuthenticationConfig
273
 
        from .github import store_github_token
274
 
        store_github_token(scheme='https', host='github.com',
275
 
                           token=authorization.token)
276
 
 
277
 
 
278
 
class cmd_gitlab_login(Command):
279
 
    __doc__ = """Log into a GitLab instance.
280
 
 
281
 
    This command takes a GitLab instance URL (e.g. https://gitlab.com)
282
 
    as well as an optional private token. Private tokens can be created via the
283
 
    web UI.
284
 
 
285
 
    :Examples:
286
 
 
287
 
      Log into GNOME's GitLab (prompts for a token):
288
 
 
289
 
         brz gitlab-login https://gitlab.gnome.org/
290
 
 
291
 
      Log into Debian's salsa, using a token created earlier:
292
 
 
293
 
         brz gitlab-login https://salsa.debian.org if4Theis6Eich7aef0zo
294
 
    """
295
 
 
296
 
    takes_args = ['url', 'private_token?']
297
 
 
298
 
    takes_options = [
299
 
        Option('name', help='Name for GitLab site in configuration.',
300
 
               type=str),
301
 
        Option('no-check',
302
 
               "Don't check that the token is valid."),
303
 
        ]
304
 
 
305
 
    def run(self, url, private_token=None, name=None, no_check=False):
306
 
        from breezy import ui
307
 
        from .gitlabs import store_gitlab_token
308
 
        if name is None:
309
 
            try:
310
 
                name = urlutils.parse_url(url)[3].split('.')[-2]
311
 
            except (ValueError, IndexError):
312
 
                raise errors.BzrCommandError(
313
 
                    'please specify a site name with --name')
314
 
        if private_token is None:
315
 
            note("Please visit %s to obtain a private token.",
316
 
                 urlutils.join(url, "profile/personal_access_tokens"))
317
 
            private_token = ui.ui_factory.get_password(u'Private token')
318
 
        if not no_check:
319
 
            from breezy.transport import get_transport
320
 
            from .gitlabs import GitLab
321
 
            GitLab(get_transport(url), private_token=private_token)
322
 
        store_gitlab_token(name=name, url=url, private_token=private_token)
323
 
 
324
 
 
325
241
class cmd_my_merge_proposals(Command):
326
242
    __doc__ = """List all merge proposals owned by the logged-in user.
327
243