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