-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathupstream-github.lisp
77 lines (64 loc) · 2.68 KB
/
upstream-github.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
;;;; github.lisp
(in-package #:quicklisp-controller)
(defun github-owner-and-repo (url)
(ppcre:register-groups-bind (owner repo)
("//github.com/([^/]+?)/([^/]+?)(\\.git)?$" url)
(values owner repo)))
(defun github-latest-release-info (url)
(multiple-value-bind (owner repo)
(github-owner-and-repo url)
(unless (and owner repo)
(error "Could not parse ~A as a github repo url" url))
(let* ((response (githappy:repo-releases :owner owner :repo repo))
(json (and response (githappy:json response))))
(list :url (githappy:jref json '(0 "tarball_url"))
:tag (githappy:jref json '(0 "tag_name"))))))
(defun github-latest-tag-info (url)
(multiple-value-bind (owner repo)
(github-owner-and-repo url)
(unless (and owner repo)
(error "Could not parse ~A as a github repo url" url))
(let* ((response (githappy:repo-tags :owner owner :repo repo))
(json (and response (githappy:json response))))
(list :url (githappy:jref json '(0 "tarball_url"))
:tag (githappy:jref json '(0 "name"))))))
(defclass latest-github-release-source (git-source)
((release-url
:initarg :release-url
:accessor release-url)
(release-tag
:initarg :release-tag
:accessor release-tag
:reader tag-data
:reader target-ref)))
(defclass latest-github-tag-source (latest-github-release-source)
())
(defgeneric github-info-plist (source)
(:method ((source symbol))
(let ((real-source (source-designator source)))
(unless real-source
(error "~S does not designate a source" source))
(github-info-plist real-source)))
(:method ((source latest-github-release-source))
(github-latest-release-info (location source)))
(:method ((source latest-github-tag-source))
(github-latest-tag-info (location source))))
(defgeneric initialize-release-info (source)
(:method (source)
(let ((info (github-info-plist source)))
(setf (release-tag source) (getf info :tag)
(release-url source) (getf info :url)))))
(defmethod slot-unbound ((class t) (source latest-github-release-source)
(slot-name (eql 'release-url)))
(initialize-release-info source)
(release-url source))
(defmethod slot-unbound ((class t) (source latest-github-release-source)
(slot-name (eql 'release-tag)))
(initialize-release-info source)
(release-tag source))
(defmethod release-tarball-prefix ((source latest-github-release-source))
(format nil "~A-~A/" (name source) (release-tag source)))
(defmethod parse-location ((source latest-github-release-source)
location-string)
(setf (location source) location-string)
source)