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

  • Committer: Jelmer Vernooij
  • Date: 2017-07-23 22:06:41 UTC
  • mfrom: (6738 trunk)
  • mto: This revision was merged to the branch mainline in revision 6739.
  • Revision ID: jelmer@jelmer.uk-20170723220641-69eczax9bmv8d6kk
Merge trunk, address review comments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2020 Jelmer Vernooij <jelmer@jelmer.uk>
2
 
#
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
"""GitLab command implementations."""
18
 
 
19
 
from __future__ import absolute_import
20
 
 
21
 
from ... import (
22
 
    errors,
23
 
    urlutils,
24
 
    )
25
 
from ...commands import Command
26
 
from ...option import (
27
 
    Option,
28
 
    )
29
 
from ...trace import note
30
 
 
31
 
 
32
 
class cmd_gitlab_login(Command):
33
 
    __doc__ = """Log into a GitLab instance.
34
 
 
35
 
    This command takes a GitLab instance URL (e.g. https://gitlab.com)
36
 
    as well as an optional private token. Private tokens can be created via the
37
 
    web UI.
38
 
 
39
 
    :Examples:
40
 
 
41
 
      Log into GNOME's GitLab (prompts for a token):
42
 
 
43
 
         brz gitlab-login https://gitlab.gnome.org/
44
 
 
45
 
      Log into Debian's salsa, using a token created earlier:
46
 
 
47
 
         brz gitlab-login https://salsa.debian.org if4Theis6Eich7aef0zo
48
 
    """
49
 
 
50
 
    takes_args = ['url', 'private_token?']
51
 
 
52
 
    takes_options = [
53
 
        Option('name', help='Name for GitLab site in configuration.',
54
 
               type=str),
55
 
        Option('no-check',
56
 
               "Don't check that the token is valid."),
57
 
        ]
58
 
 
59
 
    def run(self, url, private_token=None, name=None, no_check=False):
60
 
        from breezy import ui
61
 
        from .hoster import store_gitlab_token
62
 
        if name is None:
63
 
            try:
64
 
                name = urlutils.parse_url(url)[3].split('.')[-2]
65
 
            except (ValueError, IndexError):
66
 
                raise errors.CommandError(
67
 
                    'please specify a site name with --name')
68
 
        if private_token is None:
69
 
            note("Please visit %s to obtain a private token.",
70
 
                 urlutils.join(url, "profile/personal_access_tokens"))
71
 
            private_token = ui.ui_factory.get_password(u'Private token')
72
 
        if not no_check:
73
 
            from breezy.transport import get_transport
74
 
            from .hoster import GitLab
75
 
            GitLab(get_transport(url), private_token=private_token)
76
 
        store_gitlab_token(name=name, url=url, private_token=private_token)