]> code.delx.au - gnu-emacs-elpa/blob - packages/debbugs/debbugs-gnu.el
Merge commit '67fa7e1a60966e49eccf21b02110af12afa995e0'
[gnu-emacs-elpa] / packages / debbugs / debbugs-gnu.el
1 ;;; debbugs-gnu.el --- interface for the GNU bug tracker
2
3 ;; Copyright (C) 2011-2016 Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Michael Albinus <michael.albinus@gmx.org>
7 ;; Keywords: comm, hypermedia, maint
8 ;; Package: debbugs
9
10 ;; This file is not part of GNU Emacs.
11
12 ;; This program is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
16
17 ;; This program is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24
25 ;;; Commentary:
26
27 ;; This package provides an interface to bug reports which are located
28 ;; on the GNU bug tracker debbugs.gnu.org. Its main purpose is to
29 ;; show and manipulate bug reports from Emacs, but it could be used
30 ;; also for other GNU projects which use the same bug tracker.
31
32 ;; If you have `debbugs-gnu.el' in your load-path, you could enable
33 ;; the bug tracker commands by the following lines in your ~/.emacs
34 ;;
35 ;; (autoload 'debbugs-gnu "debbugs-gnu" "" 'interactive)
36 ;; (autoload 'debbugs-gnu-search "debbugs-gnu" "" 'interactive)
37 ;; (autoload 'debbugs-gnu-usertags "debbugs-gnu" "" 'interactive)
38 ;; (autoload 'debbugs-gnu-bugs "debbugs-gnu" "" 'interactive)
39
40 ;; The bug tracker is called interactively by
41 ;;
42 ;; M-x debbugs-gnu
43
44 ;; It asks for the severities, for which bugs shall be shown. This can
45 ;; be either just one severity, or a list of severities, separated by
46 ;; comma. Valid severities are "serious", "important", "normal",
47 ;; "minor" or "wishlist". Severities "critical" and "grave" are not
48 ;; used, although configured on the GNU bug tracker. If no severity
49 ;; is given, all bugs are selected.
50
51 ;; There is also the pseudo severity "tagged". When it is used, the
52 ;; function will ask for user tags (a comma separated list), and shows
53 ;; just the bugs which are tagged with them. In general, user tags
54 ;; shall be strings denoting to subprojects of the package, like
55 ;; "cedet" or "tramp" of the package "emacs". If no user tag is
56 ;; given, locally tagged bugs are shown.
57
58 ;; If a prefix is given to the command, more search parameters are
59 ;; asked for, like packages (also a comma separated list, "emacs" is
60 ;; the default), whether archived bugs shall be shown, and whether
61 ;; closed bugs shall be suppressed from being retrieved.
62
63 ;; Another command is
64 ;;
65 ;; M-x debbugs-gnu-search
66
67 ;; It behaves like `debbugs-gnu', but asks at the beginning for a
68 ;; search phrase to be used for full text search. Additionally, it
69 ;; asks for key-value pairs to filter bugs. Keys are as described in
70 ;; `debbugs-get-status', the corresponding value must be a regular
71 ;; expression to match for. The other parameters are as described in
72 ;; `debbugs-gnu'. Usually, there is just one value except for the
73 ;; attribute "date", which needs two arguments specifying a period in
74 ;; which the bug has been submitted or modified.
75
76 ;; The bug reports are downloaded from the bug tracker. In order to
77 ;; not generate too much load of the server, up to 500 bugs will be
78 ;; downloaded at once. If there are more hits, several downloads will
79 ;; be performed, until all bugs are retrieved.
80
81 ;; These default values could be changed also by customer options
82 ;; `debbugs-gnu-default-severities', `debbugs-gnu-default-packages'
83 ;; and `debbugs-gnu-default-suppress-bugs'.
84
85 ;; The commands create a page of bug lists. Every bug is shown in one
86 ;; line, including the bug number, the status (combining merged bug
87 ;; numbers, keywords and severities), the name of the submitter, and
88 ;; the title of the bug. On every bug line you could apply the
89 ;; following actions by the following keystrokes:
90
91 ;; RET: Show corresponding messages in Gnus/Rmail
92 ;; "C": Send a control message
93 ;; "t": Mark the bug locally as tagged
94 ;; "b": Show bugs this bug is blocked by
95 ;; "B": Show bugs this bug is blocking
96 ;; "d": Show bug attributes
97
98 ;; Furthermore, you could apply the global actions
99
100 ;; "g": Rescan bugs
101 ;; "q": Quit the buffer
102 ;; "s": Toggle bug sorting for age or for state
103 ;; "x": Toggle suppressing of bugs
104 ;; "/": Display only bugs matching a string
105 ;; "R": Display only bugs blocking the current release
106 ;; "w": Display all the currently selected bug reports
107
108 ;; When you visit the related bug messages in Gnus or Rmail, you could
109 ;; also send control messages by keystroke "C".
110
111 ;; In the header line of every bug list page, you can toggle sorting
112 ;; per column by selecting a column with the mouse. The sorting
113 ;; happens as expected for the respective column; sorting in the Title
114 ;; column is depending on whether you are the owner of a bug.
115
116 ;; Another approach for listing bugs is calling the command
117 ;;
118 ;; M-x debbugs-gnu-usertags
119
120 ;; This command shows you all existing user tags for the packages
121 ;; defined in `debbugs-gnu-default-packages'. A prefix for the
122 ;; command allows you to use other package names, or an arbitrary
123 ;; string for a user who has tagged bugs. The command returns the
124 ;; list of existing user tags for the given user(s) or package
125 ;; name(s), respectively. Applying RET on a user tag, all bugs tagged
126 ;; with this user tag are shown.
127
128 ;; Unfortunately, it is not possible with the SOAP interface to show
129 ;; all users who have tagged bugs. This list can be retrieved via
130 ;; <http://debbugs.gnu.org/cgi/pkgindex.cgi?indexon=users>.
131
132 ;; Finally, if you simply want to list some bugs with known bug
133 ;; numbers, call the command
134 ;;
135 ;; M-x debbugs-gnu-bugs
136
137 ;; The bug numbers to be shown shall be entered as comma separated list.
138
139 ;;; Code:
140
141 (require 'debbugs)
142 (require 'tabulated-list)
143 (require 'add-log)
144 (require 'subr-x)
145 (eval-when-compile (require 'cl))
146
147 (autoload 'article-decode-charset "gnus-art")
148 (autoload 'diff-goto-source "diff-mode")
149 (autoload 'diff-hunk-file-names "diff-mode")
150 (autoload 'gnus-article-mime-handles "gnus-art")
151 (autoload 'gnus-fetch-field "gnus-util")
152 (autoload 'gnus-read-ephemeral-emacs-bug-group "gnus-group")
153 (autoload 'gnus-summary-article-header "gnus-sum")
154 (autoload 'gnus-summary-select-article "gnus-sum")
155 (autoload 'gnus-summary-show-article "gnus-sum")
156 (autoload 'gnus-with-article-buffer "gnus-art")
157 (autoload 'log-edit-insert-changelog "log-edit")
158 (autoload 'mail-header-subject "nnheader")
159 (autoload 'message-goto-body "message")
160 (autoload 'message-make-from "message")
161 (autoload 'rmail-get-new-mail "rmail")
162 (autoload 'rmail-show-message "rmail")
163 (autoload 'rmail-summary "rmailsum")
164 (autoload 'vc-dir-hide-up-to-date "vc-dir")
165 (autoload 'vc-dir-mark "vc-dir")
166
167 (defvar compilation-in-progress)
168 (defvar diff-file-header-re)
169 (defvar gnus-article-buffer)
170 (defvar gnus-posting-styles)
171 (defvar gnus-save-duplicate-list)
172 (defvar gnus-suppress-duplicates)
173 (defvar rmail-current-message)
174 (defvar rmail-mode-map)
175 (defvar rmail-summary-mode-map)
176 (defvar rmail-total-messages)
177
178 ;; Buffer-local variables.
179 (defvar debbugs-gnu-local-query)
180 (defvar debbugs-gnu-local-filter)
181 (defvar debbugs-gnu-local-suppress)
182 (defvar debbugs-gnu-sort-state)
183 (defvar debbugs-gnu-limit)
184
185 (defgroup debbugs-gnu ()
186 "UI for the debbugs.gnu.org bug tracker."
187 :group 'debbugs
188 :version "24.1")
189
190 (defvar debbugs-gnu-blocking-report 19759
191 "The ID of the current release report used to track blocking bug reports.")
192
193 (defcustom debbugs-gnu-default-severities '("serious" "important" "normal")
194 "*The list severities bugs are searched for.
195 \"tagged\" is not a severity but marks locally tagged bugs."
196 ;; <http://debbugs.gnu.org/Developer.html#severities>
197 ;; /ssh:debbugs:/etc/debbugs/config @gSeverityList
198 ;; We don't use "critical" and "grave".
199 :group 'debbugs-gnu
200 :type '(set (const "serious")
201 (const "important")
202 (const "normal")
203 (const "minor")
204 (const "wishlist")
205 (const "tagged"))
206 :version "24.1")
207
208 (defconst debbugs-gnu-all-severities
209 (mapcar 'cadr (cdr (get 'debbugs-gnu-default-severities 'custom-type)))
210 "*List of all possible severities.")
211
212 (defcustom debbugs-gnu-default-packages '("emacs")
213 "*The list of packages to be searched for."
214 ;; <http://debbugs.gnu.org/Packages.html>
215 ;; <http://debbugs.gnu.org/cgi/pkgindex.cgi>
216 :group 'debbugs-gnu
217 :type '(set (const "adns")
218 (const "auctex")
219 (const "automake")
220 (const "cc-mode")
221 (const "coreutils")
222 (const "cppi")
223 (const "debbugs.gnu.org")
224 (const "diffutils")
225 (const "emacs")
226 (const "emacs-xwidgets")
227 (const "fm")
228 (const "gnus")
229 (const "grep")
230 (const "guile")
231 (const "guix")
232 (const "gzip")
233 (const "idutils")
234 (const "libtool")
235 (const "mh-e")
236 (const "org-mode")
237 (const "parted")
238 (const "sed")
239 (const "vc-dwim")
240 (const "woodchuck"))
241 :version "25.1")
242
243 (defconst debbugs-gnu-all-packages
244 (mapcar 'cadr (cdr (get 'debbugs-gnu-default-packages 'custom-type)))
245 "*List of all possible package names.")
246
247 (defcustom debbugs-gnu-default-suppress-bugs
248 '((pending . "done"))
249 "*A list of specs for bugs to be suppressed.
250 An element of this list is a cons cell \(KEY . REGEXP\), with key
251 being returned by `debbugs-get-status', and REGEXP a regular
252 expression matching the corresponding value, a string. Showing
253 suppressed bugs is toggled by `debbugs-gnu-toggle-suppress'."
254 :group 'debbugs-gnu
255 :type '(alist :key-type symbol :value-type regexp)
256 :version "24.1")
257
258 (defcustom debbugs-gnu-mail-backend 'gnus
259 "*The email backend to use for reading bug report email exchange.
260 If this is 'gnus, the default, use Gnus.
261 If this is 'rmail, use Rmail instead."
262 :group 'debbugs-gnu
263 :type '(choice (const :tag "Use Gnus" 'gnus)
264 (const :tag "Use Rmail" 'rmail))
265 :version "25.1")
266
267 (defface debbugs-gnu-archived '((t (:inverse-video t)))
268 "Face for archived bug reports.")
269
270 (defface debbugs-gnu-new '((t (:foreground "red")))
271 "Face for new reports that nobody has answered.")
272
273 (defface debbugs-gnu-handled '((t (:foreground "ForestGreen")))
274 "Face for reports that have been modified recently.")
275
276 (defface debbugs-gnu-pending '((t (:foreground "MidnightBlue")))
277 "Face for reports that are pending.")
278
279 (defface debbugs-gnu-stale '((t (:foreground "orange")))
280 "Face for reports that have not been touched for two weeks.")
281
282 (defface debbugs-gnu-done '((t (:foreground "DarkGrey")))
283 "Face for closed bug reports.")
284
285 (defface debbugs-gnu-tagged '((t (:foreground "red")))
286 "Face for reports that have been tagged locally.")
287
288 (defvar debbugs-gnu-local-tags nil
289 "List of bug numbers tagged locally, and kept persistent.")
290
291 (defvar debbugs-gnu-persistency-file
292 (expand-file-name (locate-user-emacs-file "debbugs"))
293 "File name of a persistency store for debbugs variables")
294
295 (defun debbugs-gnu-dump-persistency-file ()
296 "Function to store debbugs variables persistently."
297 (with-temp-file debbugs-gnu-persistency-file
298 (insert
299 ";; -*- emacs-lisp -*-\n"
300 ";; Debbugs tags connection history. Don't change this file.\n\n"
301 (format "(setq debbugs-gnu-local-tags '%S)"
302 (sort (copy-sequence debbugs-gnu-local-tags) '>)))))
303
304 (defvar debbugs-gnu-current-query nil
305 "The query object of the current search.
306 It will be applied server-side, when calling `debbugs-get-bugs'.
307 It has the same format as `debbugs-gnu-default-suppress-bugs'.")
308
309 (defvar debbugs-gnu-current-filter nil
310 "The filter object for the current search.
311 It will be applied client-side, when parsing the results of
312 `debbugs-get-status'. It has a similar format as
313 `debbugs-gnu-default-suppress-bugs'. In case of keys representing
314 a date, value is the cons cell \(BEFORE . AFTER\).")
315
316 (defvar debbugs-gnu-current-suppress nil
317 "Whether bugs shall be suppressed.
318 The specification which bugs shall be suppressed is taken from
319 `debbugs-gnu-default-suppress-bugs'.")
320
321 (defun debbugs-gnu-calendar-read (prompt acceptable &optional initial-contents)
322 "Return a string read from the minibuffer.
323 Derived from `calendar-read'."
324 (let ((value (read-string prompt initial-contents)))
325 (while (not (funcall acceptable value))
326 (setq value (read-string prompt initial-contents)))
327 value))
328
329 (defconst debbugs-gnu-phrase-prompt
330 (propertize
331 "Enter search phrase: "
332 'help-echo "\
333 The search phrase contains words to be searched for, combined by
334 operators like AND, ANDNOT and OR. If there is no operator
335 between the words, AND is used by default. The phrase can also
336 be empty, in this case only the following attributes are used for
337 search."))
338
339 ;;;###autoload
340 (defun debbugs-gnu-search ()
341 "Search for Emacs bugs interactively.
342 Search arguments are requested interactively. The \"search
343 phrase\" is used for full text search in the bugs database.
344 Further key-value pairs are requested until an empty key is
345 returned. If a key cannot be queried by a SOAP request, it is
346 marked as \"client-side filter\"."
347 (interactive)
348
349 (unwind-protect
350 (let ((date-format "\\([[:digit:]]\\{4\\}\\)-\\([[:digit:]]\\{1,2\\}\\)-\\([[:digit:]]\\{1,2\\}\\)")
351 key val1 val2 phrase severities packages archivedp)
352
353 ;; Check for the phrase.
354 (setq phrase (read-string debbugs-gnu-phrase-prompt))
355 (if (zerop (length phrase))
356 (setq phrase nil)
357 (add-to-list 'debbugs-gnu-current-query (cons 'phrase phrase)))
358 ;; We suppress closed bugs if there is no phrase.
359 (setq debbugs-gnu-current-suppress (null phrase))
360
361 ;; The other queries.
362 (catch :finished
363 (while t
364 (setq key (completing-read
365 "Enter attribute: "
366 (if phrase
367 '("severity" "package" "tags" "submitter" "date"
368 "subject" "status")
369 '("severity" "package" "archive" "src" "tag"
370 "owner" "submitter" "maint" "correspondent"
371 "date" "log_modified" "last_modified"
372 "found_date" "fixed_date" "unarchived"
373 "subject" "done" "forwarded" "msgid" "summary"))
374 nil t))
375 (cond
376 ;; Server-side queries.
377 ((equal key "severity")
378 (setq
379 severities
380 (completing-read-multiple
381 "Enter severities: " debbugs-gnu-all-severities nil t
382 (mapconcat 'identity debbugs-gnu-default-severities ","))))
383
384 ((equal key "package")
385 (setq
386 packages
387 (completing-read-multiple
388 "Enter packages: " debbugs-gnu-all-packages nil t
389 (mapconcat 'identity debbugs-gnu-default-packages ","))))
390
391 ((equal key "archive")
392 ;; We simplify, by assuming just archived bugs are requested.
393 (setq archivedp t))
394
395 ((member key '("src" "tag" "tags"))
396 (setq val1 (read-string (format "Enter %s: " key)))
397 (when (not (zerop (length val1)))
398 (add-to-list
399 'debbugs-gnu-current-query (cons (intern key) val1))))
400
401 ((member key '("owner" "submitter" "maint" "correspondent"))
402 (setq val1 (read-string "Enter email address: "))
403 (when (not (zerop (length val1)))
404 (add-to-list
405 'debbugs-gnu-current-query (cons (intern key) val1))))
406
407 ((equal key "status")
408 (setq
409 val1
410 (completing-read "Enter status: " '("done" "forwarded" "open")))
411 (when (not (zerop (length val1)))
412 (add-to-list
413 'debbugs-gnu-current-query (cons (intern key) val1))))
414
415 ;; Client-side filters.
416 ((member key '("date" "log_modified" "last_modified"
417 "found_date" "fixed_date" "unarchived"))
418 (setq val1
419 (debbugs-gnu-calendar-read
420 (format "Enter %s before YYYY-MM-DD%s: "
421 key (if phrase "" " (client-side filter)"))
422 (lambda (x)
423 (string-match (concat "^\\(" date-format "\\|\\)$") x))))
424 (if (string-match date-format val1)
425 (setq val1 (floor
426 (float-time
427 (encode-time
428 0 0 0
429 (string-to-number (match-string 3 val1))
430 (string-to-number (match-string 2 val1))
431 (string-to-number (match-string 1 val1))))))
432 (setq val1 nil))
433 (setq val2
434 (debbugs-gnu-calendar-read
435 (format "Enter %s after YYYY-MM-DD%s: "
436 key (if phrase "" " (client-side filter)"))
437 (lambda (x)
438 (string-match (concat "^\\(" date-format "\\|\\)$") x))))
439 (if (string-match date-format val2)
440 (setq val2 (floor
441 (float-time
442 (encode-time
443 0 0 0
444 (string-to-number (match-string 3 val2))
445 (string-to-number (match-string 2 val2))
446 (string-to-number (match-string 1 val2))))))
447 (setq val2 nil))
448 (when (or val1 val2)
449 (add-to-list
450 (if phrase
451 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
452 (cons (intern key) (cons val1 val2)))))
453
454 ((not (zerop (length key)))
455 (setq val1
456 (funcall
457 (if phrase 'read-string 'read-regexp)
458 (format "Enter %s%s"
459 key (if phrase ": " " (client-side filter)"))))
460 (when (not (zerop (length val1)))
461 (add-to-list
462 (if phrase
463 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
464 (cons (intern key) val1))))
465
466 ;; The End.
467 (t (throw :finished nil)))))
468
469 ;; Do the search.
470 (debbugs-gnu severities packages archivedp))))
471
472 ;;;###autoload
473 (defun debbugs-gnu (severities &optional packages archivedp suppress tags)
474 "List all outstanding bugs."
475 (interactive
476 (let (severities archivedp)
477 (list
478 (setq severities
479 (completing-read-multiple
480 "Severities: " debbugs-gnu-all-severities nil t
481 (mapconcat 'identity debbugs-gnu-default-severities ",")))
482 ;; The next parameters are asked only when there is a prefix.
483 (if current-prefix-arg
484 (completing-read-multiple
485 "Packages: " debbugs-gnu-all-packages nil t
486 (mapconcat 'identity debbugs-gnu-default-packages ","))
487 debbugs-gnu-default-packages)
488 (when current-prefix-arg
489 (setq archivedp (y-or-n-p "Show archived bugs?")))
490 (when (and current-prefix-arg (not archivedp))
491 (y-or-n-p "Suppress unwanted bugs?"))
492 ;; This one must be asked for severity "tagged".
493 (when (member "tagged" severities)
494 (split-string (read-string "User tag(s): ") "," t)))))
495
496 ;; Initialize variables.
497 (when (and (file-exists-p debbugs-gnu-persistency-file)
498 (not debbugs-gnu-local-tags))
499 (with-temp-buffer
500 (insert-file-contents debbugs-gnu-persistency-file)
501 (eval (read (current-buffer)))))
502 ;; Per default, we suppress retrieved unwanted bugs.
503 (when (called-interactively-p 'any)
504 (setq debbugs-gnu-current-suppress t))
505
506 ;; Add queries.
507 (dolist (severity (if (consp severities) severities (list severities)))
508 (when (not (zerop (length severity)))
509 (when (string-equal severity "tagged")
510 (setq debbugs-gnu-current-suppress nil))
511 (add-to-list 'debbugs-gnu-current-query (cons 'severity severity))))
512 (dolist (package (if (consp packages) packages (list packages)))
513 (when (not (zerop (length package)))
514 (add-to-list 'debbugs-gnu-current-query (cons 'package package))))
515 (when archivedp
516 (setq debbugs-gnu-current-suppress nil)
517 (add-to-list 'debbugs-gnu-current-query '(archive . "1")))
518 (when suppress
519 (setq debbugs-gnu-current-suppress t)
520 (add-to-list 'debbugs-gnu-current-query '(status . "open"))
521 (add-to-list 'debbugs-gnu-current-query '(status . "forwarded")))
522 (dolist (tag (if (consp tags) tags (list tags)))
523 (when (not (zerop (length tag)))
524 (add-to-list 'debbugs-gnu-current-query (cons 'tag tag))))
525
526 ;; Show result.
527 (debbugs-gnu-show-reports)
528
529 ;; Reset query, filter and suppress.
530 (setq debbugs-gnu-current-query nil
531 debbugs-gnu-current-filter nil
532 debbugs-gnu-current-suppress nil))
533
534 (defun debbugs-gnu-get-bugs (query)
535 "Retrieve bug numbers from debbugs.gnu.org according search criteria."
536 (let* ((debbugs-port "gnu.org")
537 (bugs (assoc 'bugs query))
538 (tags (assoc 'tag query))
539 (local-tags (and (member '(severity . "tagged") query) (not tags)))
540 (phrase (assoc 'phrase query))
541 args)
542 ;; Compile query arguments.
543 (unless (or query tags)
544 (dolist (elt debbugs-gnu-default-packages)
545 (setq args (append args (list :package elt)))))
546 (dolist (elt query)
547 (unless (equal elt '(severity . "tagged"))
548 (setq args
549 (append
550 args
551 (if phrase
552 (cond
553 ((eq (car elt) 'phrase)
554 (list (list :phrase (cdr elt))))
555 ((eq (car elt) 'date)
556 (list (list :date (cddr elt) (cadr elt)
557 :operator "NUMBT")))
558 (t
559 (list (list (intern (concat ":" (symbol-name (car elt))))
560 (cdr elt) :operator "ISTRINC"))))
561 (list (intern (concat ":" (symbol-name (car elt))))
562 (cdr elt)))))))
563
564 (cond
565 ;; If the query is just a list of bug numbers, we return them.
566 (bugs (cdr bugs))
567 ;; If the query contains the pseudo-severity "tagged", we return
568 ;; just the local tagged bugs.
569 (local-tags (copy-sequence debbugs-gnu-local-tags))
570 ;; A full text query.
571 (phrase
572 (mapcar
573 (lambda (x) (cdr (assoc "id" x)))
574 (apply 'debbugs-search-est args)))
575 ;; User tags.
576 (tags
577 (setq args (mapcar (lambda (x) (if (eq x :package) :user x)) args))
578 (apply 'debbugs-get-usertag args))
579 ;; Otherwise, we retrieve the bugs from the server.
580 (t (apply 'debbugs-get-bugs args)))))
581
582 (defun debbugs-gnu-show-reports (&optional offline)
583 "Show bug reports.
584 If OFFLINE is non-nil, the query is not sent to the server. Bugs
585 are taken from the cache instead."
586 (let ((inhibit-read-only t)
587 (buffer-name "*Emacs Bugs*"))
588 ;; The tabulated mode sets several local variables. We must get
589 ;; rid of them.
590 (when (get-buffer buffer-name)
591 (kill-buffer buffer-name))
592 (switch-to-buffer (get-buffer-create buffer-name))
593 (debbugs-gnu-mode)
594
595 ;; Print bug reports.
596 (dolist (status
597 (let ((debbugs-cache-expiry (if offline nil debbugs-cache-expiry))
598 ids)
599 (apply 'debbugs-get-status
600 (if offline
601 (progn
602 (maphash (lambda (key _elem)
603 (push key ids))
604 debbugs-cache-data)
605 (sort ids '<))
606 (debbugs-gnu-get-bugs debbugs-gnu-local-query)))))
607 (let* ((id (cdr (assq 'id status)))
608 (words
609 (mapconcat
610 'identity
611 (cons (cdr (assq 'severity status))
612 (cdr (assq 'keywords status)))
613 ","))
614 (address (if (cdr (assq 'originator status))
615 (mail-header-parse-address
616 (decode-coding-string (cdr (assq 'originator status))
617 'utf-8))))
618 (owner (if (cdr (assq 'owner status))
619 (car (mail-header-parse-address
620 (decode-coding-string (cdr (assq 'owner status))
621 'utf-8)))))
622 (subject (if (cdr (assq 'subject status))
623 (decode-coding-string (cdr (assq 'subject status))
624 'utf-8)))
625 merged)
626 (unless (equal (cdr (assq 'pending status)) "pending")
627 (setq words (concat words "," (cdr (assq 'pending status)))))
628 (let ((packages (delete "emacs" (cdr (assq 'package status)))))
629 (when packages
630 (setq words (concat words "," (mapconcat 'identity packages ",")))))
631 (when (setq merged (cdr (assq 'mergedwith status)))
632 (setq words (format "%s,%s"
633 (if (numberp merged)
634 merged
635 (mapconcat 'number-to-string merged ","))
636 words)))
637 (when (or (not merged)
638 (not (let ((found nil))
639 (dolist (id (if (listp merged)
640 merged
641 (list merged)))
642 (dolist (entry tabulated-list-entries)
643 (when (equal id (cdr (assq 'id (car entry))))
644 (setq found t))))
645 found)))
646 (add-to-list
647 'tabulated-list-entries
648 (list
649 status
650 (vector
651 (propertize
652 (format "%5d" id)
653 'face
654 ;; Mark tagged bugs.
655 (if (memq id debbugs-gnu-local-tags)
656 'debbugs-gnu-tagged
657 'default))
658 (propertize
659 ;; Mark status and age.
660 (or words "")
661 'face
662 (cond
663 ((cdr (assq 'archived status))
664 'debbugs-gnu-archived)
665 ((equal (cdr (assq 'pending status)) "done")
666 'debbugs-gnu-done)
667 ((member "pending" (cdr (assq 'keywords status)))
668 'debbugs-gnu-pending)
669 ((= (cdr (assq 'date status))
670 (cdr (assq 'log_modified status)))
671 'debbugs-gnu-new)
672 ((< (- (float-time)
673 (cdr (assq 'log_modified status)))
674 (* 60 60 24 7 2))
675 'debbugs-gnu-handled)
676 (t
677 'debbugs-gnu-stale)))
678 (propertize
679 ;; Prefer the name over the address.
680 (or (cdr address)
681 (car address)
682 "")
683 'face
684 ;; Mark own submitted bugs.
685 (if (and (stringp (car address))
686 (string-equal (car address) user-mail-address))
687 'debbugs-gnu-tagged
688 'default))
689 (propertize
690 (or subject "")
691 'face
692 ;; Mark owned bugs.
693 (if (and (stringp owner)
694 (string-equal owner user-mail-address))
695 'debbugs-gnu-tagged
696 'default))))
697 'append))))
698
699 (tabulated-list-init-header)
700 (tabulated-list-print)
701
702 (set-buffer-modified-p nil)
703 (goto-char (point-min))))
704
705 (defun debbugs-gnu-print-entry (list-id cols)
706 "Insert a debbugs entry at point.
707 Used instead of `tabulated-list-print-entry'."
708 (let ((beg (point))
709 (pos 0)
710 (case-fold-search t)
711 (id (aref cols 0))
712 (id-length (nth 1 (aref tabulated-list-format 0)))
713 (state (aref cols 1))
714 (state-length (nth 1 (aref tabulated-list-format 1)))
715 (submitter (aref cols 2))
716 (submitter-length (nth 1 (aref tabulated-list-format 2)))
717 (title (aref cols 3))
718 (title-length (nth 1 (aref tabulated-list-format 3))))
719 (when (and
720 ;; We may have a narrowing in effect.
721 (or (not debbugs-gnu-limit)
722 (memq (cdr (assq 'id list-id)) debbugs-gnu-limit))
723 ;; Filter suppressed bugs.
724 (or (not debbugs-gnu-local-suppress)
725 (not (catch :suppress
726 (dolist (check debbugs-gnu-default-suppress-bugs)
727 (when
728 (string-match
729 (cdr check)
730 (or (cdr (assq (car check) list-id)) ""))
731 (throw :suppress t))))))
732 ;; Filter search list.
733 (not (catch :suppress
734 (dolist (check debbugs-gnu-local-filter)
735 (let ((val (cdr (assq (car check) list-id))))
736 (if (stringp (cdr check))
737 ;; Regular expression.
738 (when (not (string-match (cdr check) (or val "")))
739 (throw :suppress t))
740 ;; Time value.
741 (when (or (and (numberp (cadr check))
742 (< (cadr check) val))
743 (and (numberp (cddr check))
744 (> (cddr check) val)))
745 (throw :suppress t))))))))
746
747 ;; Insert id.
748 (indent-to (- id-length (length id)))
749 (insert id)
750 ;; Insert state.
751 (indent-to (setq pos (+ pos id-length 1)) 1)
752 (insert (if (> (length state) state-length)
753 (propertize (substring state 0 state-length)
754 'help-echo state)
755 state))
756 ;; Insert submitter.
757 (indent-to (setq pos (+ pos state-length 1)) 1)
758 (insert "[" (if (> (length submitter) (- submitter-length 2))
759 (propertize (substring submitter 0 (- submitter-length 2))
760 'help-echo submitter)
761 submitter))
762 (indent-to (+ pos (1- submitter-length)))
763 (insert "]")
764 ;; Insert title.
765 (indent-to (setq pos (+ pos submitter-length 1)) 1)
766 (insert (propertize title 'help-echo title))
767 ;; Add properties.
768 (add-text-properties
769 beg (point)
770 `(tabulated-list-id ,list-id mouse-face highlight))
771 (insert ?\n))))
772
773 (defun debbugs-gnu-menu-map-emacs-enabled ()
774 "Whether \"Show Release Blocking Bugs\" is enabled in the menu."
775 (or ;; No package discriminator has been used.
776 (not (assq 'package debbugs-gnu-local-query))
777 ;; Package "emacs" has been selected.
778 (member '(package . "emacs") debbugs-gnu-local-query)))
779
780 (defconst debbugs-gnu-bug-triage-file
781 (expand-file-name "../admin/notes/bug-triage" data-directory)
782 "The \"bug-triage\" file.")
783
784 (defun debbugs-gnu-menu-map-bug-triage-enabled ()
785 "Whether \"Describe Bug Triage Procedure\" is enabled in the menu."
786 (and (debbugs-gnu-menu-map-emacs-enabled)
787 (stringp debbugs-gnu-bug-triage-file)
788 (file-readable-p debbugs-gnu-bug-triage-file)))
789
790 (defun debbugs-gnu-view-bug-triage ()
791 "Show \"bug-triage\" file."
792 (interactive)
793 (view-file debbugs-gnu-bug-triage-file))
794
795 (defvar debbugs-gnu-mode-map
796 (let ((map (make-sparse-keymap))
797 (menu-map (make-sparse-keymap)))
798 (set-keymap-parent map tabulated-list-mode-map)
799 (define-key map "\r" 'debbugs-gnu-select-report)
800 (define-key map [mouse-1] 'debbugs-gnu-select-report)
801 (define-key map [mouse-2] 'debbugs-gnu-select-report)
802 (define-key map "g" 'debbugs-gnu-rescan)
803 (define-key map "R" 'debbugs-gnu-show-all-blocking-reports)
804 (define-key map "C" 'debbugs-gnu-send-control-message)
805
806 (define-key map "s" 'debbugs-gnu-toggle-sort)
807 (define-key map "t" 'debbugs-gnu-toggle-tag)
808 (define-key map "x" 'debbugs-gnu-toggle-suppress)
809 (define-key map "/" 'debbugs-gnu-narrow-to-status)
810 (define-key map "w" 'debbugs-gnu-widen)
811
812 (define-key map "b" 'debbugs-gnu-show-blocked-by-reports)
813 (define-key map "B" 'debbugs-gnu-show-blocking-reports)
814 (define-key map "d" 'debbugs-gnu-display-status)
815
816 (define-key map [menu-bar debbugs] (cons "Debbugs" menu-map))
817 (define-key menu-map [debbugs-gnu-select-report]
818 '(menu-item "Show Reports" debbugs-gnu-select-report
819 :help "Show all reports belonging to this bug"))
820 (define-key-after menu-map [debbugs-gnu-rescan]
821 '(menu-item "Refresh Bugs" debbugs-gnu-rescan
822 :help "Refresh bug list")
823 'debbugs-gnu-select-report)
824 (define-key-after menu-map [debbugs-gnu-show-all-blocking-reports]
825 '(menu-item "Show Release Blocking Bugs"
826 debbugs-gnu-show-all-blocking-reports
827 :enable (debbugs-gnu-menu-map-emacs-enabled)
828 :help "Show all bugs blocking next Emacs release")
829 'debbugs-gnu-rescan)
830 (define-key-after menu-map [debbugs-gnu-send-control-message]
831 '(menu-item "Send Control Message"
832 debbugs-gnu-send-control-message
833 :help "Send control message to debbugs.gnu.org")
834 'debbugs-gnu-show-all-blocking-reports)
835
836 (define-key-after menu-map [debbugs-gnu-separator1]
837 '(menu-item "--") 'debbugs-gnu-send-control-message)
838 (define-key-after menu-map [debbugs-gnu-search]
839 '(menu-item "Search Bugs" debbugs-gnu-search
840 :help "Search bugs on debbugs.gnu.org")
841 'debbugs-gnu-separator1)
842 (define-key-after menu-map [debbugs-gnu]
843 '(menu-item "Retrieve Bugs" debbugs-gnu
844 :help "Retrieve bugs from debbugs.gnu.org")
845 'debbugs-gnu-search)
846 (define-key-after menu-map [debbugs-gnu-bugs]
847 '(menu-item "Retrieve Bugs by Number" debbugs-gnu-bugs
848 :help "Retrieve selected bugs from debbugs.gnu.org")
849 'debbugs-gnu)
850
851 (define-key-after menu-map [debbugs-gnu-separator2]
852 '(menu-item "--") 'debbugs-gnu-bugs)
853 (define-key-after menu-map [debbugs-gnu-view-bug-triage]
854 '(menu-item "Describe Bug Triage Procedure"
855 debbugs-gnu-view-bug-triage
856 :enable (debbugs-gnu-menu-map-bug-triage-enabled)
857 :help "Show procedure of triaging bugs")
858 'debbugs-gnu-separator2)
859 map))
860
861 (defun debbugs-gnu-rescan ()
862 "Rescan the current set of bug reports."
863 (interactive)
864 (let ((id (debbugs-gnu-current-id))
865 (debbugs-gnu-current-query debbugs-gnu-local-query)
866 (debbugs-gnu-current-filter debbugs-gnu-local-filter)
867 (debbugs-gnu-current-suppress debbugs-gnu-local-suppress)
868 (debbugs-cache-expiry (if current-prefix-arg t debbugs-cache-expiry)))
869 (debbugs-gnu-show-reports)
870 (when id
871 (debbugs-gnu-goto id))))
872
873 (define-derived-mode debbugs-gnu-mode tabulated-list-mode "Debbugs"
874 "Major mode for listing bug reports.
875
876 All normal editing commands are switched off.
877 \\<debbugs-gnu-mode-map>
878
879 The following commands are available:
880
881 \\{debbugs-gnu-mode-map}"
882 (set (make-local-variable 'debbugs-gnu-sort-state) 'number)
883 (set (make-local-variable 'debbugs-gnu-limit) nil)
884 (set (make-local-variable 'debbugs-gnu-local-query)
885 debbugs-gnu-current-query)
886 (set (make-local-variable 'debbugs-gnu-local-filter)
887 debbugs-gnu-current-filter)
888 (set (make-local-variable 'debbugs-gnu-local-suppress)
889 debbugs-gnu-current-suppress)
890 (setq tabulated-list-format [("Id" 5 debbugs-gnu-sort-id)
891 ("State" 20 debbugs-gnu-sort-state)
892 ("Submitter" 25 t)
893 ("Title" 10 debbugs-gnu-sort-title)])
894 (setq tabulated-list-sort-key (cons "Id" nil))
895 (setq tabulated-list-printer 'debbugs-gnu-print-entry)
896 (buffer-disable-undo)
897 (setq truncate-lines t)
898 (setq buffer-read-only t))
899
900 (defun debbugs-gnu-sort-id (s1 s2)
901 (> (cdr (assq 'id (car s1)))
902 (cdr (assq 'id (car s2)))))
903
904 (defconst debbugs-gnu-state-preference
905 '((debbugs-gnu-new . 1)
906 (debbugs-gnu-stale . 2)
907 (debbugs-gnu-handled . 3)
908 (debbugs-gnu-done . 4)
909 (debbugs-gnu-pending . 5)))
910
911 (defun debbugs-gnu-get-state-preference (face-string)
912 (or (cdr (assq (get-text-property 0 'face face-string)
913 debbugs-gnu-state-preference))
914 10))
915
916 (defconst debbugs-gnu-severity-preference
917 '(("serious" . 1)
918 ("important" . 2)
919 ("normal" . 3)
920 ("minor" . 4)
921 ("wishlist" . 5)))
922
923 (defun debbugs-gnu-get-severity-preference (state)
924 (or (cdr (assoc (cdr (assq 'severity state))
925 debbugs-gnu-severity-preference))
926 10))
927
928 (defun debbugs-gnu-sort-state (s1 s2)
929 (let ((id1 (cdr (assq 'id (car s1))))
930 (age1 (debbugs-gnu-get-state-preference (aref (nth 1 s1) 1)))
931 (id2 (cdr (assq 'id (car s2))))
932 (age2 (debbugs-gnu-get-state-preference (aref (nth 1 s2) 1))))
933 (cond
934 ;; Tagged bugs go to the end.
935 ((and (not (memq id1 debbugs-gnu-local-tags))
936 (memq id2 debbugs-gnu-local-tags))
937 t)
938 ((and (memq id1 debbugs-gnu-local-tags)
939 (not (memq id2 debbugs-gnu-local-tags)))
940 nil)
941 ;; Then, we check the age of the bugs.
942 ((< age1 age2)
943 t)
944 ((> age1 age2)
945 nil)
946 ;; If they have the same age, we check for severity.
947 ((< (debbugs-gnu-get-severity-preference (car s1))
948 (debbugs-gnu-get-severity-preference (car s2)))
949 t)
950 (t nil))))
951
952 (defun debbugs-gnu-sort-title (s1 s2)
953 (let ((owner (if (cdr (assq 'owner (car s1)))
954 (car (mail-header-parse-address
955 (decode-coding-string (cdr (assq 'owner (car s1)))
956 'utf-8))))))
957 (and (stringp owner)
958 (string-equal owner user-mail-address))))
959
960 (defun debbugs-gnu-toggle-sort ()
961 "Toggle sorting by age and by state."
962 (interactive)
963 (if (eq debbugs-gnu-sort-state 'number)
964 (progn
965 (setq debbugs-gnu-sort-state 'state)
966 (setq tabulated-list-sort-key (cons "Id" nil)))
967 (setq debbugs-gnu-sort-state 'number)
968 (setq tabulated-list-sort-key (cons "State" nil)))
969 (tabulated-list-init-header)
970 (tabulated-list-print))
971
972 (defun debbugs-gnu-widen ()
973 "Display all the currently selected bug reports."
974 (interactive)
975 (let ((id (debbugs-gnu-current-id t))
976 (inhibit-read-only t))
977 (setq debbugs-gnu-limit nil)
978 (tabulated-list-init-header)
979 (tabulated-list-print)
980 (when id
981 (debbugs-gnu-goto id))))
982
983 (defun debbugs-gnu-show-blocked-by-reports ()
984 "Display all bug reports this report is blocked by."
985 (interactive)
986 (let ((id (debbugs-gnu-current-id))
987 (status (debbugs-gnu-current-status)))
988 (if (null (cdr (assq 'blockedby status)))
989 (message "Bug %d is not blocked by any other bug" id)
990 (apply 'debbugs-gnu-bugs (cdr (assq 'blockedby status))))))
991
992 (defun debbugs-gnu-show-blocking-reports ()
993 "Display all bug reports this report is blocking."
994 (interactive)
995 (let ((id (debbugs-gnu-current-id))
996 (status (debbugs-gnu-current-status)))
997 (if (null (cdr (assq 'blocks status)))
998 (message "Bug %d is not blocking any other bug" id)
999 (apply 'debbugs-gnu-bugs (cdr (assq 'blocks status))))))
1000
1001 (defun debbugs-gnu-show-all-blocking-reports ()
1002 "Narrow the display to just the reports that are blocking a release."
1003 (interactive)
1004 (let ((blockers (cdr (assq 'blockedby
1005 (car (debbugs-get-status
1006 debbugs-gnu-blocking-report)))))
1007 (id (debbugs-gnu-current-id t))
1008 (inhibit-read-only t)
1009 status)
1010 (setq debbugs-gnu-limit nil)
1011 (goto-char (point-min))
1012 (while (not (eobp))
1013 (setq status (debbugs-gnu-current-status))
1014 (if (not (memq (cdr (assq 'id status)) blockers))
1015 (delete-region (point) (progn (forward-line 1) (point)))
1016 (push (cdr (assq 'id status)) debbugs-gnu-limit)
1017 (forward-line 1)))
1018 (when id
1019 (debbugs-gnu-goto id))))
1020
1021 (defun debbugs-gnu-narrow-to-status (string &optional status-only)
1022 "Only display the bugs matching STRING.
1023 If STATUS-ONLY (the prefix), ignore matches in the From and
1024 Subject fields."
1025 (interactive "sNarrow to: \nP")
1026 (let ((id (debbugs-gnu-current-id t))
1027 (inhibit-read-only t)
1028 status)
1029 (setq debbugs-gnu-limit nil)
1030 (if (equal string "")
1031 (debbugs-gnu-toggle-suppress)
1032 (goto-char (point-min))
1033 (while (not (eobp))
1034 (setq status (debbugs-gnu-current-status))
1035 (if (and (not (member string (assq 'keywords status)))
1036 (not (equal string (cdr (assq 'severity status))))
1037 (or status-only
1038 (not (string-match
1039 string (cdr (assq 'originator status)))))
1040 (or status-only
1041 (not (string-match string (cdr (assq 'subject status))))))
1042 (delete-region (point) (progn (forward-line 1) (point)))
1043 (push (cdr (assq 'id status)) debbugs-gnu-limit)
1044 (forward-line 1)))
1045 (when id
1046 (debbugs-gnu-goto id)))))
1047
1048 (defun debbugs-gnu-goto (id)
1049 "Go to the line displaying bug ID."
1050 (goto-char (point-min))
1051 (while (and (not (eobp))
1052 (not (equal (debbugs-gnu-current-id t) id)))
1053 (forward-line 1)))
1054
1055 (defun debbugs-gnu-toggle-tag ()
1056 "Toggle the local tag of the report in the current line.
1057 If a report is tagged locally, it is presumed to be of little
1058 interest to you."
1059 (interactive)
1060 (save-excursion
1061 (beginning-of-line)
1062 (let ((inhibit-read-only t)
1063 (id (debbugs-gnu-current-id)))
1064 (if (memq id debbugs-gnu-local-tags)
1065 (progn
1066 (setq debbugs-gnu-local-tags (delq id debbugs-gnu-local-tags))
1067 (put-text-property (point) (+ (point) 5) 'face 'default))
1068 (add-to-list 'debbugs-gnu-local-tags id)
1069 (put-text-property
1070 (+ (point) (- 5 (length (number-to-string id)))) (+ (point) 5)
1071 'face 'debbugs-gnu-tagged))
1072 (debbugs-gnu--update-tag-face id)))
1073 (debbugs-gnu-dump-persistency-file))
1074
1075 (defun debbugs-gnu--update-tag-face (id)
1076 (dolist (entry tabulated-list-entries)
1077 (when (equal (cdr (assq 'id (car entry))) id)
1078 (aset (cadr entry) 0
1079 (propertize
1080 (format "%5d" id)
1081 'face
1082 ;; Mark tagged bugs.
1083 (if (memq id debbugs-gnu-local-tags)
1084 'debbugs-gnu-tagged
1085 'default))))))
1086
1087 (defun debbugs-gnu-toggle-suppress ()
1088 "Suppress bugs marked in `debbugs-gnu-suppress-bugs'."
1089 (interactive)
1090 (setq debbugs-gnu-local-suppress (not debbugs-gnu-local-suppress))
1091 (tabulated-list-init-header)
1092 (tabulated-list-print))
1093
1094 (defvar debbugs-gnu-bug-number nil)
1095 (defvar debbugs-gnu-subject nil)
1096
1097 (defun debbugs-gnu-current-id (&optional noerror)
1098 (or (cdr (assq 'id (debbugs-gnu-current-status)))
1099 (and (not noerror)
1100 (error "No bug on the current line"))))
1101
1102 (defun debbugs-gnu-current-status ()
1103 (get-text-property (line-beginning-position) 'tabulated-list-id))
1104
1105 (defun debbugs-gnu-display-status (query filter status)
1106 "Display the query, filter and status of the report on the current line."
1107 (interactive (list debbugs-gnu-local-query
1108 debbugs-gnu-local-filter
1109 (debbugs-gnu-current-status)))
1110 (switch-to-buffer "*Bug Status*")
1111 (let ((inhibit-read-only t))
1112 (erase-buffer)
1113 (when query
1114 (insert ";; Query\n")
1115 (pp query (current-buffer))
1116 (insert "\n"))
1117 (when filter
1118 (insert ";; Filter\n")
1119 (pp filter (current-buffer))
1120 (insert "\n"))
1121 (when status
1122 (insert ";; Status\n")
1123 (pp status (current-buffer)))
1124 (goto-char (point-min)))
1125 (set-buffer-modified-p nil)
1126 (special-mode))
1127
1128 (defun debbugs-read-emacs-bug-with-rmail (id status merged)
1129 "Read email exchange for debbugs bug ID.
1130 STATUS is the bug's status list.
1131 MERGED is the list of bugs merged with this one."
1132 (let* ((mbox-dir (make-temp-file "debbugs" t))
1133 (mbox-fname (format "%s/bug_%d.mbox" mbox-dir id)))
1134 (debbugs-get-mbox id 'mboxmaint mbox-fname)
1135 (rmail mbox-fname)
1136 ;; Download messages of all the merged bug reports and append them
1137 ;; to the mailbox of the requested bug.
1138 (when merged
1139 (dolist (bugno merged)
1140 (let ((fn (make-temp-file "url")))
1141 (debbugs-get-mbox bugno 'mboxmaint fn)
1142 (rmail-get-new-mail fn)
1143 (delete-file fn)
1144 ;; Remove the 'unseen' attribute from all the messages we've
1145 ;; just read, so that all of them appear in the summary with
1146 ;; the same face.
1147 (while (< rmail-current-message rmail-total-messages)
1148 (rmail-show-message (1+ rmail-current-message))))))
1149 (set (make-local-variable 'debbugs-gnu-bug-number) id)
1150 (set (make-local-variable 'debbugs-gnu-subject)
1151 (format "Re: bug#%d: %s" id (cdr (assq 'subject status))))
1152 (rmail-summary)
1153 (define-key rmail-summary-mode-map "C" 'debbugs-gnu-send-control-message)
1154 (set-window-text-height nil 10)
1155 (other-window 1)
1156 (define-key rmail-mode-map "C" 'debbugs-gnu-send-control-message)
1157 (rmail-show-message 1)))
1158
1159 (defun debbugs-read-emacs-bug-with-gnus (id status merged)
1160 "Read email exchange for debbugs bug ID.
1161 STATUS is the bug's status list.
1162 MERGED is the list of bugs merged with this one."
1163 (require 'gnus-dup)
1164 (setq gnus-suppress-duplicates t
1165 gnus-save-duplicate-list t)
1166 ;; Use Gnus.
1167 (gnus-read-ephemeral-emacs-bug-group
1168 (cons id (if (listp merged) merged (list merged)))
1169 (cons (current-buffer)
1170 (current-window-configuration)))
1171 (with-current-buffer (window-buffer (selected-window))
1172 (set (make-local-variable 'debbugs-gnu-bug-number) id)
1173 (set (make-local-variable 'debbugs-gnu-subject)
1174 (format "Re: bug#%d: %s" id (cdr (assq 'subject status))))
1175 (debbugs-gnu-summary-mode 1)))
1176
1177 (defun debbugs-gnu-select-report ()
1178 "Select the report on the current line."
1179 (interactive)
1180 ;; We open the report messages.
1181 (let* ((status (debbugs-gnu-current-status))
1182 (id (cdr (assq 'id status)))
1183 (merged (cdr (assq 'mergedwith status))))
1184 (setq merged (if (listp merged) merged (list merged)))
1185 (cond
1186 ((not id)
1187 (message "No bug report on the current line"))
1188 ((eq debbugs-gnu-mail-backend 'rmail)
1189 (debbugs-read-emacs-bug-with-rmail id status merged))
1190 ((eq debbugs-gnu-mail-backend 'gnus)
1191 (debbugs-read-emacs-bug-with-gnus id status merged))
1192 (t (error "No valid mail backend specified")))))
1193
1194 (defvar debbugs-gnu-summary-mode-map
1195 (let ((map (make-sparse-keymap)))
1196 (define-key map "C" 'debbugs-gnu-send-control-message)
1197 (define-key map [(meta m)] 'debbugs-gnu-apply-patch)
1198 map))
1199
1200 (define-minor-mode debbugs-gnu-summary-mode
1201 "Minor mode for providing a debbugs interface in Gnus summary buffers.
1202
1203 \\{debbugs-gnu-summary-mode-map}"
1204 :lighter " Debbugs" :keymap debbugs-gnu-summary-mode-map
1205 (set (make-local-variable 'gnus-posting-styles)
1206 `((".*"
1207 (eval
1208 (when (buffer-live-p gnus-article-copy)
1209 (with-current-buffer gnus-article-copy
1210 (set (make-local-variable 'message-prune-recipient-rules)
1211 '((".*@debbugs.*" "emacs-pretest-bug")
1212 (".*@debbugs.*" "bug-gnu-emacs")
1213 ("[0-9]+@debbugs.*" "submit@debbugs.gnu.org")
1214 ("[0-9]+@debbugs.*" "quiet@debbugs.gnu.org")))
1215 (set (make-local-variable 'message-alter-recipients-function)
1216 (lambda (address)
1217 (if (string-match "\\([0-9]+\\)@donarmstrong"
1218 (car address))
1219 (let ((new (format "%s@debbugs.gnu.org"
1220 (match-string 1 (car address)))))
1221 (cons new new))
1222 address)))
1223 ;; `gnus-posting-styles' is eval'ed after
1224 ;; `message-simplify-subject'. So we cannot use m-s-s.
1225 (setq subject ,debbugs-gnu-subject))))))))
1226
1227 (defun debbugs-gnu-guess-current-id ()
1228 "Guess the ID based on \"#23\"."
1229 (save-excursion
1230 (beginning-of-line)
1231 (and
1232 (or (re-search-forward "#\\([0-9]+\\)" (line-end-position) t)
1233 (progn
1234 (goto-char (point-min))
1235 (re-search-forward "#\\([0-9]+\\)" nil t)))
1236 (string-to-number (match-string 1)))))
1237
1238 (defvar debbugs-gnu-send-mail-function nil
1239 "A function to send control messages from debbugs.")
1240
1241 (defun debbugs-gnu-send-control-message (message &optional reverse)
1242 "Send a control message for the current bug report.
1243 You can set the severity or add a tag, or close the report. If
1244 you use the special \"done\" MESSAGE, the report will be marked as
1245 fixed, and then closed.
1246
1247 If given a prefix, and given a tag to set, the tag will be
1248 removed instead."
1249 (interactive
1250 (list (completing-read
1251 "Control message: "
1252 '("serious" "important" "normal" "minor" "wishlist"
1253 "done" "donenotabug" "donewontfix" "doneunreproducible"
1254 "unarchive" "unmerge" "reopen" "close"
1255 "merge" "forcemerge"
1256 "block" "unblock"
1257 "owner" "noowner"
1258 "invalid"
1259 "reassign"
1260 "retitle"
1261 "patch" "wontfix" "moreinfo" "unreproducible" "fixed" "notabug"
1262 "pending" "help" "security" "confirmed"
1263 "usertag")
1264 nil t)
1265 current-prefix-arg))
1266 (let* ((id (or debbugs-gnu-bug-number ; Set on group entry.
1267 (debbugs-gnu-guess-current-id)
1268 (debbugs-gnu-current-id)))
1269 (version
1270 (when (member message '("close" "done"))
1271 (read-string
1272 "Version: "
1273 (cond
1274 ;; Emacs development versions.
1275 ((string-match
1276 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\." emacs-version)
1277 (format "%s.%d"
1278 (match-string 1 emacs-version)
1279 (1+ (string-to-number (match-string 2 emacs-version)))))
1280 ;; Emacs release versions.
1281 ((string-match
1282 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)$" emacs-version)
1283 (format "%s.%s"
1284 (match-string 1 emacs-version)
1285 (match-string 2 emacs-version)))
1286 (t emacs-version)))))
1287 (status (debbugs-gnu-current-status)))
1288 (with-temp-buffer
1289 (insert "To: control@debbugs.gnu.org\n"
1290 "From: " (message-make-from) "\n"
1291 (format "Subject: control message for bug #%d\n" id)
1292 mail-header-separator
1293 "\n"
1294 (cond
1295 ((member message '("unarchive" "unmerge" "reopen" "noowner"))
1296 (format "%s %d\n" message id))
1297 ((member message '("merge" "forcemerge"))
1298 (format "%s %d %s\n" message id
1299 (read-string "Merge with bug #: ")))
1300 ((member message '("block" "unblock"))
1301 (format
1302 "%s %d by %s\n" message id
1303 (mapconcat
1304 'identity
1305 (completing-read-multiple
1306 (format "%s with bug(s) #: " (capitalize message))
1307 (if (equal message "unblock")
1308 (mapcar 'number-to-string
1309 (cdr (assq 'blockedby status))))
1310 nil (and (equal message "unblock") status))
1311 " ")))
1312 ((equal message "owner")
1313 (format "owner %d !\n" id))
1314 ((equal message "retitle")
1315 (format "retitle %d %s\n" id (read-string "New title: ")))
1316 ((equal message "reassign")
1317 (format "reassign %d %s\n" id (read-string "Package(s): ")))
1318 ((equal message "close")
1319 (format "close %d %s\n" id version))
1320 ((equal message "done")
1321 (format "tags %d fixed\nclose %d %s\n" id id version))
1322 ((member message '("donenotabug" "donewontfix"
1323 "doneunreproducible"))
1324 (format "tags %d %s\nclose %d\n" id (substring message 4) id))
1325 ((member message '("serious" "important" "normal"
1326 "minor" "wishlist"))
1327 (format "severity %d %s\n" id message))
1328 ((equal message "invalid")
1329 (format "tags %d notabug\ntags %d wontfix\nclose %d\n"
1330 id id id))
1331 ((equal message "usertag")
1332 (format "user %s\nusertag %d %s\n"
1333 (completing-read
1334 "Package name or email address: "
1335 (append
1336 debbugs-gnu-all-packages (list user-mail-address))
1337 nil nil (car debbugs-gnu-default-packages))
1338 id (read-string "User tag: ")))
1339 (t
1340 (format "tags %d%s %s\n"
1341 id (if reverse " -" "")
1342 message))))
1343 (funcall (or debbugs-gnu-send-mail-function send-mail-function))
1344 (remhash id debbugs-cache-data)
1345 (message-goto-body)
1346 (message "Control message sent:\n%s"
1347 (buffer-substring-no-properties (point) (1- (point-max)))))))
1348
1349 (defvar debbugs-gnu-usertags-mode-map
1350 (let ((map (make-sparse-keymap)))
1351 (set-keymap-parent map tabulated-list-mode-map)
1352 (define-key map "\r" 'debbugs-gnu-select-usertag)
1353 (define-key map [mouse-1] 'debbugs-gnu-select-usertag)
1354 (define-key map [mouse-2] 'debbugs-gnu-select-usertag)
1355 map))
1356
1357 (define-derived-mode debbugs-gnu-usertags-mode tabulated-list-mode "Usertags"
1358 "Major mode for listing user tags.
1359
1360 All normal editing commands are switched off.
1361 \\<debbugs-gnu-usertags-mode-map>
1362
1363 The following commands are available:
1364
1365 \\{debbugs-gnu-usertags-mode-map}"
1366 (buffer-disable-undo)
1367 (setq truncate-lines t)
1368 (setq buffer-read-only t))
1369
1370 ;;;###autoload
1371 (defun debbugs-gnu-usertags (&rest users)
1372 "List all user tags for USERS, which is \(\"emacs\"\) by default."
1373 (interactive
1374 (if current-prefix-arg
1375 (completing-read-multiple
1376 "Package name(s) or email address: "
1377 (append debbugs-gnu-all-packages (list user-mail-address)) nil nil
1378 (mapconcat 'identity debbugs-gnu-default-packages ","))
1379 debbugs-gnu-default-packages))
1380
1381 (unwind-protect
1382 (let ((inhibit-read-only t)
1383 (debbugs-port "gnu.org")
1384 (buffer-name "*Emacs User Tags*")
1385 (user-tab-length
1386 (1+ (apply 'max (length "User") (mapcar 'length users)))))
1387
1388 ;; Initialize variables.
1389 (when (and (file-exists-p debbugs-gnu-persistency-file)
1390 (not debbugs-gnu-local-tags))
1391 (with-temp-buffer
1392 (insert-file-contents debbugs-gnu-persistency-file)
1393 (eval (read (current-buffer)))))
1394
1395 ;; Create buffer.
1396 (when (get-buffer buffer-name)
1397 (kill-buffer buffer-name))
1398 (switch-to-buffer (get-buffer-create buffer-name))
1399 (debbugs-gnu-usertags-mode)
1400 (setq tabulated-list-format `[("User" ,user-tab-length t)
1401 ("Tag" 10 t)])
1402 (setq tabulated-list-sort-key (cons "User" nil))
1403 ;(setq tabulated-list-printer 'debbugs-gnu-print-entry)
1404
1405 ;; Retrieve user tags.
1406 (dolist (user users)
1407 (dolist (tag (sort (debbugs-get-usertag :user user) 'string<))
1408 (add-to-list
1409 'tabulated-list-entries
1410 ;; `tabulated-list-id' is the parameter list for `debbugs-gnu'.
1411 `((("tagged") (,user) nil nil (,tag))
1412 ,(vector (propertize user 'mouse-face 'highlight)
1413 (propertize tag 'mouse-face 'highlight)))
1414 'append)))
1415
1416 ;; Add local tags.
1417 (when debbugs-gnu-local-tags
1418 (add-to-list
1419 'tabulated-list-entries
1420 `((("tagged"))
1421 ,(vector
1422 "" (propertize "(local tags)" 'mouse-face 'highlight)))))
1423
1424 ;; Show them.
1425 (tabulated-list-init-header)
1426 (tabulated-list-print)
1427
1428 (set-buffer-modified-p nil)
1429 (goto-char (point-min)))))
1430
1431 (defun debbugs-gnu-select-usertag ()
1432 "Select the user tag on the current line."
1433 (interactive)
1434 ;; We open the bug reports.
1435 (let ((args (get-text-property (line-beginning-position) 'tabulated-list-id)))
1436 (when args (apply 'debbugs-gnu args))))
1437
1438 ;;;###autoload
1439 (defun debbugs-gnu-bugs (&rest bugs)
1440 "List all BUGS, a list of bug numbers."
1441 (interactive
1442 (mapcar 'string-to-number
1443 (completing-read-multiple "Bug numbers: " nil 'natnump)))
1444 (dolist (elt bugs)
1445 (unless (natnump elt) (signal 'wrong-type-argument (list 'natnump elt))))
1446 (add-to-list 'debbugs-gnu-current-query (cons 'bugs bugs))
1447 ;; We do not suppress bugs requested explicitely.
1448 (setq debbugs-gnu-current-suppress nil)
1449 (debbugs-gnu nil))
1450
1451 (defvar debbugs-gnu-trunk-directory "~/src/emacs/trunk/"
1452 "The directory where the main source tree lives.")
1453
1454 (defvar debbugs-gnu-branch-directory "~/src/emacs/emacs-25/"
1455 "The directory where the previous source tree lives.")
1456
1457 (defun debbugs-gnu-apply-patch (&optional branch)
1458 "Apply the patch from the current message.
1459 If given a prefix, patch in the branch directory instead."
1460 (interactive "P")
1461 (add-hook 'emacs-lisp-mode-hook 'debbugs-gnu-lisp-mode)
1462 (add-hook 'diff-mode-hook 'debbugs-gnu-diff-mode)
1463 (add-hook 'change-log-mode-hook 'debbugs-gnu-change-mode)
1464 (let ((rej "/tmp/debbugs-gnu.rej")
1465 (output-buffer (get-buffer-create "*debbugs patch*"))
1466 (dir (if branch
1467 debbugs-gnu-branch-directory
1468 debbugs-gnu-trunk-directory))
1469 (patch-buffers nil))
1470 (when (file-exists-p rej)
1471 (delete-file rej))
1472 (with-current-buffer output-buffer
1473 (erase-buffer))
1474 (gnus-summary-select-article nil t)
1475 ;; The patches are either in MIME attachements or the main article
1476 ;; buffer. Determine which.
1477 (gnus-with-article-buffer
1478 (dolist (handle (mapcar 'cdr (gnus-article-mime-handles)))
1479 (when (string-match "diff\\|patch\\|plain" (mm-handle-media-type handle))
1480 (push (cons (mm-handle-encoding handle)
1481 (mm-handle-buffer handle))
1482 patch-buffers))))
1483 (unless patch-buffers
1484 (gnus-summary-show-article 'raw)
1485 (article-decode-charset)
1486 (push (cons nil gnus-article-buffer) patch-buffers))
1487 (dolist (elem patch-buffers)
1488 (with-current-buffer (generate-new-buffer "*debbugs input patch*")
1489 (insert-buffer-substring (cdr elem))
1490 (cond ((eq (car elem) 'base64)
1491 (base64-decode-region (point-min) (point-max)))
1492 ((eq (car elem) 'quoted-printable)
1493 (quoted-printable-decode-region (point-min) (point-max))))
1494 (debbugs-gnu-fix-patch dir)
1495 (call-process-region (point-min) (point-max)
1496 "patch" nil output-buffer nil
1497 "-r" rej "--no-backup-if-mismatch"
1498 "-l" "-f"
1499 "-d" (expand-file-name dir)
1500 "-p1")))
1501 (set-buffer output-buffer)
1502 (when (file-exists-p rej)
1503 (goto-char (point-max))
1504 (insert-file-contents-literally rej))
1505 (goto-char (point-max))
1506 (save-some-buffers t)
1507 (require 'compile)
1508 (mapc 'kill-process compilation-in-progress)
1509 (compile (format "cd %s; make -k" (expand-file-name "lisp" dir)))
1510 (vc-dir dir)
1511 (vc-dir-hide-up-to-date)
1512 (goto-char (point-min))
1513 (sit-for 1)
1514 (vc-diff)
1515 ;; All these commands are asynchronous, so just wait a bit. This
1516 ;; should be done properly a different way.
1517 (sit-for 2)
1518 ;; We've now done everything, so arrange the windows we need to see.
1519 (delete-other-windows)
1520 (switch-to-buffer output-buffer)
1521 (split-window)
1522 (split-window)
1523 (other-window 1)
1524 (switch-to-buffer "*compilation*")
1525 (goto-char (point-max))
1526 (other-window 1)
1527 (switch-to-buffer "*vc-diff*")
1528 (goto-char (point-min))))
1529
1530 (defun debbugs-gnu-fix-patch (dir)
1531 (setq dir (directory-file-name (expand-file-name dir)))
1532 (goto-char (point-min))
1533 (while (re-search-forward diff-file-header-re nil t)
1534 (goto-char (match-beginning 0))
1535 (let ((target-name (car (diff-hunk-file-names))))
1536 (when (and target-name
1537 (or (not (string-match "/" target-name))
1538 (and (string-match "^[ab]/" target-name)
1539 (not (file-exists-p
1540 (expand-file-name (substring target-name 2)
1541 dir))))
1542 (file-exists-p (expand-file-name target-name dir))))
1543 ;; We have a simple patch that refers to a file somewhere in the
1544 ;; tree. Find it.
1545 (when-let ((files (directory-files-recursively
1546 dir
1547 (concat "^" (regexp-quote
1548 (file-name-nondirectory target-name))
1549 "$"))))
1550 (when (re-search-forward (concat "^[+]+ "
1551 (regexp-quote target-name)
1552 "\\([ \t\n]\\)")
1553 nil t)
1554 (replace-match (concat "+++ a"
1555 (substring (car files) (length dir))
1556 (match-string 1))
1557 nil t)))))
1558 (forward-line 2)))
1559
1560 (defun debbugs-gnu-find-contributor (string)
1561 "Search through ChangeLogs to find contributors."
1562 (interactive "sContributor match: ")
1563 (let ((found 0)
1564 (match (concat "^[0-9].*" string)))
1565 (dolist (file (directory-files-recursively
1566 debbugs-gnu-trunk-directory "ChangeLog\\(.[0-9]+\\)?$"))
1567 (with-temp-buffer
1568 (when (file-exists-p file)
1569 (insert-file-contents file))
1570 (goto-char (point-min))
1571 (while (and (re-search-forward match nil t)
1572 (not (looking-at ".*tiny change")))
1573 (cl-incf found))))
1574 (message "%s is a contributor %d times" string found)
1575 found))
1576
1577 (defun debbugs-gnu-insert-changelog ()
1578 "Add a ChangeLog from a recently applied patch from a third party."
1579 (interactive)
1580 (let (from subject)
1581 (gnus-with-article-buffer
1582 (widen)
1583 (goto-char (point-min))
1584 (setq from (mail-extract-address-components (gnus-fetch-field "from"))
1585 subject (gnus-fetch-field "subject")))
1586 (let ((add-log-full-name (car from))
1587 (add-log-mailing-address (cadr from)))
1588 (add-change-log-entry-other-window)
1589 (let ((point (point)))
1590 (when (string-match "\\(bug#[0-9]+\\)" subject)
1591 (insert " (" (match-string 1 subject) ")."))
1592 (when (zerop (debbugs-gnu-find-contributor
1593 (let ((bits (split-string (car from))))
1594 (cond
1595 ((>= (length bits) 2)
1596 (format "%s.*%s" (car bits) (car (last bits))))
1597 ((= (length bits) 1)
1598 (car bits))
1599 ;; Fall back on the email address.
1600 (t
1601 (cadr from))))))
1602 (goto-char (point-max))
1603 (end-of-line)
1604 (insert " Copyright-paperwork-exempt: yes"))
1605 (goto-char point)))))
1606
1607 (defvar debbugs-gnu-lisp-mode-map
1608 (let ((map (make-sparse-keymap)))
1609 (define-key map [(meta m)] 'debbugs-gnu-insert-changelog)
1610 map))
1611
1612 (define-minor-mode debbugs-gnu-lisp-mode
1613 "Minor mode for providing a debbugs interface in Lisp buffers.
1614 \\{debbugs-gnu-lisp-mode-map}"
1615 :lighter " Debbugs" :keymap debbugs-gnu-lisp-mode-map)
1616
1617 (defvar debbugs-gnu-diff-mode-map
1618 (let ((map (make-sparse-keymap)))
1619 (define-key map [(meta m)] 'debbugs-gnu-diff-select)
1620 map))
1621
1622 (define-minor-mode debbugs-gnu-diff-mode
1623 "Minor mode for providing a debbugs interface in diff buffers.
1624 \\{debbugs-gnu-diff-mode-map}"
1625 :lighter " Debbugs" :keymap debbugs-gnu-diff-mode-map)
1626
1627 (defun debbugs-gnu-diff-select ()
1628 "Select the diff under point."
1629 (interactive)
1630 (delete-other-windows)
1631 (diff-goto-source))
1632
1633 (defvar debbugs-gnu-change-mode-map
1634 (let ((map (make-sparse-keymap)))
1635 (define-key map [(meta m)] 'debbugs-gnu-change-checkin)
1636 map))
1637
1638 (define-minor-mode debbugs-gnu-change-mode
1639 "Minor mode for providing a debbugs interface in ChangeLog buffers.
1640 \\{debbugs-gnu-change-mode-map}"
1641 :lighter " Debbugs" :keymap debbugs-gnu-change-mode-map)
1642
1643 (defun debbugs-gnu-change-checkin ()
1644 "Prepare checking in the current changes."
1645 (interactive)
1646 (save-some-buffers t)
1647 (when (get-buffer "*vc-dir*")
1648 (kill-buffer (get-buffer "*vc-dir*")))
1649 (let ((trunk (expand-file-name debbugs-gnu-trunk-directory)))
1650 (if (equal (cl-subseq default-directory 0 (length trunk))
1651 trunk)
1652 (vc-dir debbugs-gnu-trunk-directory)
1653 (vc-dir debbugs-gnu-branch-directory)))
1654 (goto-char (point-min))
1655 (while (not (search-forward "edited" nil t))
1656 (sit-for 0.01))
1657 (beginning-of-line)
1658 (while (search-forward "edited" nil t)
1659 (vc-dir-mark)
1660 (beginning-of-line))
1661 (vc-diff nil)
1662 (vc-next-action nil)
1663 (log-edit-insert-changelog t)
1664 (delete-other-windows)
1665 (split-window)
1666 (other-window 1)
1667 (switch-to-buffer "*vc-diff*")
1668 (other-window 1))
1669
1670 (defun debbugs-gnu-save-cache ()
1671 "Save the bugs cache to a file."
1672 (interactive)
1673 (unless debbugs-cache-data
1674 (error "No data to cache"))
1675 (unless (file-exists-p "~/.emacs.d/debbugs-cache")
1676 (make-directory "~/.emacs.d/debbugs-cache" t))
1677 (let ((coding-system-for-write 'utf-8))
1678 (with-temp-file "~/.emacs.d/debbugs-cache/list"
1679 (prin1 debbugs-cache-data (current-buffer)))))
1680
1681 (provide 'debbugs-gnu)
1682
1683 ;;; TODO:
1684
1685 ;; * Another random thought - is it possible to implement some local
1686 ;; cache, so only changed bugs are fetched? Glenn Morris.
1687
1688 ;;; debbugs-gnu.el ends here