blob: efcafb7909f446a719377eae010536d5ac25645d (
plain)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
(define-module (guix-qa-frontpage guix-data-service)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-11)
#:use-module (ice-9 match)
#:use-module (ice-9 exceptions)
#:use-module (web uri)
#:use-module (web client)
#:use-module (web response)
#:use-module (rnrs bytevectors)
#:use-module (json)
#:use-module (guix-build-coordinator utils)
#:use-module (guix-qa-frontpage patchwork)
#:export (patch-series-derivation-changes-url
patch-series-derivation-changes
patch-series-compare-url
patch-series-comparison
list-branches-url
list-branches
branch-derivation-changes-url
branch-derivation-changes
get-latest-processed-branch-revision))
(define* (patch-series-derivation-changes-url checks #:key systems)
(define comparison-check
(match (sort (filter (lambda (check)
(string=? (assoc-ref check "context")
"comparison"))
checks)
(lambda (a b)
(string>? (assoc-ref a "date")
(assoc-ref b "date"))))
((first . rest) first)
(() #f)))
(and comparison-check
(let ((url-query-params
(uri-query
(string->uri
(assoc-ref comparison-check "target_url")))))
(string-append
"https://data.qa.guix.gnu.org/compare/package-derivations.json?"
url-query-params
(string-join
(map (lambda (system)
(simple-format #f "&system=~A" system))
(or systems '()))
"")
"&target=none"
"&field=builds&limit_results=&all_results=on"))))
(define (patch-series-derivation-changes url)
(let-values (((response body)
(http-get (string->uri url))))
(if (eq? (response-code response)
404)
(values #f #f)
(let ((json-body
(json-string->scm (utf8->string body))))
(if (or (> (response-code response)
400)
(assoc-ref json-body "error"))
(raise-exception
(make-exception-with-message
(simple-format
#f
"error fetching patch series derivation changes: ~A (response code: ~A): ~A"
url
(response-code response)
(assoc-ref json-body "error"))))
(values (vector->list
(assoc-ref json-body
"derivation_changes"))
(alist-delete "derivation_changes"
json-body)))))))
(define (patch-series-compare-url series)
(define comparison-check
(match (sort (filter (lambda (check)
(string=? (assoc-ref check "context")
"comparison"))
(patchwork-patch-checks
(assoc-ref (first (assoc-ref series "patches"))
"checks")))
(lambda (a b)
(string>? (assoc-ref a "date")
(assoc-ref b "date"))))
((first . rest) first)
(() #f)))
(and comparison-check
(let ((url-query-params
(uri-query
(string->uri
(assoc-ref comparison-check "target_url")))))
(string-append
"https://data.qa.guix.gnu.org/compare.json?"
url-query-params))))
(define (patch-series-comparison url)
(retry-on-error
(lambda ()
(let-values (((response body)
(http-get (string->uri url))))
(if (eq? (response-code response)
404)
#f
(let ((json-body
(json-string->scm (utf8->string body))))
(if (assoc-ref json-body "error")
#f
json-body)))))
#:times 6
#:delay 5))
(define (list-branches-url repository-id)
(simple-format #f "https://data.qa.guix.gnu.org/repository/~A.json"
repository-id))
(define (list-branches url)
(retry-on-error
(lambda ()
(let-values (((response body)
(http-get (string->uri url))))
(if (eq? (response-code response)
404)
#f
(let ((json-body
(json-string->scm (utf8->string body))))
(if (assoc-ref json-body "error")
#f
(vector->list
(assoc-ref json-body "branches")))))))
#:times 6
#:delay 5))
(define* (branch-derivation-changes-url branch #:key systems)
(string-append
"https://data.qa.guix.gnu.org/compare-by-datetime/package-derivations.json?"
"base_branch=master"
"&target_branch=" branch
(string-join
(map (lambda (system)
(simple-format #f "&system=~A" system))
(or systems '()))
"")
"&target=none"
"&field=builds&limit_results=&all_results=on"))
(define (branch-derivation-changes url)
(retry-on-error
(lambda ()
(let-values (((response body)
(http-get (string->uri url))))
(if (eq? (response-code response)
404)
(values #f #f)
(let ((json-body
(json-string->scm (utf8->string body))))
(if (assoc-ref json-body "error")
(values #f #f)
(values (vector->list
(assoc-ref json-body
"derivation_changes"))
(alist-delete "derivation_changes"
json-body)))))))
#:times 6
#:delay 5))
(define (get-latest-processed-branch-revision branch)
(retry-on-error
(lambda ()
(let-values (((response body)
(http-get (string->uri
(string-append
"https://data.qa.guix.gnu.org"
"/repository/2"
"/branch/" branch
"/latest-processed-revision.json")))))
(let ((json-body
(json-string->scm (utf8->string body))))
(assoc-ref
(assoc-ref json-body "revision")
"commit"))))
#:times 5
#:delay 5))
|