1
# Copyright (C) 2020 Jelmer Vernooij <jelmer@jelmer.uk>
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.
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.
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
17
"""GitLab command implementations."""
19
from __future__ import absolute_import
25
from ...commands import Command
26
from ...option import (
29
from ...trace import note
32
class cmd_gitlab_login(Command):
33
__doc__ = """Log into a GitLab instance.
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
41
Log into GNOME's GitLab (prompts for a token):
43
brz gitlab-login https://gitlab.gnome.org/
45
Log into Debian's salsa, using a token created earlier:
47
brz gitlab-login https://salsa.debian.org if4Theis6Eich7aef0zo
50
takes_args = ['url', 'private_token?']
53
Option('name', help='Name for GitLab site in configuration.',
56
"Don't check that the token is valid."),
59
def run(self, url, private_token=None, name=None, no_check=False):
61
from .hoster import store_gitlab_token
64
name = urlutils.parse_url(url)[3].split('.')[-2]
65
except (ValueError, IndexError):
66
raise errors.BzrCommandError(
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')
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)