Fixes #390 Reimplement check of new version
The new implementation does not depend on the Github API It depends only on git
This commit is contained in:
parent
e4763abb4a
commit
2c9f94aa00
|
@ -13,6 +13,10 @@
|
||||||
"Name of the Spacemacs remote repository.")
|
"Name of the Spacemacs remote repository.")
|
||||||
(defconst spacemacs-repository-owner "syl20bnr"
|
(defconst spacemacs-repository-owner "syl20bnr"
|
||||||
"Name of the Spacemacs remote repository owner.")
|
"Name of the Spacemacs remote repository owner.")
|
||||||
|
(defconst spacemacs-checkversion-remote "checkversion"
|
||||||
|
"Name of the remote repository used to check for new version.")
|
||||||
|
(defconst spacemacs-checkversion-branch "master"
|
||||||
|
"Name of the branch used to check for new version.")
|
||||||
|
|
||||||
(defgroup spacemacs nil
|
(defgroup spacemacs nil
|
||||||
"Spacemacs customizations."
|
"Spacemacs customizations."
|
||||||
|
@ -220,33 +224,34 @@ FILE-TO-LOAD is an explicit file to load after the installation."
|
||||||
"Change the default welcome message of minibuffer to another one."
|
"Change the default welcome message of minibuffer to another one."
|
||||||
(message "Spacemacs is ready."))
|
(message "Spacemacs is ready."))
|
||||||
|
|
||||||
(defun spacemacs//get-last-version (repo owner)
|
(defun spacemacs/get-last-version (repo owner remote branch)
|
||||||
"Return the last version fetched from Github REPO of OWNER."
|
"Return the last tagged version of BRANCH on REMOTE repository from
|
||||||
(let* ((api (gh-repos-api "api"))
|
OWNER REPO."
|
||||||
(repo (oref (gh-repos-repo-get api spacemacs-repository
|
(let ((url (format "http://github.com/%s/%s" owner repo)))
|
||||||
spacemacs-repository-owner) :data))
|
(unless (spacemacs/git-has-remote remote)
|
||||||
(tags (oref (gh-repos-repo-tags api repo) :data))
|
(spacemacs/git-declare-remote remote url)))
|
||||||
(last-version (cdr (assq 'name (nth 0 tags)))))
|
(spacemacs/git-fetch-tags remote branch)
|
||||||
(when last-version
|
(let ((version (spacemacs/git-latest-tag remote branch)))
|
||||||
|
(when version
|
||||||
(save-match-data
|
(save-match-data
|
||||||
(string-match "^.*\\([0-9]+\\.[0-9]+\\.[0-9]+\\)$" last-version)
|
(string-match "^.*\\([0-9]+\\.[0-9]+\\.[0-9]+\\)$" version)
|
||||||
(match-string 1 last-version)))))
|
(match-string 1 version)))))
|
||||||
|
|
||||||
(defun spacemacs/check-for-new-version (&optional interval)
|
(defun spacemacs/check-for-new-version (&optional interval)
|
||||||
"Periodicly check for new for new Spacemacs version.
|
"Periodicly check for new for new Spacemacs version.
|
||||||
Update `spacemacs-new-version' variable if any new version has been
|
Update `spacemacs-new-version' variable if any new version has been
|
||||||
found."
|
found."
|
||||||
;; (message "Start checking for new version...")
|
(message "Start checking for new version...")
|
||||||
(async-start
|
(async-start
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(add-to-list 'load-path (concat user-emacs-directory "core/"))
|
(add-to-list 'load-path (concat user-emacs-directory "core/"))
|
||||||
(require 'spacemacs-mode)
|
(require 'spacemacs-mode)
|
||||||
(spacemacs/load-or-install-package 'pcache t)
|
(spacemacs/get-last-version spacemacs-repository
|
||||||
(spacemacs/load-or-install-package 'logito t)
|
spacemacs-repository-owner
|
||||||
(spacemacs/load-or-install-package 'gh t "gh-repos.el")
|
spacemacs-checkversion-remote
|
||||||
(spacemacs//get-last-version spacemacs-repository
|
spacemacs-checkversion-branch))
|
||||||
spacemacs-repository-owner))
|
|
||||||
(lambda (result)
|
(lambda (result)
|
||||||
|
(message "result: %s" result)
|
||||||
(when result
|
(when result
|
||||||
(unless (or (version< result spacemacs-version)
|
(unless (or (version< result spacemacs-version)
|
||||||
(string= result spacemacs-version)
|
(string= result spacemacs-version)
|
||||||
|
@ -259,6 +264,48 @@ found."
|
||||||
(run-at-time t (timer-duration interval)
|
(run-at-time t (timer-duration interval)
|
||||||
'spacemacs/check-for-new-version))))
|
'spacemacs/check-for-new-version))))
|
||||||
|
|
||||||
|
(defun spacemacs/git-has-remote (remote)
|
||||||
|
"Return non nil if REMOTE is declared."
|
||||||
|
(let((proc-buffer "git-has-remote")
|
||||||
|
(default-directory user-emacs-directory))
|
||||||
|
(when (eq 0 (process-file "git" nil proc-buffer nil "remote"))
|
||||||
|
(with-current-buffer proc-buffer
|
||||||
|
(prog2
|
||||||
|
(goto-char (point-min))
|
||||||
|
(> (re-search-forward (format "^%s$" remote) nil 'noerror) 0)
|
||||||
|
(kill-buffer proc-buffer))))))
|
||||||
|
|
||||||
|
(defun spacemacs/git-declare-remote (remote url)
|
||||||
|
"Declare a new REMOTE pointing to URL, return t if no error."
|
||||||
|
(let((proc-buffer "git-declare-remote")
|
||||||
|
(default-directory user-emacs-directory))
|
||||||
|
(prog1
|
||||||
|
(eq 0 (process-file "git" nil proc-buffer nil
|
||||||
|
"remote" "add" remote url))
|
||||||
|
(kill-buffer proc-buffer))))
|
||||||
|
|
||||||
|
(defun spacemacs/git-fetch-tags (remote branch)
|
||||||
|
"Fetch the tags for BRANCH in REMOTE repository."
|
||||||
|
(let((proc-buffer "git-fetch-tags")
|
||||||
|
(default-directory user-emacs-directory))
|
||||||
|
(prog1
|
||||||
|
(eq 0 (process-file "git" nil proc-buffer nil
|
||||||
|
"fetch" "--tags" remote branch))
|
||||||
|
(kill-buffer proc-buffer))))
|
||||||
|
|
||||||
|
(defun spacemacs/git-latest-tag (remote branch)
|
||||||
|
"Returns the latest tag on REMOTE/BRANCH."
|
||||||
|
(let((proc-buffer "git-latest-tag")
|
||||||
|
(default-directory user-emacs-directory)
|
||||||
|
(where (format "%s/%s" remote branch)))
|
||||||
|
(when (eq 0 (process-file "git" nil proc-buffer nil
|
||||||
|
"describe" "--tags" "--match=v*" where))
|
||||||
|
(with-current-buffer proc-buffer
|
||||||
|
(prog1
|
||||||
|
(if (buffer-string)
|
||||||
|
(replace-regexp-in-string "\n$" "" (buffer-string)))
|
||||||
|
(kill-buffer proc-buffer))))))
|
||||||
|
|
||||||
(defun spacemacs//deffaces-new-version-lighter (state)
|
(defun spacemacs//deffaces-new-version-lighter (state)
|
||||||
"Define a new version lighter face for the given STATE."
|
"Define a new version lighter face for the given STATE."
|
||||||
(let* ((fname (intern (format "spacemacs-mode-line-new-version-lighter-%s-face"
|
(let* ((fname (intern (format "spacemacs-mode-line-new-version-lighter-%s-face"
|
||||||
|
|
Loading…
Reference in a new issue