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