Skip to content
Snippets Groups Projects
Unverified Commit cb5fe915 authored by Arun Isaac's avatar Arun Isaac
Browse files

import: github: Improve readability.

* guix/import/github.scm (latest-released-version): Use any and cond instead
of a recursive loop and an if-else ladder respectively.
parent 6b7ea49b
No related branches found
No related tags found
No related merge requests found
...@@ -183,35 +183,32 @@ (define (pre-release? x) ...@@ -183,35 +183,32 @@ (define (pre-release? x)
API. This may be fixed by using an access token and setting the environment API. This may be fixed by using an access token and setting the environment
variable GUIX_GITHUB_TOKEN, for instance one procured from variable GUIX_GITHUB_TOKEN, for instance one procured from
https://github.com/settings/tokens")) https://github.com/settings/tokens"))
(let loop ((releases (any
(match (remove pre-release? json) (lambda (release)
(() json) ; keep everything (let ((tag (or (hash-ref release "tag_name") ;a "release"
(releases releases)))) (hash-ref release "name"))) ;a tag
(match releases (name-length (string-length package-name)))
(() ;empty release list (cond
#f) ;; some tags include the name of the package e.g. "fdupes-1.51"
((release . rest) ;one or more releases ;; so remove these
(let ((tag (or (hash-ref release "tag_name") ;a "release" ((and (< name-length (string-length tag))
(hash-ref release "name"))) ;a tag (string=? (string-append package-name "-")
(name-length (string-length package-name))) (substring tag 0 (+ name-length 1))))
;; some tags include the name of the package e.g. "fdupes-1.51" (substring tag (+ name-length 1)))
;; so remove these ;; some tags start with a "v" e.g. "v0.25.0"
(if (and (< name-length (string-length tag)) ;; where some are just the version number
(string=? (string-append package-name "-") ((string-prefix? "v" tag)
(substring tag 0 (+ name-length 1)))) (substring tag 1))
(substring tag (+ name-length 1)) ;; Finally, reject tags that don't start with a digit:
;; some tags start with a "v" e.g. "v0.25.0" ;; they may not represent a release.
;; where some are just the version number ((and (not (string-null? tag))
(if (string-prefix? "v" tag) (char-set-contains? char-set:digit
(substring tag 1) (string-ref tag 0)))
tag)
;; Finally, reject tags that don't start with a digit: (else #f))))
;; they may not represent a release. (match (remove pre-release? json)
(if (and (not (string-null? tag)) (() json) ; keep everything
(char-set-contains? char-set:digit (releases releases))))))
(string-ref tag 0)))
tag
(loop rest)))))))))))
(define (latest-release pkg) (define (latest-release pkg)
"Return an <upstream-source> for the latest release of PKG." "Return an <upstream-source> for the latest release of PKG."
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment