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