Skip to content

Commit

Permalink
make gh-auth-alist useful
Browse files Browse the repository at this point in the history
  • Loading branch information
sigma committed Nov 27, 2013
1 parent a8363a1 commit f3171ca
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions gh-auth.el
Expand Up @@ -41,6 +41,13 @@

(defvar gh-auth-alist nil)

(defun gh-auth-remember (profile key value)
(let ((cell (assoc profile gh-auth-alist)))
(when (not cell)
(setq cell (cons profile nil))
(setq gh-auth-alist (append gh-auth-alist (list cell))))
(setcdr cell (plist-put (cdr cell) key value))))

(defun gh-auth-get-username ()
(let* ((profile (gh-profile-current-profile))
(user (or (plist-get (cdr (assoc profile gh-auth-alist)) :username)
Expand All @@ -49,7 +56,7 @@
(when (not user)
(setq user (read-string "GitHub username: "))
(gh-set-config "user" user))
(plist-put (cdr (assoc profile gh-auth-alist)) :username user)
(gh-auth-remember profile :username user)
user))

(defun gh-auth-get-password (&optional remember)
Expand All @@ -59,10 +66,9 @@
(gh-config "password"))))
(when (not pass)
(setq pass (read-passwd "GitHub password: "))
(when remember
(gh-set-config "password" pass)))
(gh-set-config "password" pass))
(when remember
(plist-put (cdr (assoc profile gh-auth-alist)) :password pass))
(gh-auth-remember profile :password pass))
pass))

(declare-function 'gh-oauth-auth-new "gh-oauth")
Expand All @@ -79,8 +85,8 @@
'(user repo gist)) :data)
:token))))
(setq token (or tok (read-string "GitHub OAuth token: ")))
(plist-put (cdr (assoc profile gh-auth-alist)) :token token)
(gh-set-config "oauth-token" token)))
(gh-auth-remember profile :token token)
token))

;;;###autoload
Expand Down

0 comments on commit f3171ca

Please sign in to comment.