mirror of
https://codeberg.org/guix/guix.git
synced 2025-10-02 02:15:12 +00:00
import: json: Consolidate duplicate json-fetch functionality.
* guix/import/json.scm (json-fetch): Return a list or hash table. (json-fetch-alist): New procedure. * guix/import/github.scm (json-fetch*): Remove. (latest-released-version): Use json-fetch. * guix/import/cpan.scm (module->dist-name): Use json-fetch-alist. (cpan-fetch): Likewise. * guix/import/crate.scm (crate-fetch): Likewise. * guix/import/gem.scm (rubygems-fetch): Likewise. * guix/import/pypi.scm (pypi-fetch): Likewise. * guix/import/stackage.scm (stackage-lts-info-fetch): Likewise.
This commit is contained in:
parent
670a5e5430
commit
3edf0d53a4
7 changed files with 30 additions and 34 deletions
|
@ -22,31 +22,16 @@
|
|||
#:use-module (srfi srfi-1)
|
||||
#:use-module (srfi srfi-26)
|
||||
#:use-module (srfi srfi-34)
|
||||
#:use-module (json)
|
||||
#:use-module (guix utils)
|
||||
#:use-module ((guix download) #:prefix download:)
|
||||
#:use-module (guix import utils)
|
||||
#:use-module (guix import json)
|
||||
#:use-module (guix packages)
|
||||
#:use-module (guix upstream)
|
||||
#:use-module (guix http-client)
|
||||
#:use-module (web uri)
|
||||
#:export (%github-updater))
|
||||
|
||||
(define (json-fetch* url)
|
||||
"Return a representation of the JSON resource URL (a list or hash table), or
|
||||
#f if URL returns 403 or 404."
|
||||
(guard (c ((and (http-get-error? c)
|
||||
(let ((error (http-get-error-code c)))
|
||||
(or (= 403 error)
|
||||
(= 404 error))))
|
||||
#f)) ;; "expected" if there is an authentification error (403),
|
||||
;; or if package is unknown (404).
|
||||
;; Note: github.com returns 403 if we omit a 'User-Agent' header.
|
||||
(let* ((port (http-fetch url))
|
||||
(result (json->scm port)))
|
||||
(close-port port)
|
||||
result)))
|
||||
|
||||
(define (find-extension url)
|
||||
"Return the extension of the archive e.g. '.tar.gz' given a URL, or
|
||||
false if none is recognized"
|
||||
|
@ -144,7 +129,7 @@ the package e.g. 'bedtools2'. Return #f if there is no releases"
|
|||
"https://api.github.com/repos/"
|
||||
(github-user-slash-repository url)
|
||||
"/releases"))
|
||||
(json (json-fetch*
|
||||
(json (json-fetch
|
||||
(if token
|
||||
(string-append api-url "?access_token=" token)
|
||||
api-url))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue