diff options
author | Leandro Lucarella <leandro.lucarella@sociomantic.com> | 2015-05-13 20:29:46 +0200 |
---|---|---|
committer | Mihails Strasuns <mihails.strasuns.contractor@sociomantic.com> | 2015-05-16 16:30:13 +0300 |
commit | e5b5b761a8ae9c0329db1b7f2d58989c683d9a01 (patch) | |
tree | e7045ca5fecb9faabd8fcaafe67e36c125e11884 | |
parent | 6be31ddf792fe6861b41cd594a7bcc4049991d50 (diff) |
setup: Ask the user for another note if the current is taken
The GitHub API changed, and it doesn't return the OAuth token anymore.
If a previous note exists, now the user is asked for a new name to
create a new token. If no new name is specified, the setup command is
cancelled. A tip is included to the user in case they want to regenerate
the token of the offered note.
-rwxr-xr-x | git-hub | 32 |
1 files changed, 22 insertions, 10 deletions
@@ -684,17 +684,29 @@ class SetupCmd (object): proj = config.forkrepo.split('/', 1)[1] note += ' (%s)' % proj - infof("Looking for GitHub authorization tokens...") - auths = dict([(a['note'], a) + while True: + infof("Looking for GitHub authorization token...") + auths = dict([(a['note'], a) for a in req.get('/authorizations')]) - if note in auths: - auth = auths[note] - infof("Reusing existing token '{}' (id: {})", note, - auth['id']) - else: - infof("Creating auth token '{}'", note) - auth = req.post('/authorizations', note=note, - scopes=['user', 'repo']) + + if note not in auths: + break + + errf("The OAuth token with name '{}' already exists.", + note) + infof("If you want to create a new one, enter a " + "name for it. Otherwise you can go to " + "https://github.com/settings/tokens to " + "regenerate or delete the token '{}'", note) + note = raw_input("Enter a new token name (an empty " + "name cancels the setup): ") + + if not note: + sys.exit(0) + + infof("Creating auth token '{}'", note) + auth = req.post('/authorizations', note=note, + scopes=['user', 'repo']) set_config = lambda k, v: git_config(k, value=v, opts=args.opts) |