Update magithub

This commit is contained in:
Gergely Polonkai 2016-10-14 12:04:53 +02:00
parent 78f6ebc3d3
commit 5feea2e7f0
7 changed files with 89 additions and 42 deletions

View File

@ -5,7 +5,7 @@
;;;### (autoloads nil nil ("magithub-cache.el" "magithub-ci.el" "magithub-core.el" ;;;### (autoloads nil nil ("magithub-cache.el" "magithub-ci.el" "magithub-core.el"
;;;;;; "magithub-issue.el" "magithub-pkg.el" "magithub.el") (22528 ;;;;;; "magithub-issue.el" "magithub-pkg.el" "magithub.el") (22528
;;;;;; 31239 328273 102000)) ;;;;;; 44286 378835 655000))
;;;*** ;;;***

View File

@ -79,14 +79,12 @@ If magithub.ci.enabled is not set, CI is considered to be enabled."
(defun magithub-ci-status () (defun magithub-ci-status ()
"One of 'success, 'error, 'failure, 'pending, or 'no-status." "One of 'success, 'error, 'failure, 'pending, or 'no-status."
(let ((same-commit (unless (string-equal (magit-rev-parse "HEAD")
(string-equal (magit-rev-parse "HEAD") (magithub-ci-status-current-commit))
(magithub-ci-status-current-commit)))) (magithub-cache-clear (magithub-repo-id) :ci-status))
(unless same-commit (let ((cached-val (magithub-cache-value (magithub-repo-id) :ci-status)))
(magithub-cache-clear (magithub-repo-id) :ci-status)) (if (and (consp cached-val) (eq (plist-get (car cached-val) :status) 'success))
(if (eq (magithub-cache-value (magithub-repo-id) :ci-status) cached-val
'success)
'success
(magithub-cache (magithub-repo-id) :ci-status (magithub-cache (magithub-repo-id) :ci-status
'(magithub-ci-status--internal))))) '(magithub-ci-status--internal)))))
@ -96,42 +94,32 @@ If magithub.ci.enabled is not set, CI is considered to be enabled."
(if new-value (apply #'magit-set new-value keys) (if new-value (apply #'magit-set new-value keys)
(apply #'magit-get keys)))) (apply #'magit-get keys))))
(defun magithub-ci-update-urls (statuses)
"Updates `magithub-ci-urls' according to STATUSES.
See also `magithub-repo-id'."
(let* ((id (magithub-repo-id))
(repo-urls (assoc id magithub-ci-urls))
(urls (mapcar (lambda (s) (plist-get s :url)) statuses)))
(if repo-urls (setcdr repo-urls urls)
(add-to-list 'magithub-ci-urls (cons id urls))
urls)))
(defun magithub-ci-status--parse-2.2.8 (output) (defun magithub-ci-status--parse-2.2.8 (output)
"Backwards compatibility for old versions of hub. "Backwards compatibility for old versions of hub.
See `magithub-ci-status--parse'." See `magithub-ci-status--parse'."
(-when-let (matches (cdr (s-match (rx bos (group (+ (any alpha space))) (-when-let (matches (cdr (s-match (rx bos (group (+ (any alpha space)))
(? ": " (group (+ (not (any " "))))) eos) (? ": " (group (+ (not (any " "))))) eos)
output))) output)))
(let ((status (list :status (intern (replace-regexp-in-string "\s" "-" (car matches))) (list (list :status (intern (replace-regexp-in-string
:url (cadr matches)))) "\s" "-" (car matches)))
(magithub-ci-update-urls (list status)) :url (cadr matches)))))
status)))
(defun magithub-ci-status--internal (&optional for-commit) (defun magithub-ci-status--internal (&optional for-commit)
"One of 'success, 'error, 'failure, 'pending, or 'no-status." "One of 'success, 'error, 'failure, 'pending, or 'no-status."
(let* ((current-commit (magit-rev-parse "HEAD")) (let* ((current-commit (magit-rev-parse "HEAD"))
(last-commit (or for-commit current-commit)) (last-commit (or for-commit current-commit))
(output (magithub--command-output "ci-status" `("-v" ,last-commit)))) (output (magithub--command-output "ci-status" `("-v" ,last-commit))))
(-if-let (check (if (magithub-hub-version-at-least "2.3") (-if-let (checks (if (magithub-hub-version-at-least "2.3")
(car (magithub-ci-status--parse output)) (magithub-ci-status--parse output)
(magithub-ci-status--parse-2.2.8 (car output)))) (magithub-ci-status--parse-2.2.8 (car output))))
(prog1 (or (plist-get check :status) 'no-status) (let ((overall-status (car checks)))
(if (not (or for-commit (plist-get check :status))) (prog1 (or (and (plist-get overall-status :status) checks) 'no-status)
(let ((last-commit (magithub-ci-status--last-commit))) (if (not (or for-commit (plist-get overall-status :status)))
(unless (string-equal current-commit last-commit) (let ((last-commit (magithub-ci-status--last-commit)))
(magithub-ci-status--internal last-commit)) (unless (string-equal current-commit last-commit)
(magithub-ci-status-current-commit current-commit)) (magithub-ci-status--internal last-commit))
(magithub-ci-status-current-commit current-commit))) (magithub-ci-status-current-commit current-commit))
(magithub-ci-status-current-commit current-commit))))
(beep) (beep)
(setq magithub-hub-error (setq magithub-hub-error
(message (message
@ -145,7 +133,6 @@ See `magithub-ci-status--parse'."
The first status will be an `overall' status." The first status will be an `overall' status."
(let ((statuses (mapcar #'magithub-ci-status--parse-line output)) (let ((statuses (mapcar #'magithub-ci-status--parse-line output))
(get-status (lambda (status) (lambda (s) (eq (plist-get s :status) status))))) (get-status (lambda (status) (lambda (s) (eq (plist-get s :status) status)))))
(magithub-ci-update-urls statuses)
(cons (cons
(list :check 'overall (list :check 'overall
:status :status
@ -236,9 +223,23 @@ See the following resources:
"Browse the CI. "Browse the CI.
Sets up magithub.ci.url if necessary." Sets up magithub.ci.url if necessary."
(interactive) (interactive)
(let* ((urls (cdr (assoc (magithub-repo-id) magithub-ci-urls))) (let* ((checks (magithub-ci-status))
(target-url (if (= 1 (length urls)) (car urls) (checks-alist
(when urls (completing-read "CI Dashboard URL: " urls))))) (magithub--zip
checks
(if (magithub-hub-version-at-least "2.3")
(lambda (c)
(format "%S: %s"
(plist-get c :status)
(plist-get c :check)))
:status)
:url))
(target-url
(if (= 1 (length checks-alist))
(cdar checks-alist)
(when checks-alist
(cdr (assoc (completing-read "CI Service: " checks-alist)
checks-alist))))))
(when (or (null target-url) (string= "" target-url)) (when (or (null target-url) (string= "" target-url))
(user-error "No CI URL detected")) (user-error "No CI URL detected"))
(browse-url target-url))) (browse-url target-url)))
@ -258,7 +259,8 @@ Sets up magithub.ci.url if necessary."
(magit-refresh))) (magit-refresh)))
(defun magithub-insert-ci-status-header () (defun magithub-insert-ci-status-header ()
(let* ((status (magithub-ci-status)) (let* ((checks (magithub-ci-status))
(status (if (consp checks) (plist-get (car checks) :status) checks))
(face (intern (format "magithub-ci-%s" (face (intern (format "magithub-ci-%s"
(symbol-name status)))) (symbol-name status))))
(status-val (cdr (assq status magithub-ci-status-alist)))) (status-val (cdr (assq status magithub-ci-status-alist))))
@ -270,6 +272,16 @@ Sets up magithub.ci.url if necessary."
((functionp status-val) (funcall status-val)) ((functionp status-val) (funcall status-val))
(t (format "%S" status-val))) (t (format "%S" status-val)))
'face (if (facep face) face 'magithub-ci-unknown))) 'face (if (facep face) face 'magithub-ci-unknown)))
(when (and (consp checks) (not (eq status 'success)) (< 1 (length checks)))
(let* ((successes (-filter (lambda (c) (eq (plist-get c :status) 'success))
checks))
(numsuccesses (length successes))
(numchecks (length checks)))
(insert
(format " %d succeeded; %d did not; %s for details"
numsuccesses
(- numchecks numsuccesses)
(substitute-command-keys "\\[magit-visit-thing]")))))
(insert ?\n)))) (insert ?\n))))
(magithub--deftoggle magithub-toggle-ci-status-header (magithub--deftoggle magithub-toggle-ci-status-header

View File

@ -162,7 +162,8 @@ See /.github/ISSUE_TEMPLATE.md in this repository."
"Non-nil if Magithub should do its thing." "Non-nil if Magithub should do its thing."
(and (executable-find magithub-hub-executable) (and (executable-find magithub-hub-executable)
(magithub-enabled-p) (magithub-enabled-p)
(magithub-github-repository-p))) (magithub-github-repository-p)
(magithub--api-available-p)))
(defun magithub-error (err-message tag &optional trace) (defun magithub-error (err-message tag &optional trace)
"Report a Magithub error." "Report a Magithub error."
@ -206,5 +207,33 @@ See /.github/ISSUE_TEMPLATE.md in this repository."
(magit-refresh)) (magit-refresh))
(memq ,func ,hook))) (memq ,func ,hook)))
(defun magithub--zip-case (p e)
"Get an appropriate value for element E given property/function P."
(cond
((symbolp p) (plist-get e p))
((functionp p) (funcall p e))
((null p) e)
(t nil)))
(defun magithub--zip (object-list prop1 prop2)
"Process OBJECT-LIST into an alist defined by PROP1 and PROP2.
If a prop is a symbol, that property will be used.
If a prop is a function, it will be called with the
currentelement of OBJECT-LIST.
If a prop is nil, the entire element is used."
(delq nil
(-zip-with
(lambda (e1 e2)
(let ((p1 (magithub--zip-case prop1 e1))
(p2 (magithub--zip-case prop2 e2)))
(unless (or (and prop1 (not p1))
(and prop2 (not p2)))
(cons (if prop1 p1 e1)
(if prop2 p2 e2)))))
object-list object-list)))
(provide 'magithub-core) (provide 'magithub-core)
;;; magithub-core.el ends here ;;; magithub-core.el ends here

View File

@ -282,8 +282,14 @@ default."
(defun magithub-pull-request-checkout (pull-request) (defun magithub-pull-request-checkout (pull-request)
"Checkout PULL-REQUEST as a local branch." "Checkout PULL-REQUEST as a local branch."
(interactive (list (magithub-pull-request--completing-read))) (interactive (list (magithub-pull-request--completing-read)))
(magithub-with-hub (-when-let (url (plist-get pull-request :url))
(magit-checkout (plist-get pull-request :url)))) (magithub-with-hub
(magit-checkout url))
(dolist (var-val `(("URL" . ,url)
("ID" . ,(plist-get pull-request :number))))
(magit-set (cdr var-val)
"branch" (magit-get-current-branch)
(concat "magithubPullRequest" (car var-val))))))
;;; Hook into the status buffer ;;; Hook into the status buffer
(magithub--deftoggle magithub-toggle-issues (magithub--deftoggle magithub-toggle-issues

View File

@ -1,4 +1,4 @@
(define-package "magithub" "20161013.2008" "Magit interfaces for GitHub" (define-package "magithub" "20161013.2332" "Magit interfaces for GitHub"
'((emacs "24.4") '((emacs "24.4")
(magit "2.8.0") (magit "2.8.0")
(git-commit "20160821.1338") (git-commit "20160821.1338")