From d4f39e90902aa683bf4f23f464e23630e0a1de2f Mon Sep 17 00:00:00 2001 From: gavk Date: Tue, 16 Jan 2018 12:11:31 +1000 Subject: [PATCH] Create method 'gitlab'. --- .travis.yml | 2 +- el-get-check.el | 7 ++- methods/el-get-gitlab-tar.el | 50 ++++++++++++++++++ methods/el-get-gitlab-zip.el | 48 +++++++++++++++++ methods/el-get-gitlab.el | 100 +++++++++++++++++++++++++++++++++++ 5 files changed, 205 insertions(+), 2 deletions(-) create mode 100644 methods/el-get-gitlab-tar.el create mode 100644 methods/el-get-gitlab-zip.el create mode 100644 methods/el-get-gitlab.el diff --git a/.travis.yml b/.travis.yml index 95ad591c5..dee725311 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,5 +14,5 @@ script: - byte-compile pkg/*.el - byte-compile -Werror *.el methods/*.el - ert-tests - - check-recipes -Wno-features -Wno-github -Wno-autoloads recipes/ + - check-recipes -Wno-features -Wno-github -Wno-gitlab -Wno-autoloads recipes/ - check-whitespace diff --git a/el-get-check.el b/el-get-check.el index 16dee38b2..7b289b91f 100644 --- a/el-get-check.el +++ b/el-get-check.el @@ -51,7 +51,7 @@ See Info node `(el-get) Authoring Recipes'.") "List of `el-get-check-recipe' warnings to suppress. Current possibe elements are: - `features', `github', `autoloads'") + `features', `github', `gitlab', `autoloads'") (defun el-get-check-recipe-batch-1 (recipe-file) (let ((warning-prefix-function @@ -175,6 +175,11 @@ FILENAME defaults to `buffer-file-name'." (eq type 'git) (string-match "//github.com/" url)) (el-get-check-warning :warning "Use `:type github' for github type recipe")) + ;; Is gitlab type used? + (when (and (not (memq 'gitlab el-get-check-suppressed-warnings)) + (eq type 'git) (string-match "//gitlab.com/" url)) + (el-get-check-warning :warning + "Use `:type gitlab' for gitlab type recipe")) ;; Warn when `:autoloads nil' is specified. (when (and (not (memq 'autoloads el-get-check-suppressed-warnings)) (null autoloads) (plist-member recipe :autoloads)) diff --git a/methods/el-get-gitlab-tar.el b/methods/el-get-gitlab-tar.el new file mode 100644 index 000000000..489b60138 --- /dev/null +++ b/methods/el-get-gitlab-tar.el @@ -0,0 +1,50 @@ +;;; el-get --- Manage the external elisp bits and pieces you depend upon +;; +;; Copyright (C) 2010-2011 Dimitri Fontaine +;; +;; Author: Dimitri Fontaine +;; URL: http://www.emacswiki.org/emacs/el-get +;; GIT: https://githab.com/dimitri/el-get +;; Licence: WTFPL, grab your copy here: http://sam.zoy.org/wtfpl/ +;; +;; This file is NOT part of GNU Emacs. +;; +;; Install +;; Please see the README.md file from the same distribution + +(require 'el-get-http-tar) +(require 'el-get-gitlab) + +(defun el-get-gitlab-tar-url (package) + (let* ((source (el-get-package-def package))) + (or + ;; Use :url if provided + (plist-get source :url) + ;; Else generate URL from username, and reponame + (let* ((user-and-repo (el-get-gitlab-parse-user-and-repo package)) + (username (car user-and-repo)) + (reponame (cdr user-and-repo)) + (branch (or (plist-get source :branch) + "master"))) + (format "https://gitlab.com/%s/%s/tarball/%s" + username reponame branch))))) + +(defun el-get-gitlab-tar-install (package url post-install-fun) + "Clone the given package from Github following the URL." + ;; The recipe must have a `:url' property for + ;; `el-get-http-tar-install' to work. Also, since gitlab tarballs + ;; are ".tar.gz", we know what the default tar options should be. + (let* ((old-pdef (el-get-package-def package)) + (url (or url (el-get-gitlab-tar-url package))) + (options (or (plist-get old-pdef :options) '("xzf"))) + (new-pdef (append `(:url ,url :options ,options) + (el-get-package-def package))) + (el-get-sources (cons new-pdef el-get-sources))) + (el-get-http-tar-install package url post-install-fun))) + +(el-get-register-derived-method :gitlab-tar :http-tar + :install #'el-get-gitlab-tar-install + :update #'el-get-gitlab-tar-install + :guess-website #'el-get-gitlab-guess-website) + +(provide 'el-get-gitlab-tar) diff --git a/methods/el-get-gitlab-zip.el b/methods/el-get-gitlab-zip.el new file mode 100644 index 000000000..8be672720 --- /dev/null +++ b/methods/el-get-gitlab-zip.el @@ -0,0 +1,48 @@ +;;; el-get --- Manage the external elisp bits and pieces you depend upon +;; +;; Copyright (C) 2010-2011 Dimitri Fontaine +;; +;; Author: Dimitri Fontaine +;; URL: http://www.emacswiki.org/emacs/el-get +;; GIT: https://github.com/dimitri/el-get +;; Licence: WTFPL, grab your copy here: http://sam.zoy.org/wtfpl/ +;; +;; This file is NOT part of GNU Emacs. +;; +;; Install +;; Please see the README.md file from the same distribution + +(require 'el-get-http-zip) +(require 'el-get-gitlab) + +(defun el-get-gitlab-zip-url (package) + (let* ((source (el-get-package-def package))) + (or + ;; Use :url if provided + (plist-get source :url) + ;; Else generate URL from username, and reponame + (let* ((user-and-repo (el-get-gitlab-parse-user-and-repo package)) + (username (car user-and-repo)) + (reponame (cdr user-and-repo)) + (branch (or (plist-get source :branch) + "master"))) + (format "https://gitlab.com/%s/%s/zipball/%s" + username reponame branch))))) + +(defun el-get-gitlab-zip-install (package url post-install-fun) + "Clone the given package from Github following the URL." + ;; The recipe must have a `:url' property for + ;; `el-get-http-zip-install' to work. + (let* ((old-pdef (el-get-package-def package)) + (url (or url (el-get-gitlab-zip-url package))) + (new-pdef (append `(:url ,url) + (el-get-package-def package))) + (el-get-sources (cons new-pdef el-get-sources))) + (el-get-http-zip-install package url post-install-fun))) + +(el-get-register-derived-method :gitlab-zip :http-zip + :install #'el-get-gitlab-zip-install + :update #'el-get-gitlab-zip-install + :guess-website #'el-get-gitlab-guess-website) + +(provide 'el-get-gitlab-zip) diff --git a/methods/el-get-gitlab.el b/methods/el-get-gitlab.el new file mode 100644 index 000000000..27531d8a6 --- /dev/null +++ b/methods/el-get-gitlab.el @@ -0,0 +1,100 @@ +;;; el-get --- Manage the external elisp bits and pieces you depend upon +;; +;; Copyright (C) 2010-2011 Dimitri Fontaine +;; +;; Author: Dimitri Fontaine +;; URL: http://www.emacswiki.org/emacs/el-get +;; GIT: https://github.com/dimitri/el-get +;; Licence: WTFPL, grab your copy here: http://sam.zoy.org/wtfpl/ +;; +;; This file is NOT part of GNU Emacs. +;; +;; Install +;; Please see the README.md file from the same distribution + +(require 'el-get-core) +(require 'el-get-git) + +(defconst el-get-gitlab-url-type-plist + (list 'http "http://gitlab.com/%USER%/%REPO%.git" + 'https "https://gitlab.com/%USER%/%REPO%.git" + 'git "git://gitlab.com/%USER%/%REPO%.git" + 'ssh "git@gitlab.com:%USER%/%REPO%.git") + "Plist mapping Github types to their URL format strings.") + +(defcustom el-get-gitlab-default-url-type 'https + "The kind of URL to use for Github repositories. + +Choices are `http', `https', `git'. This is effectively the +default `:url-type' for Github recipes that do not specify one. +Individual Github recipes can override this setting by providing +their own `:url-type' property. Note that `ssh' is also an +acceptable value for `:url-type', but you should not set it here +because it will prevent access to any repositories not owned by +you." + :group 'el-get + :type '(choice (const :tag "HTTP" http) + (const :tag "HTTPS" https) + (const :tag "git" git))) + +(defun el-get-replace-string (from to str) + "Replace all instances of FROM with TO in str. + +FROM is a literal string, not a regexp." + (replace-regexp-in-string (regexp-quote from) to str 'fixedcase 'literal)) + +(defun el-get-gitlab-parse-user-and-repo (package) + "Returns a cons cell of `(USER . REPO)'." + (let* ((source (el-get-package-def package)) + (user-slash-repo + (or (plist-get source :pkgname) + (error ":pkgname \"username/reponame\" is mandatory for gitlab recipe '%s" + package))) + (user-and-repo (split-string user-slash-repo "/" 'omit-nulls))) + (assert (= (length user-and-repo) 2) nil + "Github pkgname %s must be of the form username/reponame" + user-slash-repo) + (cons (first user-and-repo) (second user-and-repo)))) + +(defun el-get-gitlab-url-private (url-type username reponame) + "Return the url of a particular gitlab project. +URL-TYPE must be a valid property (a symbol) of +`el-get-gitlab-url-type-plist'. +USERNAME and REPONAME are strings." + (let ((url-format-string + (or (plist-get el-get-gitlab-url-type-plist url-type) + (error "Unknown Github repo URL type: %s" url-type)))) + (el-get-replace-string + "%USER%" username + (el-get-replace-string "%REPO%" reponame url-format-string)))) + +(defun el-get-gitlab-url (package) + (let* ((source (el-get-package-def package)) + (user-and-repo (el-get-gitlab-parse-user-and-repo package)) + (username (car user-and-repo)) + (reponame (cdr user-and-repo)) + (url-type (el-get-as-symbol + (or (plist-get source :url-type) + el-get-gitlab-default-url-type)))) + (el-get-gitlab-url-private url-type username reponame))) + +(defun el-get-gitlab-clone (package _url post-install-fun) + "Clone the given package from Github following the URL." + (el-get-git-clone package (el-get-gitlab-url package) post-install-fun)) + +(defun el-get-gitlab-pull (package _url post-install-fun) + "Update the given package from Github following the URL." + (el-get-git-pull package (el-get-gitlab-url package) post-install-fun)) + +(defun el-get-gitlab-guess-website (package) + (let* ((user-and-repo (el-get-gitlab-parse-user-and-repo package)) + (username (car user-and-repo)) + (reponame (cdr user-and-repo))) + (el-get-gitlab-url-private 'https username reponame))) + +(el-get-register-derived-method :gitlab :git + :install #'el-get-gitlab-clone + :update #'el-get-gitlab-pull + :guess-website #'el-get-gitlab-guess-website) + +(provide 'el-get-gitlab)