1 ;;; debbugs-gnu.el --- interface for the GNU bug tracker -*- lexical-binding:t -*-
3 ;; Copyright (C) 2011-2016 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Michael Albinus <michael.albinus@gmx.org>
7 ;; Keywords: comm, hypermedia, maint
10 ;; This file is not part of GNU Emacs.
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.
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.
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/>.
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.
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
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)
40 ;; The bug tracker is called interactively by
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.
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.
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.
65 ;; M-x debbugs-gnu-search
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.
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.
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'.
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:
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
98 ;; Furthermore, you could apply the global actions
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
108 ;; When you visit the related bug messages in Gnus or Rmail, you could
109 ;; also send control messages by keystroke "C".
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.
116 ;; Another approach for listing bugs is calling the command
118 ;; M-x debbugs-gnu-usertags
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.
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>.
132 ;; Finally, if you simply want to list some bugs with known bug
133 ;; numbers, call the command
135 ;; M-x debbugs-gnu-bugs
137 ;; The bug numbers to be shown shall be entered as comma separated list.
142 (require 'tabulated-list)
144 (eval-when-compile (require 'subr-x))
145 (eval-when-compile (require 'cl-lib))
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")
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)
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)
185 (defgroup debbugs-gnu ()
186 "UI for the debbugs.gnu.org bug tracker."
190 (defvar debbugs-gnu-blocking-report 19759
191 "The ID of the current release report used to track blocking bug reports.")
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".
200 :type '(set (const "serious")
208 (defcustom debbugs-gnu-suppress-closed t
209 "If non-nil, don't show closed bugs."
214 (defconst debbugs-gnu-all-severities
215 (mapcar 'cadr (cdr (get 'debbugs-gnu-default-severities 'custom-type)))
216 "*List of all possible severities.")
218 (defcustom debbugs-gnu-default-packages '("emacs")
219 "*The list of packages to be searched for."
220 ;; <http://debbugs.gnu.org/Packages.html>
221 ;; <http://debbugs.gnu.org/cgi/pkgindex.cgi>
223 :type '(set (const "adns")
229 (const "debbugs.gnu.org")
232 (const "emacs-xwidgets")
250 (defconst debbugs-gnu-all-packages
251 (mapcar 'cadr (cdr (get 'debbugs-gnu-default-packages 'custom-type)))
252 "*List of all possible package names.")
254 (defcustom debbugs-gnu-default-suppress-bugs
255 '((pending . "done"))
256 "*A list of specs for bugs to be suppressed.
257 An element of this list is a cons cell \(KEY . REGEXP\), with key
258 being returned by `debbugs-get-status', and REGEXP a regular
259 expression matching the corresponding value, a string. Showing
260 suppressed bugs is toggled by `debbugs-gnu-toggle-suppress'."
262 :type '(alist :key-type symbol :value-type regexp)
265 (defcustom debbugs-gnu-mail-backend 'gnus
266 "*The email backend to use for reading bug report email exchange.
267 If this is 'gnus, the default, use Gnus.
268 If this is 'rmail, use Rmail instead."
270 :type '(choice (const :tag "Use Gnus" 'gnus)
271 (const :tag "Use Rmail" 'rmail))
274 (defface debbugs-gnu-archived '((t (:inverse-video t)))
275 "Face for archived bug reports.")
277 (defface debbugs-gnu-new '((t (:foreground "red")))
278 "Face for new reports that nobody has answered.")
280 (defface debbugs-gnu-handled '((t (:foreground "ForestGreen")))
281 "Face for reports that have been modified recently.")
283 (defface debbugs-gnu-pending '((t (:foreground "MidnightBlue")))
284 "Face for reports that are pending.")
286 (defface debbugs-gnu-stale '((t (:foreground "orange")))
287 "Face for reports that have not been touched for two weeks.")
289 (defface debbugs-gnu-done '((t (:foreground "DarkGrey")))
290 "Face for closed bug reports.")
292 (defface debbugs-gnu-tagged '((t (:foreground "red")))
293 "Face for reports that have been tagged locally.")
295 (defvar debbugs-gnu-local-tags nil
296 "List of bug numbers tagged locally, and kept persistent.")
298 (defvar debbugs-gnu-persistency-file
299 (expand-file-name (locate-user-emacs-file "debbugs"))
300 "File name of a persistency store for debbugs variables")
302 (defun debbugs-gnu-dump-persistency-file ()
303 "Function to store debbugs variables persistently."
304 (with-temp-file debbugs-gnu-persistency-file
306 ";; -*- emacs-lisp -*-\n"
307 ";; Debbugs tags connection history. Don't change this file.\n\n"
308 (format "(setq debbugs-gnu-local-tags '%S)"
309 (sort (copy-sequence debbugs-gnu-local-tags) '>)))))
311 (defvar debbugs-gnu-current-query nil
312 "The query object of the current search.
313 It will be applied server-side, when calling `debbugs-get-bugs'.
314 It has the same format as `debbugs-gnu-default-suppress-bugs'.")
316 (defvar debbugs-gnu-current-filter nil
317 "The filter object for the current search.
318 It will be applied client-side, when parsing the results of
319 `debbugs-get-status'. It has a similar format as
320 `debbugs-gnu-default-suppress-bugs'. In case of keys representing
321 a date, value is the cons cell \(BEFORE . AFTER\).")
323 (defvar debbugs-gnu-current-suppress nil
324 "Whether bugs shall be suppressed.
325 The specification which bugs shall be suppressed is taken from
326 `debbugs-gnu-default-suppress-bugs'.")
328 (defun debbugs-gnu-calendar-read (prompt acceptable &optional initial-contents)
329 "Return a string read from the minibuffer.
330 Derived from `calendar-read'."
331 (let ((value (read-string prompt initial-contents)))
332 (while (not (funcall acceptable value))
333 (setq value (read-string prompt initial-contents)))
336 (defconst debbugs-gnu-phrase-prompt
338 "Enter search phrase: "
340 The search phrase contains words to be searched for, combined by
341 operators like AND, ANDNOT and OR. If there is no operator
342 between the words, AND is used by default. The phrase can also
343 be empty, in this case only the following attributes are used for
347 (defun debbugs-gnu-search ()
348 "Search for Emacs bugs interactively.
349 Search arguments are requested interactively. The \"search
350 phrase\" is used for full text search in the bugs database.
351 Further key-value pairs are requested until an empty key is
352 returned. If a key cannot be queried by a SOAP request, it is
353 marked as \"client-side filter\"."
357 (let ((date-format "\\([[:digit:]]\\{4\\}\\)-\\([[:digit:]]\\{1,2\\}\\)-\\([[:digit:]]\\{1,2\\}\\)")
358 key val1 val2 phrase severities packages archivedp)
360 ;; Check for the phrase.
361 (setq phrase (read-string debbugs-gnu-phrase-prompt))
362 (if (zerop (length phrase))
364 (add-to-list 'debbugs-gnu-current-query (cons 'phrase phrase)))
365 ;; We suppress closed bugs if there is no phrase.
366 (setq debbugs-gnu-current-suppress
367 (if (not debbugs-gnu-suppress-closed)
371 ;; The other queries.
374 (setq key (completing-read
378 '("severity" "package" "tags"
379 "author" "date" "subject")
380 ;; Client-side filters.
384 key 'face 'debbugs-gnu-done
385 'help-echo "Client-side filter"))
388 '("severity" "package" "archive" "src" "status" "tag"
389 "owner" "submitter" "maint" "correspondent")
390 ;; Client-side filters.
394 key 'face 'debbugs-gnu-done
395 'help-echo "Client-side filter"))
396 '("date" "log_modified" "last_modified"
397 "found_date" "fixed_date" "unarchived"
398 "subject" "done" "forwarded" "msgid" "summary"))))
401 ;; Server-side queries.
402 ((equal key "severity")
405 (completing-read-multiple
406 "Enter severities: " debbugs-gnu-all-severities nil t
407 (mapconcat 'identity debbugs-gnu-default-severities ","))))
409 ((equal key "package")
412 (completing-read-multiple
413 "Enter packages: " debbugs-gnu-all-packages nil t
414 (mapconcat 'identity debbugs-gnu-default-packages ","))))
416 ((equal key "archive")
417 ;; We simplify, by assuming just archived bugs are requested.
420 ((member key '("src" "tag" "tags"))
421 (setq val1 (read-string (format "Enter %s: " key)))
422 (when (not (zerop (length val1)))
424 'debbugs-gnu-current-query (cons (intern key) val1))))
427 key '("author" "owner" "submitter" "maint" "correspondent"))
428 (setq val1 (read-string "Enter email address: "))
429 (when (not (zerop (length val1)))
431 'debbugs-gnu-current-query
432 (cons (intern (if (equal key "author") "@author" key)) val1))))
434 ;; Client-side filters.
435 ((equal key "status")
439 (format "Enter status%s: "
440 (if (null phrase) "" " (client-side filter)"))
441 '("pending" "forwarded" "fixed" "done")))
442 (when (not (zerop (length val1)))
445 'debbugs-gnu-current-query (cons (intern key) val1))
447 'debbugs-gnu-current-filter (cons 'pending val1)))))
449 ((member key '("date" "log_modified" "last_modified"
450 "found_date" "fixed_date" "unarchived"))
452 (debbugs-gnu-calendar-read
453 (format "Enter %s before YYYY-MM-DD%s: "
454 key (if phrase "" " (client-side filter)"))
456 (string-match (concat "^\\(" date-format "\\|\\)$") x))))
457 (if (string-match date-format val1)
462 (string-to-number (match-string 3 val1))
463 (string-to-number (match-string 2 val1))
464 (string-to-number (match-string 1 val1))))))
467 (debbugs-gnu-calendar-read
468 (format "Enter %s after YYYY-MM-DD%s: "
469 key (if phrase "" " (client-side filter)"))
471 (string-match (concat "^\\(" date-format "\\|\\)$") x))))
472 (if (string-match date-format val2)
477 (string-to-number (match-string 3 val2))
478 (string-to-number (match-string 2 val2))
479 (string-to-number (match-string 1 val2))))))
484 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
485 (cons (intern key) (cons val1 val2)))))
487 ;; "subject", "done", "forwarded", "msgid", "summary".
488 ((not (zerop (length key)))
491 (if phrase 'read-string 'read-regexp)
492 (format "Enter %s%s: "
493 key (if phrase "" " (client-side filter)"))))
494 (when (not (zerop (length val1)))
497 'debbugs-gnu-current-query 'debbugs-gnu-current-filter)
498 (cons (intern key) val1))))
501 (t (throw :finished nil)))))
504 (debbugs-gnu severities packages archivedp))))
507 (defun debbugs-gnu-patches ()
508 "List the bug reports that have been marked as containing a patch."
510 (debbugs-gnu nil debbugs-gnu-default-packages nil nil "patch"))
513 (defun debbugs-gnu (severities &optional packages archivedp suppress tags)
514 "List all outstanding bugs."
516 (let (severities archivedp)
519 (completing-read-multiple
520 "Severities: " debbugs-gnu-all-severities nil t
521 (mapconcat 'identity debbugs-gnu-default-severities ",")))
522 ;; The next parameters are asked only when there is a prefix.
523 (if current-prefix-arg
524 (completing-read-multiple
525 "Packages: " debbugs-gnu-all-packages nil t
526 (mapconcat 'identity debbugs-gnu-default-packages ","))
527 debbugs-gnu-default-packages)
528 (when current-prefix-arg
529 (setq archivedp (y-or-n-p "Show archived bugs?")))
530 (when (and current-prefix-arg (not archivedp))
531 (y-or-n-p "Suppress unwanted bugs?"))
532 ;; This one must be asked for severity "tagged".
533 (when (member "tagged" severities)
534 (split-string (read-string "User tag(s): ") "," t)))))
536 ;; Initialize variables.
537 (when (and (file-exists-p debbugs-gnu-persistency-file)
538 (not debbugs-gnu-local-tags))
540 (insert-file-contents debbugs-gnu-persistency-file)
541 (eval (read (current-buffer)))))
542 ;; Per default, we suppress retrieved unwanted bugs.
543 (when (and (called-interactively-p 'any)
544 debbugs-gnu-suppress-closed)
545 (setq debbugs-gnu-current-suppress t))
548 (dolist (severity (if (consp severities) severities (list severities)))
549 (when (not (zerop (length severity)))
550 (when (string-equal severity "tagged")
551 (setq debbugs-gnu-current-suppress nil))
552 (add-to-list 'debbugs-gnu-current-query (cons 'severity severity))))
553 (dolist (package (if (consp packages) packages (list packages)))
554 (when (not (zerop (length package)))
555 (add-to-list 'debbugs-gnu-current-query (cons 'package package))))
557 (setq debbugs-gnu-current-suppress nil)
558 (add-to-list 'debbugs-gnu-current-query '(archive . "1")))
560 (setq debbugs-gnu-current-suppress t)
561 (add-to-list 'debbugs-gnu-current-query '(status . "open"))
562 (add-to-list 'debbugs-gnu-current-query '(status . "forwarded")))
563 (dolist (tag (if (consp tags) tags (list tags)))
564 (when (not (zerop (length tag)))
565 (add-to-list 'debbugs-gnu-current-query (cons 'tag tag))))
568 (debbugs-gnu-show-reports)
570 ;; Reset query, filter and suppress.
571 (setq debbugs-gnu-current-query nil
572 debbugs-gnu-current-filter nil
573 debbugs-gnu-current-suppress nil))
575 (defun debbugs-gnu-get-bugs (query)
576 "Retrieve bug numbers from debbugs.gnu.org according search criteria."
577 (let* ((debbugs-port "gnu.org")
578 (bugs (assoc 'bugs query))
579 (tags (and (member '(severity . "tagged") query) (assoc 'tag query)))
580 (local-tags (and (member '(severity . "tagged") query) (not tags)))
581 (phrase (assoc 'phrase query))
583 ;; Compile query arguments.
584 (unless (or query tags)
585 (dolist (elt debbugs-gnu-default-packages)
586 (setq args (append args (list :package elt)))))
588 (unless (equal elt '(severity . "tagged"))
594 ((eq (car elt) 'phrase)
595 (list (list :phrase (cdr elt))))
596 ((eq (car elt) 'date)
597 (list (list :date (cddr elt) (cadr elt)
600 (list (list (intern (concat ":" (symbol-name (car elt))))
601 (cdr elt) :operator "ISTRINC"))))
602 (list (intern (concat ":" (symbol-name (car elt))))
606 ;; If the query is just a list of bug numbers, we return them.
608 ;; If the query contains the pseudo-severity "tagged", we return
609 ;; just the local tagged bugs.
610 (local-tags (copy-sequence debbugs-gnu-local-tags))
611 ;; A full text query.
614 (lambda (x) (cdr (assoc "id" x)))
615 (apply 'debbugs-search-est args)))
618 (setq args (mapcar (lambda (x) (if (eq x :package) :user x)) args))
619 (apply 'debbugs-get-usertag args))
620 ;; Otherwise, we retrieve the bugs from the server.
621 (t (apply 'debbugs-get-bugs args)))))
623 (defun debbugs-gnu-show-reports (&optional offline)
625 If OFFLINE is non-nil, the query is not sent to the server. Bugs
626 are taken from the cache instead."
627 (let ((inhibit-read-only t)
628 (buffer-name "*Emacs Bugs*"))
629 ;; The tabulated mode sets several local variables. We must get
631 (when (get-buffer buffer-name)
632 (kill-buffer buffer-name))
633 (switch-to-buffer (get-buffer-create buffer-name))
636 ;; Print bug reports.
638 (let ((debbugs-cache-expiry (if offline nil debbugs-cache-expiry))
640 (apply 'debbugs-get-status
643 (maphash (lambda (key _elem)
647 (debbugs-gnu-get-bugs debbugs-gnu-local-query)))))
648 (let* ((id (cdr (assq 'id status)))
652 (cons (cdr (assq 'severity status))
653 (cdr (assq 'keywords status)))
655 (address (if (cdr (assq 'originator status))
656 (mail-header-parse-address
657 (decode-coding-string (cdr (assq 'originator status))
659 (owner (if (cdr (assq 'owner status))
660 (car (mail-header-parse-address
661 (decode-coding-string (cdr (assq 'owner status))
663 (subject (if (cdr (assq 'subject status))
664 (decode-coding-string (cdr (assq 'subject status))
667 (unless (equal (cdr (assq 'pending status)) "pending")
668 (setq words (concat words "," (cdr (assq 'pending status)))))
669 (let ((packages (delete "emacs" (cdr (assq 'package status)))))
671 (setq words (concat words "," (mapconcat 'identity packages ",")))))
672 (when (setq merged (cdr (assq 'mergedwith status)))
673 (setq words (format "%s,%s"
676 (mapconcat 'number-to-string merged ","))
678 (when (or (not merged)
679 (not (let ((found nil))
680 (dolist (id (if (listp merged)
683 (dolist (entry tabulated-list-entries)
684 (when (equal id (cdr (assq 'id (car entry))))
688 'tabulated-list-entries
696 (if (memq id debbugs-gnu-local-tags)
700 ;; Mark status and age.
704 ((cdr (assq 'archived status))
705 'debbugs-gnu-archived)
706 ((equal (cdr (assq 'pending status)) "done")
708 ((member "pending" (cdr (assq 'keywords status)))
709 'debbugs-gnu-pending)
710 ;; For some new bugs `date' and `log_modified' may
711 ;; differ in 1 second.
712 ((< (abs (- (cdr (assq 'date status))
713 (cdr (assq 'log_modified status))))
717 (cdr (assq 'log_modified status)))
719 'debbugs-gnu-handled)
721 'debbugs-gnu-stale)))
723 ;; Prefer the name over the address.
728 ;; Mark own submitted bugs.
729 (if (and (stringp (car address))
730 (string-equal (car address) user-mail-address))
737 (if (and (stringp owner)
738 (string-equal owner user-mail-address))
743 (tabulated-list-init-header)
744 (tabulated-list-print)
746 (set-buffer-modified-p nil)
747 (goto-char (point-min))))
749 (defun debbugs-gnu-print-entry (list-id cols)
750 "Insert a debbugs entry at point.
751 Used instead of `tabulated-list-print-entry'."
756 (id-length (nth 1 (aref tabulated-list-format 0)))
757 (state (aref cols 1))
758 (state-length (nth 1 (aref tabulated-list-format 1)))
759 (submitter (aref cols 2))
760 (submitter-length (nth 1 (aref tabulated-list-format 2)))
761 (title (aref cols 3))
762 ;; (title-length (nth 1 (aref tabulated-list-format 3)))
765 ;; We may have a narrowing in effect.
766 (or (not debbugs-gnu-limit)
767 (memq (cdr (assq 'id list-id)) debbugs-gnu-limit))
768 ;; Filter suppressed bugs.
769 (or (not debbugs-gnu-local-suppress)
770 (not (catch :suppress
771 (dolist (check debbugs-gnu-default-suppress-bugs)
775 (or (cdr (assq (car check) list-id)) ""))
776 (throw :suppress t))))))
777 ;; Filter search list.
778 (not (catch :suppress
779 (dolist (check debbugs-gnu-local-filter)
780 (let ((val (cdr (assq (car check) list-id))))
781 (if (stringp (cdr check))
782 ;; Regular expression.
783 (when (not (string-match (cdr check) (or val "")))
786 (when (or (and (numberp (cadr check))
787 (< (cadr check) val))
788 (and (numberp (cddr check))
789 (> (cddr check) val)))
790 (throw :suppress t))))))))
793 (indent-to (- id-length (length id)))
796 (indent-to (setq pos (+ pos id-length 1)) 1)
797 (insert (if (> (length state) state-length)
798 (propertize (substring state 0 state-length)
802 (indent-to (setq pos (+ pos state-length 1)) 1)
803 (insert "[" (if (> (length submitter) (- submitter-length 2))
804 (propertize (substring submitter 0 (- submitter-length 2))
805 'help-echo submitter)
807 (indent-to (+ pos (1- submitter-length)))
810 (indent-to (setq pos (+ pos submitter-length 1)) 1)
811 (insert (propertize title 'help-echo title))
815 `(tabulated-list-id ,list-id mouse-face highlight))
818 (defun debbugs-gnu-menu-map-emacs-enabled ()
819 "Whether \"Show Release Blocking Bugs\" is enabled in the menu."
820 (or ;; No package discriminator has been used.
821 (not (assq 'package debbugs-gnu-local-query))
822 ;; Package "emacs" has been selected.
823 (member '(package . "emacs") debbugs-gnu-local-query)))
825 (defconst debbugs-gnu-bug-triage-file
826 (expand-file-name "../admin/notes/bug-triage" data-directory)
827 "The \"bug-triage\" file.")
829 (defun debbugs-gnu-menu-map-bug-triage-enabled ()
830 "Whether \"Describe Bug Triage Procedure\" is enabled in the menu."
831 (and (debbugs-gnu-menu-map-emacs-enabled)
832 (stringp debbugs-gnu-bug-triage-file)
833 (file-readable-p debbugs-gnu-bug-triage-file)))
835 (defun debbugs-gnu-view-bug-triage ()
836 "Show \"bug-triage\" file."
838 (view-file debbugs-gnu-bug-triage-file))
840 (defvar debbugs-gnu-mode-map
841 (let ((map (make-sparse-keymap))
842 (menu-map (make-sparse-keymap)))
843 (set-keymap-parent map tabulated-list-mode-map)
844 (define-key map "\r" 'debbugs-gnu-select-report)
845 (define-key map [mouse-1] 'debbugs-gnu-select-report)
846 (define-key map [mouse-2] 'debbugs-gnu-select-report)
847 (define-key map "g" 'debbugs-gnu-rescan)
848 (define-key map "R" 'debbugs-gnu-show-all-blocking-reports)
849 (define-key map "C" 'debbugs-gnu-send-control-message)
851 (define-key map "s" 'debbugs-gnu-toggle-sort)
852 (define-key map "t" 'debbugs-gnu-toggle-tag)
853 (define-key map "x" 'debbugs-gnu-toggle-suppress)
854 (define-key map "/" 'debbugs-gnu-narrow-to-status)
855 (define-key map "w" 'debbugs-gnu-widen)
857 (define-key map "b" 'debbugs-gnu-show-blocked-by-reports)
858 (define-key map "B" 'debbugs-gnu-show-blocking-reports)
859 (define-key map "d" 'debbugs-gnu-display-status)
861 (define-key map [menu-bar debbugs] (cons "Debbugs" menu-map))
862 (define-key menu-map [debbugs-gnu-select-report]
863 '(menu-item "Show Reports" debbugs-gnu-select-report
864 :help "Show all reports belonging to this bug"))
865 (define-key-after menu-map [debbugs-gnu-rescan]
866 '(menu-item "Refresh Bugs" debbugs-gnu-rescan
867 :help "Refresh bug list")
868 'debbugs-gnu-select-report)
869 (define-key-after menu-map [debbugs-gnu-show-all-blocking-reports]
870 '(menu-item "Show Release Blocking Bugs"
871 debbugs-gnu-show-all-blocking-reports
872 :enable (debbugs-gnu-menu-map-emacs-enabled)
873 :help "Show all bugs blocking next Emacs release")
875 (define-key-after menu-map [debbugs-gnu-send-control-message]
876 '(menu-item "Send Control Message"
877 debbugs-gnu-send-control-message
878 :help "Send control message to debbugs.gnu.org")
879 'debbugs-gnu-show-all-blocking-reports)
881 (define-key-after menu-map [debbugs-gnu-separator1]
882 '(menu-item "--") 'debbugs-gnu-send-control-message)
883 (define-key-after menu-map [debbugs-gnu-search]
884 '(menu-item "Search Bugs" debbugs-gnu-search
885 :help "Search bugs on debbugs.gnu.org")
886 'debbugs-gnu-separator1)
887 (define-key-after menu-map [debbugs-gnu]
888 '(menu-item "Retrieve Bugs" debbugs-gnu
889 :help "Retrieve bugs from debbugs.gnu.org")
891 (define-key-after menu-map [debbugs-gnu-bugs]
892 '(menu-item "Retrieve Bugs by Number" debbugs-gnu-bugs
893 :help "Retrieve selected bugs from debbugs.gnu.org")
896 (define-key-after menu-map [debbugs-gnu-separator2]
897 '(menu-item "--") 'debbugs-gnu-bugs)
898 (define-key-after menu-map [debbugs-gnu-view-bug-triage]
899 '(menu-item "Describe Bug Triage Procedure"
900 debbugs-gnu-view-bug-triage
901 :enable (debbugs-gnu-menu-map-bug-triage-enabled)
902 :help "Show procedure of triaging bugs")
903 'debbugs-gnu-separator2)
906 (defun debbugs-gnu-rescan ()
907 "Rescan the current set of bug reports."
909 (let ((id (debbugs-gnu-current-id))
910 (debbugs-gnu-current-query debbugs-gnu-local-query)
911 (debbugs-gnu-current-filter debbugs-gnu-local-filter)
912 (debbugs-gnu-current-suppress debbugs-gnu-local-suppress)
913 (debbugs-cache-expiry (if current-prefix-arg t debbugs-cache-expiry)))
914 (debbugs-gnu-show-reports)
916 (debbugs-gnu-goto id))))
918 (define-derived-mode debbugs-gnu-mode tabulated-list-mode "Debbugs"
919 "Major mode for listing bug reports.
921 All normal editing commands are switched off.
922 \\<debbugs-gnu-mode-map>
924 The following commands are available:
926 \\{debbugs-gnu-mode-map}"
927 (set (make-local-variable 'debbugs-gnu-sort-state) 'number)
928 (set (make-local-variable 'debbugs-gnu-limit) nil)
929 (set (make-local-variable 'debbugs-gnu-local-query)
930 debbugs-gnu-current-query)
931 (set (make-local-variable 'debbugs-gnu-local-filter)
932 debbugs-gnu-current-filter)
933 (set (make-local-variable 'debbugs-gnu-local-suppress)
934 debbugs-gnu-current-suppress)
935 (setq tabulated-list-format [("Id" 5 debbugs-gnu-sort-id)
936 ("State" 20 debbugs-gnu-sort-state)
938 ("Title" 10 debbugs-gnu-sort-title)])
939 (setq tabulated-list-sort-key (cons "Id" nil))
940 (setq tabulated-list-printer 'debbugs-gnu-print-entry)
941 (buffer-disable-undo)
942 (setq truncate-lines t)
943 (setq buffer-read-only t))
945 (defun debbugs-gnu-sort-id (s1 s2)
946 (> (cdr (assq 'id (car s1)))
947 (cdr (assq 'id (car s2)))))
949 (defconst debbugs-gnu-state-preference
950 '((debbugs-gnu-new . 1)
951 (debbugs-gnu-stale . 2)
952 (debbugs-gnu-handled . 3)
953 (debbugs-gnu-done . 4)
954 (debbugs-gnu-pending . 5)))
956 (defun debbugs-gnu-get-state-preference (face-string)
957 (or (cdr (assq (get-text-property 0 'face face-string)
958 debbugs-gnu-state-preference))
961 (defconst debbugs-gnu-severity-preference
968 (defun debbugs-gnu-get-severity-preference (state)
969 (or (cdr (assoc (cdr (assq 'severity state))
970 debbugs-gnu-severity-preference))
973 (defun debbugs-gnu-sort-state (s1 s2)
974 (let ((id1 (cdr (assq 'id (car s1))))
975 (age1 (debbugs-gnu-get-state-preference (aref (nth 1 s1) 1)))
976 (id2 (cdr (assq 'id (car s2))))
977 (age2 (debbugs-gnu-get-state-preference (aref (nth 1 s2) 1))))
979 ;; Tagged bugs go to the end.
980 ((and (not (memq id1 debbugs-gnu-local-tags))
981 (memq id2 debbugs-gnu-local-tags))
983 ((and (memq id1 debbugs-gnu-local-tags)
984 (not (memq id2 debbugs-gnu-local-tags)))
986 ;; Then, we check the age of the bugs.
991 ;; If they have the same age, we check for severity.
992 ((< (debbugs-gnu-get-severity-preference (car s1))
993 (debbugs-gnu-get-severity-preference (car s2)))
997 (defun debbugs-gnu-sort-title (s1 _s2)
998 (let ((owner (if (cdr (assq 'owner (car s1)))
999 (car (mail-header-parse-address
1000 (decode-coding-string (cdr (assq 'owner (car s1)))
1002 (and (stringp owner)
1003 (string-equal owner user-mail-address))))
1005 (defun debbugs-gnu-toggle-sort ()
1006 "Toggle sorting by age and by state."
1008 (if (eq debbugs-gnu-sort-state 'number)
1010 (setq debbugs-gnu-sort-state 'state)
1011 (setq tabulated-list-sort-key (cons "Id" nil)))
1012 (setq debbugs-gnu-sort-state 'number)
1013 (setq tabulated-list-sort-key (cons "State" nil)))
1014 (tabulated-list-init-header)
1015 (tabulated-list-print))
1017 (defun debbugs-gnu-widen ()
1018 "Display all the currently selected bug reports."
1020 (let ((id (debbugs-gnu-current-id t))
1021 (inhibit-read-only t))
1022 (setq debbugs-gnu-limit nil)
1023 (tabulated-list-init-header)
1024 (tabulated-list-print)
1026 (debbugs-gnu-goto id))))
1028 (defun debbugs-gnu-show-blocked-by-reports ()
1029 "Display all bug reports this report is blocked by."
1031 (let ((id (debbugs-gnu-current-id))
1032 (status (debbugs-gnu-current-status)))
1033 (if (null (cdr (assq 'blockedby status)))
1034 (message "Bug %d is not blocked by any other bug" id)
1035 (apply 'debbugs-gnu-bugs (cdr (assq 'blockedby status))))))
1037 (defun debbugs-gnu-show-blocking-reports ()
1038 "Display all bug reports this report is blocking."
1040 (let ((id (debbugs-gnu-current-id))
1041 (status (debbugs-gnu-current-status)))
1042 (if (null (cdr (assq 'blocks status)))
1043 (message "Bug %d is not blocking any other bug" id)
1044 (apply 'debbugs-gnu-bugs (cdr (assq 'blocks status))))))
1046 (defun debbugs-gnu-show-all-blocking-reports ()
1047 "Narrow the display to just the reports that are blocking a release."
1049 (let ((blockers (cdr (assq 'blockedby
1050 (car (debbugs-get-status
1051 debbugs-gnu-blocking-report)))))
1052 (id (debbugs-gnu-current-id t))
1053 (inhibit-read-only t)
1055 (setq debbugs-gnu-limit nil)
1056 (goto-char (point-min))
1058 (setq status (debbugs-gnu-current-status))
1059 (if (not (memq (cdr (assq 'id status)) blockers))
1060 (delete-region (point) (progn (forward-line 1) (point)))
1061 (push (cdr (assq 'id status)) debbugs-gnu-limit)
1064 (debbugs-gnu-goto id))))
1066 (defun debbugs-gnu-narrow-to-status (string &optional status-only)
1067 "Only display the bugs matching STRING.
1068 If STATUS-ONLY (the prefix), ignore matches in the From and
1070 (interactive "sNarrow to: \nP")
1071 (let ((id (debbugs-gnu-current-id t))
1072 (inhibit-read-only t)
1074 (setq debbugs-gnu-limit nil)
1075 (if (equal string "")
1076 (debbugs-gnu-toggle-suppress)
1077 (goto-char (point-min))
1079 (setq status (debbugs-gnu-current-status))
1080 (if (and (not (member string (assq 'keywords status)))
1081 (not (equal string (cdr (assq 'severity status))))
1084 string (cdr (assq 'originator status)))))
1086 (not (string-match string (cdr (assq 'subject status))))))
1087 (delete-region (point) (progn (forward-line 1) (point)))
1088 (push (cdr (assq 'id status)) debbugs-gnu-limit)
1091 (debbugs-gnu-goto id)))))
1093 (defun debbugs-gnu-goto (id)
1094 "Go to the line displaying bug ID."
1095 (goto-char (point-min))
1096 (while (and (not (eobp))
1097 (not (equal (debbugs-gnu-current-id t) id)))
1100 (defun debbugs-gnu-toggle-tag ()
1101 "Toggle the local tag of the report in the current line.
1102 If a report is tagged locally, it is presumed to be of little
1107 (let ((inhibit-read-only t)
1108 (id (debbugs-gnu-current-id)))
1109 (if (memq id debbugs-gnu-local-tags)
1111 (setq debbugs-gnu-local-tags (delq id debbugs-gnu-local-tags))
1112 (put-text-property (point) (+ (point) 5) 'face 'default))
1113 (add-to-list 'debbugs-gnu-local-tags id)
1115 (+ (point) (- 5 (length (number-to-string id)))) (+ (point) 5)
1116 'face 'debbugs-gnu-tagged))
1117 (debbugs-gnu--update-tag-face id)))
1118 (debbugs-gnu-dump-persistency-file))
1120 (defun debbugs-gnu--update-tag-face (id)
1121 (dolist (entry tabulated-list-entries)
1122 (when (equal (cdr (assq 'id (car entry))) id)
1123 (aset (cadr entry) 0
1127 ;; Mark tagged bugs.
1128 (if (memq id debbugs-gnu-local-tags)
1132 (defun debbugs-gnu-toggle-suppress ()
1133 "Suppress bugs marked in `debbugs-gnu-suppress-bugs'."
1135 (setq debbugs-gnu-local-suppress (not debbugs-gnu-local-suppress))
1136 (tabulated-list-init-header)
1137 (tabulated-list-print))
1139 (defvar debbugs-gnu-bug-number nil)
1140 (defvar debbugs-gnu-subject nil)
1142 (defun debbugs-gnu-current-id (&optional noerror)
1143 (or (cdr (assq 'id (debbugs-gnu-current-status)))
1145 (error "No bug on the current line"))))
1147 (defun debbugs-gnu-current-status ()
1148 (get-text-property (line-beginning-position) 'tabulated-list-id))
1150 (defun debbugs-gnu-display-status (query filter status)
1151 "Display the query, filter and status of the report on the current line."
1152 (interactive (list debbugs-gnu-local-query
1153 debbugs-gnu-local-filter
1154 (debbugs-gnu-current-status)))
1155 (switch-to-buffer "*Bug Status*")
1156 (let ((inhibit-read-only t))
1159 (insert ";; Query\n")
1160 (pp query (current-buffer))
1163 (insert ";; Filter\n")
1164 (pp filter (current-buffer))
1167 (insert ";; Status\n")
1168 (pp status (current-buffer)))
1169 (goto-char (point-min)))
1170 (set-buffer-modified-p nil)
1173 (defun debbugs-read-emacs-bug-with-rmail (id status merged)
1174 "Read email exchange for debbugs bug ID.
1175 STATUS is the bug's status list.
1176 MERGED is the list of bugs merged with this one."
1177 (let* ((mbox-dir (make-temp-file "debbugs" t))
1178 (mbox-fname (format "%s/bug_%d.mbox" mbox-dir id)))
1179 (debbugs-get-mbox id 'mboxmaint mbox-fname)
1181 ;; Download messages of all the merged bug reports and append them
1182 ;; to the mailbox of the requested bug.
1184 (dolist (bugno merged)
1185 (let ((fn (make-temp-file "url")))
1186 (debbugs-get-mbox bugno 'mboxmaint fn)
1187 (rmail-get-new-mail fn)
1189 ;; Remove the 'unseen' attribute from all the messages we've
1190 ;; just read, so that all of them appear in the summary with
1192 (while (< rmail-current-message rmail-total-messages)
1193 (rmail-show-message (1+ rmail-current-message))))))
1194 (set (make-local-variable 'debbugs-gnu-bug-number) id)
1195 (set (make-local-variable 'debbugs-gnu-subject)
1196 (format "Re: bug#%d: %s" id (cdr (assq 'subject status))))
1198 (define-key rmail-summary-mode-map "C" 'debbugs-gnu-send-control-message)
1199 (set-window-text-height nil 10)
1201 (define-key rmail-mode-map "C" 'debbugs-gnu-send-control-message)
1202 (rmail-show-message 1)))
1204 (defun debbugs-read-emacs-bug-with-gnus (id status merged)
1205 "Read email exchange for debbugs bug ID.
1206 STATUS is the bug's status list.
1207 MERGED is the list of bugs merged with this one."
1209 (setq gnus-suppress-duplicates t
1210 gnus-save-duplicate-list t)
1212 (gnus-read-ephemeral-emacs-bug-group
1213 (cons id (if (listp merged) merged (list merged)))
1214 (cons (current-buffer)
1215 (current-window-configuration)))
1216 (with-current-buffer (window-buffer (selected-window))
1217 (set (make-local-variable 'debbugs-gnu-bug-number) id)
1218 (set (make-local-variable 'debbugs-gnu-subject)
1219 (format "Re: bug#%d: %s" id (cdr (assq 'subject status))))
1220 (debbugs-gnu-summary-mode 1)))
1222 (defun debbugs-gnu-select-report ()
1223 "Select the report on the current line."
1225 ;; We open the report messages.
1226 (let* ((status (debbugs-gnu-current-status))
1227 (id (cdr (assq 'id status)))
1228 (merged (cdr (assq 'mergedwith status))))
1229 (setq merged (if (listp merged) merged (list merged)))
1232 (message "No bug report on the current line"))
1233 ((eq debbugs-gnu-mail-backend 'rmail)
1234 (debbugs-read-emacs-bug-with-rmail id status merged))
1235 ((eq debbugs-gnu-mail-backend 'gnus)
1236 (debbugs-read-emacs-bug-with-gnus id status merged))
1237 (t (error "No valid mail backend specified")))))
1239 (defvar debbugs-gnu-summary-mode-map
1240 (let ((map (make-sparse-keymap)))
1241 (define-key map "C" 'debbugs-gnu-send-control-message)
1242 (define-key map [(meta m)] 'debbugs-gnu-apply-patch)
1245 (define-minor-mode debbugs-gnu-summary-mode
1246 "Minor mode for providing a debbugs interface in Gnus summary buffers.
1248 \\{debbugs-gnu-summary-mode-map}"
1249 :lighter " Debbugs" :keymap debbugs-gnu-summary-mode-map
1250 (set (make-local-variable 'gnus-posting-styles)
1253 (when (buffer-live-p gnus-article-copy)
1254 (with-current-buffer gnus-article-copy
1255 (set (make-local-variable 'message-prune-recipient-rules)
1256 '((".*@debbugs.*" "emacs-pretest-bug")
1257 (".*@debbugs.*" "bug-gnu-emacs")
1258 ("[0-9]+@debbugs.*" "submit@debbugs.gnu.org")
1259 ("[0-9]+@debbugs.*" "quiet@debbugs.gnu.org")))
1260 (set (make-local-variable 'message-alter-recipients-function)
1262 (if (string-match "\\([0-9]+\\)@donarmstrong"
1264 (let ((new (format "%s@debbugs.gnu.org"
1265 (match-string 1 (car address)))))
1268 ;; `gnus-posting-styles' is eval'ed after
1269 ;; `message-simplify-subject'. So we cannot use m-s-s.
1270 (setq subject ,debbugs-gnu-subject))))))))
1272 (defun debbugs-gnu-guess-current-id ()
1273 "Guess the ID based on \"#23\"."
1277 (or (re-search-forward "#\\([0-9]+\\)" (line-end-position) t)
1279 (goto-char (point-min))
1280 (re-search-forward "#\\([0-9]+\\)" nil t)))
1281 (string-to-number (match-string 1)))))
1283 (defvar debbugs-gnu-send-mail-function nil
1284 "A function to send control messages from debbugs.")
1286 (defun debbugs-gnu-send-control-message (message &optional reverse)
1287 "Send a control message for the current bug report.
1288 You can set the severity or add a tag, or close the report. If
1289 you use the special \"done\" MESSAGE, the report will be marked as
1290 fixed, and then closed.
1292 If given a prefix, and given a tag to set, the tag will be
1295 (list (completing-read
1297 '("serious" "important" "normal" "minor" "wishlist"
1298 "done" "donenotabug" "donewontfix" "doneunreproducible"
1299 "unarchive" "unmerge" "reopen" "close"
1300 "merge" "forcemerge"
1306 "patch" "wontfix" "moreinfo" "unreproducible" "fixed" "notabug"
1307 "pending" "help" "security" "confirmed"
1310 current-prefix-arg))
1311 (let* ((id (or (debbugs-gnu-current-id t)
1312 debbugs-gnu-bug-number ; Set on group entry.
1313 (debbugs-gnu-guess-current-id)))
1315 (when (member message '("close" "done"))
1319 ;; Emacs development versions.
1321 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\." emacs-version)
1323 (match-string 1 emacs-version)
1324 (1+ (string-to-number (match-string 2 emacs-version)))))
1325 ;; Emacs release versions.
1327 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)$" emacs-version)
1329 (match-string 1 emacs-version)
1330 (match-string 2 emacs-version)))
1331 (t emacs-version)))))
1332 (status (debbugs-gnu-current-status)))
1334 (insert "To: control@debbugs.gnu.org\n"
1335 "From: " (message-make-from) "\n"
1336 (format "Subject: control message for bug #%d\n" id)
1337 mail-header-separator
1340 ((member message '("unarchive" "unmerge" "reopen" "noowner"))
1341 (format "%s %d\n" message id))
1342 ((member message '("merge" "forcemerge"))
1343 (format "%s %d %s\n" message id
1344 (read-string "Merge with bug #: ")))
1345 ((member message '("block" "unblock"))
1347 "%s %d by %s\n" message id
1350 (completing-read-multiple
1351 (format "%s with bug(s) #: " (capitalize message))
1352 (if (equal message "unblock")
1353 (mapcar 'number-to-string
1354 (cdr (assq 'blockedby status))))
1355 nil (and (equal message "unblock") status))
1357 ((equal message "owner")
1358 (format "owner %d !\n" id))
1359 ((equal message "retitle")
1360 (format "retitle %d %s\n" id (read-string "New title: ")))
1361 ((equal message "reassign")
1362 (format "reassign %d %s\n" id (read-string "Package(s): ")))
1363 ((equal message "close")
1364 (format "close %d %s\n" id version))
1365 ((equal message "done")
1366 (format "tags %d fixed\nclose %d %s\n" id id version))
1367 ((member message '("donenotabug" "donewontfix"
1368 "doneunreproducible"))
1369 (format "tags %d %s\nclose %d\n" id (substring message 4) id))
1370 ((member message '("serious" "important" "normal"
1371 "minor" "wishlist"))
1372 (format "severity %d %s\n" id message))
1373 ((equal message "invalid")
1374 (format "tags %d notabug\ntags %d wontfix\nclose %d\n"
1376 ((equal message "usertag")
1377 (format "user %s\nusertag %d %s\n"
1379 "Package name or email address: "
1381 debbugs-gnu-all-packages (list user-mail-address))
1382 nil nil (car debbugs-gnu-default-packages))
1383 id (read-string "User tag: ")))
1385 (format "tags %d%s %s\n"
1386 id (if reverse " -" "")
1388 (funcall (or debbugs-gnu-send-mail-function send-mail-function))
1389 (remhash id debbugs-cache-data)
1391 (message "Control message sent:\n%s"
1392 (buffer-substring-no-properties (point) (1- (point-max)))))))
1394 (defvar debbugs-gnu-usertags-mode-map
1395 (let ((map (make-sparse-keymap)))
1396 (set-keymap-parent map tabulated-list-mode-map)
1397 (define-key map "\r" 'debbugs-gnu-select-usertag)
1398 (define-key map [mouse-1] 'debbugs-gnu-select-usertag)
1399 (define-key map [mouse-2] 'debbugs-gnu-select-usertag)
1402 (define-derived-mode debbugs-gnu-usertags-mode tabulated-list-mode "Usertags"
1403 "Major mode for listing user tags.
1405 All normal editing commands are switched off.
1406 \\<debbugs-gnu-usertags-mode-map>
1408 The following commands are available:
1410 \\{debbugs-gnu-usertags-mode-map}"
1411 (buffer-disable-undo)
1412 (setq truncate-lines t)
1413 (setq buffer-read-only t))
1416 (defun debbugs-gnu-usertags (&rest users)
1417 "List all user tags for USERS, which is \(\"emacs\"\) by default."
1419 (if current-prefix-arg
1420 (completing-read-multiple
1421 "Package name(s) or email address: "
1422 (append debbugs-gnu-all-packages (list user-mail-address)) nil nil
1423 (mapconcat 'identity debbugs-gnu-default-packages ","))
1424 debbugs-gnu-default-packages))
1427 (let ((inhibit-read-only t)
1428 (debbugs-port "gnu.org")
1429 (buffer-name "*Emacs User Tags*")
1431 (1+ (apply 'max (length "User") (mapcar 'length users)))))
1433 ;; Initialize variables.
1434 (when (and (file-exists-p debbugs-gnu-persistency-file)
1435 (not debbugs-gnu-local-tags))
1437 (insert-file-contents debbugs-gnu-persistency-file)
1438 (eval (read (current-buffer)))))
1441 (when (get-buffer buffer-name)
1442 (kill-buffer buffer-name))
1443 (switch-to-buffer (get-buffer-create buffer-name))
1444 (debbugs-gnu-usertags-mode)
1445 (setq tabulated-list-format `[("User" ,user-tab-length t)
1447 (setq tabulated-list-sort-key (cons "User" nil))
1448 ;(setq tabulated-list-printer 'debbugs-gnu-print-entry)
1450 ;; Retrieve user tags.
1451 (dolist (user users)
1452 (dolist (tag (sort (debbugs-get-usertag :user user) 'string<))
1454 'tabulated-list-entries
1455 ;; `tabulated-list-id' is the parameter list for `debbugs-gnu'.
1456 `((("tagged") (,user) nil nil (,tag))
1457 ,(vector (propertize user 'mouse-face 'highlight)
1458 (propertize tag 'mouse-face 'highlight)))
1462 (when debbugs-gnu-local-tags
1464 'tabulated-list-entries
1467 "" (propertize "(local tags)" 'mouse-face 'highlight)))))
1470 (tabulated-list-init-header)
1471 (tabulated-list-print)
1473 (set-buffer-modified-p nil)
1474 (goto-char (point-min)))))
1476 (defun debbugs-gnu-select-usertag ()
1477 "Select the user tag on the current line."
1479 ;; We open the bug reports.
1480 (let ((args (get-text-property (line-beginning-position) 'tabulated-list-id)))
1481 (when args (apply 'debbugs-gnu args))))
1484 (defun debbugs-gnu-bugs (&rest bugs)
1485 "List all BUGS, a list of bug numbers."
1487 (mapcar 'string-to-number
1488 (completing-read-multiple "Bug numbers: " nil 'natnump)))
1490 (unless (natnump elt) (signal 'wrong-type-argument (list 'natnump elt))))
1491 (add-to-list 'debbugs-gnu-current-query (cons 'bugs bugs))
1492 ;; We do not suppress bugs requested explicitely.
1493 (setq debbugs-gnu-current-suppress nil)
1496 (defvar debbugs-gnu-trunk-directory "~/src/emacs/trunk/"
1497 "The directory where the main source tree lives.")
1499 (defvar debbugs-gnu-branch-directory "~/src/emacs/emacs-25/"
1500 "The directory where the previous source tree lives.")
1502 (defun debbugs-gnu-apply-patch (&optional branch)
1503 "Apply the patch from the current message.
1504 If given a prefix, patch in the branch directory instead."
1506 (add-hook 'emacs-lisp-mode-hook 'debbugs-gnu-lisp-mode)
1507 (add-hook 'diff-mode-hook 'debbugs-gnu-diff-mode)
1508 (add-hook 'change-log-mode-hook 'debbugs-gnu-change-mode)
1509 (let ((rej "/tmp/debbugs-gnu.rej")
1510 (output-buffer (get-buffer-create "*debbugs patch*"))
1512 debbugs-gnu-branch-directory
1513 debbugs-gnu-trunk-directory))
1514 (patch-buffers nil))
1515 (when (file-exists-p rej)
1517 (with-current-buffer output-buffer
1519 (gnus-summary-select-article nil t)
1520 ;; The patches are either in MIME attachements or the main article
1521 ;; buffer. Determine which.
1522 (gnus-with-article-buffer
1523 (dolist (handle (mapcar 'cdr (gnus-article-mime-handles)))
1524 (when (string-match "diff\\|patch\\|plain" (mm-handle-media-type handle))
1525 (push (cons (mm-handle-encoding handle)
1526 (mm-handle-buffer handle))
1528 (unless patch-buffers
1529 (gnus-summary-show-article 'raw)
1530 (article-decode-charset)
1531 (push (cons nil gnus-article-buffer) patch-buffers))
1532 (dolist (elem patch-buffers)
1533 (with-current-buffer (generate-new-buffer "*debbugs input patch*")
1534 (insert-buffer-substring (cdr elem))
1535 (cond ((eq (car elem) 'base64)
1536 (base64-decode-region (point-min) (point-max)))
1537 ((eq (car elem) 'quoted-printable)
1538 (quoted-printable-decode-region (point-min) (point-max))))
1539 (debbugs-gnu-fix-patch dir)
1540 (call-process-region (point-min) (point-max)
1541 "patch" nil output-buffer nil
1542 "-r" rej "--no-backup-if-mismatch"
1544 "-d" (expand-file-name dir)
1546 (set-buffer output-buffer)
1547 (when (file-exists-p rej)
1548 (goto-char (point-max))
1549 (insert-file-contents-literally rej))
1550 (goto-char (point-max))
1551 (save-some-buffers t)
1553 (mapc 'kill-process compilation-in-progress)
1554 (compile (format "cd %s; make -k" (expand-file-name "lisp" dir)))
1556 (vc-dir-hide-up-to-date)
1557 (goto-char (point-min))
1560 ;; All these commands are asynchronous, so just wait a bit. This
1561 ;; should be done properly a different way.
1563 ;; We've now done everything, so arrange the windows we need to see.
1564 (delete-other-windows)
1565 (switch-to-buffer output-buffer)
1569 (switch-to-buffer "*compilation*")
1570 (goto-char (point-max))
1572 (switch-to-buffer "*vc-diff*")
1573 (goto-char (point-min))))
1575 (defun debbugs-gnu-fix-patch (dir)
1576 (setq dir (directory-file-name (expand-file-name dir)))
1577 (goto-char (point-min))
1578 (while (re-search-forward diff-file-header-re nil t)
1579 (goto-char (match-beginning 0))
1580 (let ((target-name (car (diff-hunk-file-names))))
1581 (when (and target-name
1582 (or (not (string-match "/" target-name))
1583 (and (string-match "^[ab]/" target-name)
1585 (expand-file-name (substring target-name 2)
1587 (file-exists-p (expand-file-name target-name dir))))
1588 ;; We have a simple patch that refers to a file somewhere in the
1590 (when-let ((files (directory-files-recursively
1592 (concat "^" (regexp-quote
1593 (file-name-nondirectory target-name))
1595 (when (re-search-forward (concat "^[+]+ "
1596 (regexp-quote target-name)
1599 (replace-match (concat "+++ a"
1600 (substring (car files) (length dir))
1605 (defun debbugs-gnu-find-contributor (string)
1606 "Search through ChangeLogs to find contributors."
1607 (interactive "sContributor match: ")
1609 (match (concat "^[0-9].*" string)))
1610 (dolist (file (directory-files-recursively
1611 debbugs-gnu-trunk-directory "ChangeLog\\(.[0-9]+\\)?$"))
1613 (when (file-exists-p file)
1614 (insert-file-contents file))
1615 (goto-char (point-min))
1616 (while (and (re-search-forward match nil t)
1617 (not (looking-at ".*tiny change")))
1619 (message "%s is a contributor %d times" string found)
1622 (defvar debbugs-gnu-patch-subject nil)
1624 (defun debbugs-gnu-insert-changelog ()
1625 "Add a ChangeLog from a recently applied patch from a third party."
1627 (let (from subject patch-subject changelog)
1628 (gnus-with-article-buffer
1630 (goto-char (point-min))
1631 (setq from (mail-extract-address-components (gnus-fetch-field "from"))
1632 subject (gnus-fetch-field "subject"))
1633 ;; If it's a patch formatted the right way, extract that data.
1634 (dolist (handle (mapcar 'cdr (gnus-article-mime-handles)))
1635 (when (string-match "diff\\|patch\\|plain"
1636 (mm-handle-media-type handle))
1638 (insert-buffer-substring (mm-handle-buffer handle))
1639 (cond ((eq (mm-handle-encoding handle) 'base64)
1640 (base64-decode-region (point-min) (point-max)))
1641 ((eq (mm-handle-encoding handle) 'quoted-printable)
1642 (quoted-printable-decode-region (point-min) (point-max))))
1644 (or (gnus-fetch-field "subject") patch-subject))
1645 (goto-char (point-min))
1646 (when (re-search-forward "^[*] " nil t)
1647 (let ((start (match-beginning 0)))
1648 (while (and (not (eobp))
1649 (not (looking-at "---")))
1651 (setq changelog (buffer-substring
1652 start (line-end-position 0)))))))))
1653 (let ((add-log-full-name (car from))
1654 (add-log-mailing-address (cadr from)))
1655 (add-change-log-entry-other-window)
1657 (setq-local debbugs-gnu-patch-subject patch-subject))
1659 (delete-region (line-beginning-position) (point-max))
1661 (narrow-to-region (point) (point))
1663 (indent-region (point-min) (point-max))))
1664 (let ((point (point)))
1665 (when (string-match "\\(bug#[0-9]+\\)" subject)
1666 (insert " (" (match-string 1 subject) ")."))
1667 (when (zerop (debbugs-gnu-find-contributor
1668 (let ((bits (split-string (car from))))
1670 ((>= (length bits) 2)
1671 (format "%s.*%s" (car bits) (car (last bits))))
1672 ((= (length bits) 1)
1674 ;; Fall back on the email address.
1677 (goto-char (point-max))
1681 (insert " Copyright-paperwork-exempt: yes"))
1682 (goto-char point)))))
1684 (defvar debbugs-gnu-lisp-mode-map
1685 (let ((map (make-sparse-keymap)))
1686 (define-key map [(meta m)] 'debbugs-gnu-insert-changelog)
1689 (define-minor-mode debbugs-gnu-lisp-mode
1690 "Minor mode for providing a debbugs interface in Lisp buffers.
1691 \\{debbugs-gnu-lisp-mode-map}"
1692 :lighter " Debbugs" :keymap debbugs-gnu-lisp-mode-map)
1694 (defvar debbugs-gnu-diff-mode-map
1695 (let ((map (make-sparse-keymap)))
1696 (define-key map [(meta m)] 'debbugs-gnu-diff-select)
1699 (define-minor-mode debbugs-gnu-diff-mode
1700 "Minor mode for providing a debbugs interface in diff buffers.
1701 \\{debbugs-gnu-diff-mode-map}"
1702 :lighter " Debbugs" :keymap debbugs-gnu-diff-mode-map)
1704 (defun debbugs-gnu-diff-select ()
1705 "Select the diff under point."
1707 (delete-other-windows)
1710 (defvar debbugs-gnu-change-mode-map
1711 (let ((map (make-sparse-keymap)))
1712 (define-key map [(meta m)] 'debbugs-gnu-change-checkin)
1715 (define-minor-mode debbugs-gnu-change-mode
1716 "Minor mode for providing a debbugs interface in ChangeLog buffers.
1717 \\{debbugs-gnu-change-mode-map}"
1718 :lighter " Debbugs" :keymap debbugs-gnu-change-mode-map)
1720 (defun debbugs-gnu-change-checkin ()
1721 "Prepare checking in the current changes."
1723 (save-some-buffers t)
1724 (when (get-buffer "*vc-dir*")
1725 (kill-buffer (get-buffer "*vc-dir*")))
1726 (let ((patch-subject debbugs-gnu-patch-subject))
1727 (let ((trunk (expand-file-name debbugs-gnu-trunk-directory)))
1728 (if (equal (cl-subseq default-directory 0 (length trunk))
1730 (vc-dir debbugs-gnu-trunk-directory)
1731 (vc-dir debbugs-gnu-branch-directory)))
1732 (goto-char (point-min))
1733 (while (not (search-forward "edited" nil t))
1736 (while (search-forward "edited" nil t)
1738 (beginning-of-line))
1740 (vc-next-action nil)
1741 (delete-region (point-min) (point-max))
1742 (log-edit-insert-changelog t)
1743 (delete-other-windows)
1746 (switch-to-buffer "*vc-diff*")
1750 (replace-regexp-in-string "^ *\\[PATCH\\] *" "" patch-subject)
1753 (defun debbugs-gnu-save-cache ()
1754 "Save the bugs cache to a file."
1756 (unless debbugs-cache-data
1757 (error "No data to cache"))
1758 (unless (file-exists-p "~/.emacs.d/debbugs-cache")
1759 (make-directory "~/.emacs.d/debbugs-cache" t))
1760 (let ((coding-system-for-write 'utf-8))
1761 (with-temp-file "~/.emacs.d/debbugs-cache/list"
1762 (prin1 debbugs-cache-data (current-buffer)))))
1764 (provide 'debbugs-gnu)
1768 ;; * Another random thought - is it possible to implement some local
1769 ;; cache, so only changed bugs are fetched? Glenn Morris.
1771 ;;; debbugs-gnu.el ends here