aboutsummaryrefslogtreecommitdiff
path: root/guix-qa-frontpage/view/issue.scm
blob: bbd34e22b27067332e7502a02092f751ef4bae05 (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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
(define-module (guix-qa-frontpage view issue)
  #:use-module (srfi srfi-1)
  #:use-module (ice-9 match)
  #:use-module (web uri)
  #:use-module (guix-data-service web sxml)
  #:use-module (guix-qa-frontpage issue)
  #:use-module (guix-qa-frontpage manage-builds)
  #:use-module (guix-qa-frontpage guix-data-service)
  #:use-module (guix-qa-frontpage derivation-changes)
  #:use-module (guix-qa-frontpage view util)
  #:use-module (guix-qa-frontpage view shared)
  #:export (issue-view
            issue-package-changes-view
            issue-package-cross-changes-view

            issue-prepare-review-view))

(define (issue-view issue-number series branch mumi-tags
                    base-and-target-refs
                    create-branch-for-issue-log
                    comparison-link
                    derivation-changes
                    cross-derivation-changes
                    builds-missing?
                    change-details comparison-details
                    systems-with-low-substitute-availability)

  (define tagged-as-moreinfo?
    (member "moreinfo" mumi-tags))

  (define debbugs-usertags
    (assq-ref series 'usertags))

  (define derivation-changes-counts
    (assq-ref derivation-changes 'counts))

  (define cross-derivation-changes-counts
    (and cross-derivation-changes
         (filter
          (match-lambda
            (((system . target) . derivations) #t)
            (_ #f))
          (assq-ref cross-derivation-changes 'counts))))

  (define links-div
    `(div
      (@ (class "large-screen-float-right"))
      (h3 "Links")
      (ul
       (li
        (a (@ (href ,(simple-format #f "https://issues.guix.gnu.org/~A"
                                    issue-number)))
           "View issue on issues.guix.gnu.org")
        ,@(let ((merged-with
                 (assq-ref (assq-ref series 'mumi)
                           'merged-with)))
            (if (null? merged-with)
                '()
                `((br)
                  "Merged with:"
                  (ul
                   ,@(map
                      (lambda (number)
                        `(li
                          (a (@ (href
                                 ,(simple-format #f "https://issues.guix.gnu.org/~A"
                                                 number)))
                             ,number)))
                      merged-with))))))
       ,@(if base-and-target-refs
             `((li
                (a (@ (href
                       ,(let ((branch-name
                               (simple-format #f "issue-~A" issue-number))
                              (base-tag
                               (simple-format #f "base-for-issue-~A" issue-number)))
                          (simple-format
                           #f
                           "~A/log/?h=~A&qt=range&q=~A..~A"
                           "https://git.guix-patches.cbaines.net/guix-patches"
                           branch-name base-tag branch-name))))
                   "View Git branch")))
             '())
       (li
        (a (@ (href ,(assoc-ref series "web_url")))
           "View series on Patchwork"))
       ,@(if comparison-link
             `((li
                (a (@ (href ,comparison-link))
                   "View Guix Data Service comparison")))
             '())
       (li
        (a (@ (href
               ,(string-append
                 "mailto:control@debbugs.gnu.org?"
                 "subject="
                 (uri-encode
                  (simple-format #f "tag ~A moreinfo" issue-number))
                 "&body="
                 (uri-encode
                  (string-append
                   (simple-format #f "tags ~A ~A moreinfo"
                                  issue-number
                                  (if tagged-as-moreinfo?
                                      "-"
                                      "+"))
                   "\nquit\n")))))
           ,(if tagged-as-moreinfo?
                "Remove moreinfo tag"
                "Mark as moreinfo"))))))

  (define lint-warnings-div
    `(div
      (h3 "Lint warnings")
      (table
       (thead
        (tr
         (th "Change")
         (th "Linter")
         (th "Message")))
       (tbody
        ,@(if (and comparison-details
                   (not (assq-ref comparison-details 'exception)))
              (if (eq? (vector-length (assoc-ref comparison-details "lint_warnings"))
                       0)
                  `((tr
                     (td (@ (colspan 3))
                         "No lint warning changes"
                         (br)
                         (small "(for lint checkers that don't require the network)"))))
                  (append-map
                   (lambda (package-warnings)
                     (filter-map
                      (lambda (warning)
                        (let ((checker (assoc-ref warning "checker")))
                          (if (string=? (assoc-ref checker "name")
                                        "derivation")
                              #f
                              `(tr
                                (td (@ (style ,(string-join
                                                `("border-left-width: 0.35em;"
                                                  "border-left-style: solid;"
                                                  ,(string-append
                                                    "border-left-color: "
                                                    (if (string=? (assoc-ref warning "change")
                                                                  "new")
                                                        "red"
                                                        "green"))))))
                                    ,(assoc-ref warning "change"))
                                (td
                                 (span (@ (class "monospace")
                                          (style "display: block;"))
                                       ,(assoc-ref checker "name"))
                                 (p (@ (style "font-size: small;"))
                                    ,(assoc-ref checker "description")))
                                (td ,(assoc-ref warning "message"))))))
                      (vector->list
                       (assoc-ref package-warnings "warnings"))))
                   (vector->list
                    (assoc-ref comparison-details "lint_warnings"))))
              `((tr
                 (td (@ (colspan 3)
                        (class "bad"))
                     "Comparison unavailable"
                     ,@(or (and=>
                            (assq-ref comparison-details 'exception)
                            (lambda (exception)
                              (and=>
                               (assq-ref comparison-details 'invalid_query_parameters)
                               (lambda (invalid-params)
                                 (let ((target-commit
                                        (assoc-ref invalid-params "target_commit")))
                                   (cond
                                    (target-commit
                                     (let ((error (assq-ref target-commit 'error))
                                           (value (assq-ref target-commit 'value)))
                                       `((p
                                          ,(cond
                                            ((eq? error 'yet-to-process-revision)
                                             "Yet to process ")
                                            ((eq? error 'failed-to-process-revision)
                                             "Failed to process ")
                                            (else
                                             "Unknown issue with "))
                                          (a (@ (href ,(string-append
                                                        "https://data.qa.guix.gnu.org/revision/"
                                                        value)))
                                             "revision")))))
                                    (else
                                     #f)))))))
                           '())))))))))

  (define package-changes-div
    `(div
      (h3 "Package changes")

      ,@(if (or (not builds-missing?)
                (eq? #f systems-with-low-substitute-availability)
                (null? systems-with-low-substitute-availability)
                (not comparison-details)
                (assq-ref comparison-details 'exception)
                (and (null? derivation-changes-counts)
                     (null? cross-derivation-changes-counts)))
            '()
            ;; TODO: Only show (and apply) this if it relates to these
            ;; changes. So just look at the systems relevant to the changes.
            `((p (@ (style ,(string-join
                             '("text-align: center;"
                               "font-weight: bold;"
                               "padding: 1rem;"
                               "max-width: 46rem;"
                               "border-width: 0.35em;"
                               "border-style: dashed;"
                               "border-color: red"))))
                 "Builds for this patch series not yet submitted as "
                 (a (@ (href "/branch/master"))
                    "master branch substitute availability")
                 " is low for: "
                 ,@(append-map
                    (lambda (system)
                      `((span (@ (style "font-family: monospace; white-space: nowrap;"))
                              ,system
                              " ")))
                    systems-with-low-substitute-availability))))

      ,(package-changes-summary-table
        (let ((revisions (assoc-ref change-details "revisions")))
          `((base . ,(assoc-ref (assoc-ref revisions "base")
                                "commit"))
            (target . ,(assoc-ref (assoc-ref revisions "target")
                                  "commit"))))
        derivation-changes-counts
        (string-append "/issue/" issue-number))

      (h4 "Cross builds from "
          (code "x86_64-linux"))

      ,(package-cross-changes-summary-table
        (let ((revisions (assoc-ref change-details "revisions")))
          `((base . ,(assoc-ref (assoc-ref revisions "base")
                                "commit"))
            (target . ,(assoc-ref (assoc-ref revisions "target")
                                  "commit"))))
        cross-derivation-changes-counts
        (string-append "/issue/" issue-number))))

  (define prepare-review-section
    `(section
      (form
       (@ (action ,(simple-format #f "/issue/~A/prepare-review"
                                  issue-number)))
       (header
        (@ (style "padding: 0; margin: 0;"))
        (h3 "Mark patches as reviewed")
        (p "This feature is for people other than those involved in submitting the
patches to record a review, which will highlight that these patches should be
ready to merge.")

        (p "Here's a list of common things to check, tick them off as you review
the patches:"))

       ,@(map
          (match-lambda
            ((id label)
             `(div
               (input (@ (type "checkbox")
                         (id ,id)
                         (name ,id)))
               (label (@ (for ,id)) ,label))))
          '(("lint-warnings" "Are these changes not adding to the lint warnings?")
            ("package-builds" "Do these changes not cause packages to fail to build?")
            ("commit-messages" "Are the commit messages written well?")))

       "New packages"
       (div
        (@ (style "margin-left: 0.4em;"))
        ,@(map
           (match-lambda
             ((id label)
              `(div
                (input (@ (type "checkbox")
                          (id ,id)
                          (name ,id)))
                (label (@ (for ,id)) ,label))))
           '(("license" "Is the license information complete?")
             ("package-tests" "Are package tests being run (if available)?")
             ("synopsis-and-description"
              "Are the synopsis and description well written?"))))

       (div
        (label (@ (for "notes")) "Notes to include in the review")
        (textarea (@ (id "notes")
                     (name "notes")
                     (rows 5)
                     (style "width: 96%"))))

       (button (@ (type "submit")) "Prepare review"))))

  (layout
   #:title (simple-format #f "Issue ~A" issue-number)
   #:head
   '((style "
td.good {
  padding: 0.05rem 0.65rem;
  font-weight: bold;

  border: 0.3rem dashed green;
}

td.bad {
  padding: 0.05rem 0.65rem;
  font-weight: bold;

  border: 0.3rem dashed red;
}

div.bad {
  padding: 0.05rem 0.65rem;
  border: 0.3rem dashed red;
}

.tag {
    display: inline-block;
    padding: 0.25em 0.4em;
    margin-left: 0.25em;
    font-size: 75%;
    font-weight: 700;
    line-height: 1;
    text-align: center;
    white-space: nowrap;
    vertical-align: baseline;
    border-radius: 0.25rem;
    background-color: var(--color-accent);
}
"))
   #:body
   `((main
      ,links-div

      (h2 ,(assoc-ref series "name")
          ,@(map
             (lambda (tag)
               `(span (@ (class "tag"))
                      ,tag))
             (or mumi-tags '()))
          ,@(map
             (lambda (tag)
               `(span (@ (class "tag"))
                      "(guix) "
                      ,tag))
             (or debbugs-usertags '())))

      (h3 (@ (style ,(if (string=? branch "master")
                         ""
                         "padding-left: 0.2em; border-left-width: 0.3em; border-left-style: solid; border-left-color: orange")))
          "For branch: " (code ,branch))

      (ul
       ,@(map
          (lambda (patch)
            `(li ,(assoc-ref patch "name")))
          (vector->list
           (assoc-ref series "patches"))))

      ,@(if base-and-target-refs
            `(,lint-warnings-div
              ,package-changes-div)
            (if create-branch-for-issue-log
                `((div
                   (@ (class "bad")
                      (style "width: fit-content;"))
                   (h3 "Unable to apply "
                       ,(if (= 0 (vector-length
                                  (assoc-ref series "patches")))
                            "patch"
                            "patches"))
                   (pre ,create-branch-for-issue-log)))
                '()))

      ,prepare-review-section

      (div
       (h3 "Badges (work in progress)")
       (img
        (@ (src ,(simple-format #f "/issue/~A/status-badge-medium.svg"
                                issue-number)))))))))

(define (issue-package-changes-view issue-number
                                    derivation-changes
                                    query-parameters)
  (package-changes-view
   (simple-format #f "Issue ~A" issue-number)
   derivation-changes
   query-parameters))

(define (issue-package-cross-changes-view issue-number
                                          system
                                          cross-derivation-changes
                                          query-parameters)
  (package-cross-changes-view
   (simple-format #f "Issue ~A" issue-number)
   system
   cross-derivation-changes
   query-parameters))

(define (issue-prepare-review-view issue-number query-parameters)
  (define (escape str)
    (call-with-output-string
      (lambda (port)
        (sxml->html str port))))

  (define checkboxes
    ;; Form field name -> text in the email
    `(("lint-warnings" . "Lint warnings")
      ("package-builds" . "Package builds")
      ("commit-messages" . "Commit messages")
      ("license" . "New package licenses")
      ("package-tests" . "New package tests")
      ("synopsis-and-description" . "New package synopsis and descriptions")))

  (define email-text
    (string-append
     "user guix
usertag "
     issue-number
     " + reviewed-looks-good
thanks

Guix QA review form submission:"
     (or
      (and=> (assoc-ref query-parameters "notes")
             (lambda (notes)
               (string-append
                "\n"
                (escape notes))))
      "")
     (let ((things-checked
            (filter-map
             (lambda (param)
               (if (and (member (car param)
                                (map car checkboxes))
                        (string=? (cdr param) "on"))
                   (assoc-ref checkboxes (car param))
                   #f))
             query-parameters)))
       (if (null? things-checked)
           "\n\nNo checks recorded."
           (string-append
            "\n\nItems marked as checked: "
            (string-join things-checked ", "))))))

  (layout
   #:title (simple-format #f "Prepare review - Issue ~A" issue-number)
   #:body
   `((main
      (p "Like patches, reviews are submitted by email.")
      (a (@ (href
             ,(string-append
               "mailto:control@debbugs.gnu.org"
               (simple-format #f ",~A@debbugs.gnu.org" issue-number)
               "?"
               "subject="
               (uri-encode
                (simple-format #f "QA review for ~A" issue-number))
               "&body="
               (uri-encode email-text))))
         (b "Open mail client to send review email"))
      (p "If the above link doesn't work for you, the contents of the suggested email is given below, and can be sent "
         (strong "to control@debbugs.gnu.org and 66195@debbugs.gnu.org"))
      (pre ,email-text)))))