Browse files

make use of the new profile feature

  • Loading branch information...
1 parent 4ba53ad commit 4521dc2c614b37dfb8cb0272cb12830719509641 @sigma committed Mar 13, 2013
Showing with 37 additions and 16 deletions.
  1. +6 −1 gh-api.el
  2. +19 −13 gh-auth.el
  3. +12 −2 gh-common.el
@@ -33,6 +33,8 @@
(require 'eieio)
(require 'json)
+(require 'gh-profile)
(require 'gh-url)
(require 'gh-auth)
(require 'gh-cache)
@@ -97,7 +99,10 @@
:group 'gh-api)
(defmethod constructor :static ((api gh-api-v3) newname &rest args)
- (let ((obj (call-next-method)))
+ (let ((obj (call-next-method))
+ (gh-profile-current-profile (or gh-profile-current-profile
+ gh-profile-default-profile)))
+ (oset obj :base (gh-profile-url))
(gh-api-set-default-auth obj
(or (oref obj :auth)
(funcall gh-api-v3-authenticator "auth")))
@@ -32,48 +32,54 @@
(require 'eieio)
+(require 'gh-profile)
(require 'gh-common)
(defgroup gh-auth nil
"Github authentication."
:group 'gh)
-(defvar gh-auth-username nil)
-(defvar gh-auth-password nil)
-(defvar gh-auth-oauth-token nil)
+(defvar gh-auth-alist nil)
(defun gh-auth-get-username ()
- (let ((user (or gh-auth-username
- (setq gh-auth-username (gh-config "user")))))
+ (let* ((profile (gh-profile-current-profile))
+ (user (or (plist-get (cdr (assoc profile gh-auth-alist)) :username)
+ (plist-get (cdr (assoc profile gh-profile-alist)) :username)
+ (gh-config "user"))))
(when (not user)
(setq user (read-string "GitHub username: "))
- (setq gh-auth-username user)
(gh-set-config "user" user))
+ (plist-put (cdr (assoc profile gh-auth-alist)) :username user)
-(defun gh-auth-get-password (remember)
- (let ((pass (or gh-auth-password
- (setq gh-auth-password (gh-config "password")))))
+(defun gh-auth-get-password (&optional remember)
+ (let* ((profile (gh-profile-current-profile))
+ (pass (or (plist-get (cdr (assoc profile gh-auth-alist)) :password)
+ (plist-get (cdr (assoc profile gh-profile-alist)) :password)
+ (gh-config "password"))))
(when (not pass)
(setq pass (read-passwd "GitHub password: "))
(when remember
- (setq gh-auth-password pass)
(gh-set-config "password" pass)))
+ (when remember
+ (plist-put (cdr (assoc profile gh-auth-alist)) :password pass))
(declare-function 'gh-oauth-auth-new "gh-oauth")
(defun gh-auth-get-oauth-token ()
- (let ((token (or gh-auth-oauth-token
- (setq gh-auth-oauth-token (gh-config "oauth-token")))))
+ (let* ((profile (gh-profile-current-profile))
+ (token (or (plist-get (cdr (assoc profile gh-auth-alist)) :token)
+ (plist-get (cdr (assoc profile gh-profile-alist)) :token)
+ (gh-config "oauth-token"))))
(when (not token)
(let* ((api (make-instance 'gh-oauth-api))
(tok (and (fboundp 'gh-oauth-auth-new)
(oref (oref (funcall 'gh-oauth-auth-new api
'(user repo gist)) :data)
(setq token (or tok (read-string "GitHub OAuth token: ")))
- (setq gh-auth-oauth-token token)
+ (plist-put (cdr (assoc profile gh-auth-alist)) :token token)
(gh-set-config "oauth-token" token)))
@@ -32,6 +32,8 @@
(require 'eieio)
+(require 'gh-profile)
(defgroup gh nil
"Github API client libraries."
:group 'applications)
@@ -77,20 +79,28 @@
(defun gh-read (obj field)
(cdr (assoc field obj)))
+(defun gh-namespaced-key (key)
+ (let ((profile (gh-profile-current-profile)))
+ (concat "github."
+ (if (string= profile gh-profile-default-profile)
+ ""
+ (concat profile "."))
+ key)))
(defun gh-config (key)
"Returns a GitHub specific value from the global Git config."
(let ((strip (lambda (string)
(if (> (length string) 0)
(substring string 0 (- (length string) 1)))))
(git (executable-find "git")))
(funcall strip (shell-command-to-string
- (concat git " config github." key)))))
+ (concat git " config " (gh-namespaced-key key))))))
(defun gh-set-config (key value)
"Sets a GitHub specific value to the global Git config."
(let ((git (executable-find "git")))
- (concat git " config --global github." key " " value))))
+ (concat git " config --global " (gh-namespaced-key key) " " value))))
(provide 'gh-common)
;;; gh-common.el ends here

0 comments on commit 4521dc2

Please sign in to comment.