1 ;;; debbugs-gnu.el --- interface for the GNU bug tracker
3 ;; Copyright (C) 2011 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: comm, hypermedia, maint
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
30 (eval-when-compile (require 'cl))
32 (autoload 'gnus-read-ephemeral-emacs-bug-group "gnus-group")
33 (autoload 'mail-header-subject "nnheader")
34 (autoload 'gnus-summary-article-header "gnus-sum")
35 (autoload 'message-make-from "message")
37 (defface debbugs-new '((t (:foreground "red")))
38 "Face for new reports that nobody has answered.")
40 (defface debbugs-handled '((t (:foreground "ForestGreen")))
41 "Face for new reports that nobody has answered.")
43 (defface debbugs-stale '((t (:foreground "orange")))
44 "Face for new reports that nobody has answered.")
46 (defface debbugs-done '((t (:foreground "DarkGrey")))
47 "Face for closed bug reports.")
49 (defun debbugs-emacs (severities &optional package suppress-done archivedp)
50 "List all outstanding Emacs bugs."
53 (completing-read "Severity: "
54 '("important" "normal" "minor" "wishlist")
56 (unless (consp severities)
57 (setq severities (list severities)))
58 (pop-to-buffer (get-buffer-create "*Emacs Bugs*"))
60 (let ((debbugs-port "gnu.org")
61 (buffer-read-only nil)
64 (dolist (severity severities)
66 (debbugs-get-bugs :package (or package "emacs")
68 :archive (if archivedp
72 (when (> (length ids) default)
73 (let* ((cursor-in-echo-area nil)
77 "How many reports (available %d, default %d): "
81 (number-to-string default))))
82 (setq ids (last (sort ids '<) (string-to-number input)))))
84 (dolist (status (sort (apply 'debbugs-get-status ids)
86 (< (cdr (assq 'id s1))
87 (cdr (assq 'id s2))))))
88 (when (or (not suppress-done)
89 (not (equal (cdr (assq 'pending status)) "done")))
90 (let ((address (mail-header-parse-address
91 (decode-coding-string (cdr (assq 'originator status))
93 (subject (decode-coding-string (cdr (assq 'subject status))
96 ;; Prefer the name over the address.
100 (format "%5d %-20s [%-23s] %s\n"
101 (cdr (assq 'id status))
105 (cons (cdr (assq 'severity status))
106 (cdr (assq 'keywords status)))
108 (unless (equal (cdr (assq 'pending status)) "pending")
110 (concat words "," (cdr (assq 'pending status)))))
111 (if (> (length words) 20)
112 (propertize (substring words 0 20) 'help-echo words)
114 (if (> (length address) 23)
115 (propertize (substring address 0 23) 'help-echo address)
117 (propertize subject 'help-echo subject)))
120 (+ (point) 5) (+ (point) 26)
123 ((equal (cdr (assq 'pending status)) "done")
125 ((= (cdr (assq 'date status))
126 (cdr (assq 'log_modified status)))
129 (cdr (assq 'log_modified status)))
135 (goto-char (point-min)))
137 (defvar debbugs-mode-map
138 (let ((map (make-sparse-keymap)))
139 (define-key map "\r" 'debbugs-select-report)
140 (define-key map "q" 'kill-buffer)
141 (define-key map "s" 'debbugs-toggle-sort)
144 (defvar debbugs-sort-state 'number)
146 (defun debbugs-mode ()
147 "Major mode for listing bug reports.
149 All normal editing commands are switched off.
152 The following commands are available:
154 \\{debbugs-mode-map}"
156 (kill-all-local-variables)
157 (setq major-mode 'debbugs-mode)
158 (setq mode-name "Debbugs")
159 (use-local-map debbugs-mode-map)
160 (set (make-local-variable 'debbugs-sort-state)
162 (buffer-disable-undo)
163 (setq truncate-lines t)
164 (setq buffer-read-only t))
166 (defvar debbugs-state-preference
169 (debbugs-handled . 3)
172 (defun debbugs-toggle-sort ()
173 "Toggle sorting by age and by state."
176 (let ((buffer-read-only nil)
177 (current-bug (buffer-substring (point) (+ (point) 5))))
178 (goto-char (point-min))
179 (setq debbugs-sort-state
180 (if (eq debbugs-sort-state 'number)
184 nil (lambda () (forward-line 1)) 'end-of-line
186 (if (eq debbugs-sort-state 'number)
187 (string-to-number (buffer-substring (point) (+ (point) 5)))
188 (or (cdr (assq (get-text-property (+ (point) 7) 'face)
189 debbugs-state-preference))
191 (goto-char (point-min))
192 (re-search-forward (concat "^" current-bug) nil t)))
194 (defun debbugs-select-report ()
195 "Select the report on the current line."
200 (if (not (looking-at " *\\([0-9]+\\)"))
201 (error "No bug report on the current line")
202 (setq id (string-to-number (match-string 1)))))
203 (gnus-read-ephemeral-emacs-bug-group
204 id (cons (current-buffer)
205 (current-window-configuration)))
206 (with-current-buffer (window-buffer (selected-window))
207 (debbugs-summary-mode 1))))
209 (defvar debbugs-summary-mode-map
210 (let ((map (make-sparse-keymap)))
211 (define-key map "C" 'debbugs-send-control-message)
214 (define-minor-mode debbugs-summary-mode
215 "Minor mode for providing a debbugs interface in Gnus summary buffers.
217 \\{debbugs-summary-mode-map}"
218 :lighter " Debbugs" :keymap debbugs-summary-mode-map
219 (set (make-local-variable 'gnus-posting-styles)
222 (with-current-buffer gnus-article-copy
223 (set (make-local-variable 'message-prune-recipient-rules)
224 '((".*@debbugs.*" "emacs-pretest-bug")
225 (".*@debbugs.*" "bug-gnu-emacs")))
226 (set (make-local-variable 'message-alter-recipients-function)
228 (if (string-match "\\([0-9]+\\)@donarmstrong" (car address))
229 (let ((new (format "%s@debbugs.gnu.org"
230 (match-string 1 (car address)))))
234 (defun debbugs-send-control-message (message)
235 "Send a control message for the current bug report.
236 You can set the severity or add a tag, or close the report. If
237 you use the special \"done\" MESSAGE, the report will be marked as
238 fixed, and then closed."
240 (list (completing-read
242 '("important" "normal" "minor" "wishlist"
244 "unarchive" "reopen" "close"
246 "patch" "wontfix" "moreinfo" "unreproducible" "fixed" "notabug")
248 (let* ((subject (mail-header-subject (gnus-summary-article-header)))
250 (if (string-match "bug#\\([0-9]+\\)" subject)
251 (string-to-number (match-string 1 subject))
252 (error "No bug number present")))
254 (when (member message '("close" "done"))
258 ;; Emacs development versions.
260 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\." emacs-version)
262 (match-string 1 emacs-version)
263 (1+ (string-to-number (match-string 2 emacs-version)))))
264 ;; Emacs release versions.
266 "^\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)$" emacs-version)
268 (match-string 1 emacs-version)
269 (match-string 2 emacs-version)))
270 (t emacs-version))))))
272 (insert "To: control@debbugs.gnu.org\n"
273 "From: " (message-make-from) "\n"
274 (format "Subject: control message for bug #%d\n" id)
277 ((member message '("unarchive" "reopen"))
278 (format "%s %d\n" message id))
279 ((member message '("merge" "forcemerge"))
280 (format "%s %d %s\n" message id
281 (read-string "Merge with bug #: ")))
282 ((equal message "close")
283 (format "close %d %s\n" id version))
284 ((equal message "done")
285 (format "tags %d fixed\nclose %d %s\n" id id version))
286 ((member message '("important" "normal" "minor" "wishlist"))
287 (format "severity %d %s\n" id message))
289 (format "tags %d %s\n" id message))))
290 (funcall send-mail-function))))
292 (provide 'debbugs-gnu)
296 ;; * Widget-oriented bug overview like webDDTs.
297 ;; * Actions on bugs.
298 ;; * Integration into gnus (nnir).
300 ;;; debbugs-gnu.el ends here