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