Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create method 'gitlab'. #2605

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there's just six recipes using gitlab urls right now, maybe we should just change them all to :type gitlab?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. In addition to the existing 6 recipes, there is also "mo-git-blame", which moved to gitlab.
type git => type gitlab
url "https://gitlab.com/warsaw/winring.git" => pkgname "warsaw/winring"

- check-whitespace
7 changes: 6 additions & 1 deletion el-get-check.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
50 changes: 50 additions & 0 deletions methods/el-get-gitlab-tar.el
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
;; 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)
48 changes: 48 additions & 0 deletions methods/el-get-gitlab-zip.el
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
;; 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)
100 changes: 100 additions & 0 deletions methods/el-get-gitlab.el
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
;; 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 "[email protected]:%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)