summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeandro Lucarella <leandro.lucarella@sociomantic.com>2015-05-13 20:29:46 +0200
committerMihails Strasuns <mihails.strasuns.contractor@sociomantic.com>2015-05-16 16:30:13 +0300
commite5b5b761a8ae9c0329db1b7f2d58989c683d9a01 (patch)
treee7045ca5fecb9faabd8fcaafe67e36c125e11884
parent6be31ddf792fe6861b41cd594a7bcc4049991d50 (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-xgit-hub32
1 files changed, 22 insertions, 10 deletions
diff --git a/git-hub b/git-hub
index 5fd0f14..031a089 100755
--- a/git-hub
+++ b/git-hub
@@ -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)