140
137
help='Use the hoster.',
141
138
lazy_registry=('breezy.plugins.propose.propose', 'hosters')),
142
ListOption('reviewers', short_name='R', type=text_type,
139
ListOption('reviewers', short_name='R', type=str,
143
140
help='Requested reviewers.'),
144
141
Option('name', help='Name of the new remote branch.', type=str),
145
142
Option('description', help='Description of the change.', type=str),
149
146
'commit-message',
150
147
help='Set commit message for merge, if supported', type=str),
151
ListOption('labels', short_name='l', type=text_type,
148
ListOption('labels', short_name='l', type=str,
152
149
help='Labels to apply.'),
153
150
Option('no-allow-lossy',
154
151
help='Allow fallback to lossy push, if necessary.'),
238
235
self.outf.write(gettext('Merge proposal: %s\n') % mp.url)
241
class cmd_github_login(Command):
242
__doc__ = """Log into GitHub.
244
When communicating with GitHub, some commands need to authenticate to
248
takes_args = ['username?']
250
def run(self, username=None):
251
from github import Github, GithubException
252
from breezy.config import AuthenticationConfig
253
authconfig = AuthenticationConfig()
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()
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', [])
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)
278
class cmd_gitlab_login(Command):
279
__doc__ = """Log into a GitLab instance.
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
287
Log into GNOME's GitLab (prompts for a token):
289
brz gitlab-login https://gitlab.gnome.org/
291
Log into Debian's salsa, using a token created earlier:
293
brz gitlab-login https://salsa.debian.org if4Theis6Eich7aef0zo
296
takes_args = ['url', 'private_token?']
299
Option('name', help='Name for GitLab site in configuration.',
302
"Don't check that the token is valid."),
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
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')
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)
325
238
class cmd_my_merge_proposals(Command):
326
239
__doc__ = """List all merge proposals owned by the logged-in user.