From 9e6207f37ac1b87a751434c9ba39056983b12522 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Mon, 24 Apr 2017 06:36:04 +0100 Subject: Alter the GitHub updater to use git tags Just using tags is the most consistent way of getting releases for GOV.UK related software. --- guix/import/github.scm | 73 +++++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 30 deletions(-) diff --git a/guix/import/github.scm b/guix/import/github.scm index 4d12339204..78f32a4fef 100644 --- a/guix/import/github.scm +++ b/guix/import/github.scm @@ -171,10 +171,19 @@ empty list." "Return a string of the newest released version name given a string URL like 'https://github.com/arq5x/bedtools2/archive/v2.24.0.tar.gz' and the name of the package e.g. 'bedtools2'. Return #f if there is no releases" - (define (pre-release? x) - (hash-ref x "prerelease")) - - (let* ((json (fetch-releases-or-tags url))) + (let* ((token (%github-token)) + (releases-api-url (string-append + "https://api.github.com/repos/" + (github-user-slash-repository url) + "/releases")) + (tags-api-url (string-append + "https://api.github.com/repos/" + (github-user-slash-repository url) + "/tags")) + (json (json-fetch + (if token + (string-append tags-api-url "?access_token=" token) + tags-api-url)))) (if (eq? json #f) (if (%github-token) (error "Error downloading release information through the GitHub @@ -183,32 +192,36 @@ API when using a GitHub token") API. This may be fixed by using an access token and setting the environment variable GUIX_GITHUB_TOKEN, for instance one procured from https://github.com/settings/tokens")) - (any - (lambda (release) - (let ((tag (or (hash-ref release "tag_name") ;a "release" - (hash-ref release "name"))) ;a tag - (name-length (string-length package-name))) - (cond - ;; some tags include the name of the package e.g. "fdupes-1.51" - ;; so remove these - ((and (< name-length (string-length tag)) - (string=? (string-append package-name "-") - (substring tag 0 (+ name-length 1)))) - (substring tag (+ name-length 1))) - ;; some tags start with a "v" e.g. "v0.25.0" - ;; where some are just the version number - ((string-prefix? "v" tag) - (substring tag 1)) - ;; Finally, reject tags that don't start with a digit: - ;; they may not represent a release. - ((and (not (string-null? tag)) - (char-set-contains? char-set:digit - (string-ref tag 0))) - tag) - (else #f)))) - (match (remove pre-release? json) - (() json) ; keep everything - (releases releases)))))) + (let ((proper-releases + (filter + (lambda (x) + ;; example pre-release: + ;; https://github.com/wwood/OrfM/releases/tag/v0.5.1 + ;; or an all-prerelease set + ;; https://github.com/powertab/powertabeditor/releases + (and (not (hash-ref x "prerelease")) + (string-prefix? "release_" + (or (hash-ref x "tag_name") + (hash-ref x "name"))))) + json))) + (match proper-releases + (() ;empty release list + #f) + + ((release . rest) ;one or more releases + (let ((tag (or (hash-ref release "tag_name") + (hash-ref release "name"))) + (name-length (string-length package-name))) + ;; some tags include the name of the package e.g. "fdupes-1.51" + ;; so remove these + (if (and (< name-length (string-length tag)) + (string=? (string-append package-name "-") + (substring tag 0 (+ name-length 1)))) + (substring tag (+ name-length 1)) + ;; some tags start with a "v" e.g. "v0.25.0" + ;; where some are just the version number + (if (string-prefix? "v" tag) + (substring tag 1) tag))))))))) (define (latest-release pkg) "Return an for the latest release of PKG." -- cgit v1.2.3