1 ;;; debbugs.el --- SOAP library to access debbugs servers
3 ;; Copyright (C) 2011 Free Software Foundation, Inc.
5 ;; Author: Michael Albinus <michael.albinus@gmx.de>
6 ;; Keywords: comm, hypermedia
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/>.
27 ;; This package provides some basic functions to access a debbugs SOAP
28 ;; server (see <http://wiki.debian.org/DebbugsSoapInterface>).
30 ;; The SOAP functions "get_usertag" and "get_versions" are not
35 ;(setq soap-debug t message-log-max t)
36 (require 'soap-client)
37 (eval-when-compile (require 'cl))
43 (defcustom debbugs-servers
45 :wsdl "http://debbugs.gnu.org/cgi/soap.cgi?WSDL"
46 :bugreport-url "http://debbugs.gnu.org/cgi/bugreport.cgi")
48 :wsdl "http://bugs.debian.org/cgi-bin/soap.cgi?WSDL"
49 :bugreport-url "http://bugs.debian.org/cgi-bin/bugreport.cgi"))
50 "*List of Debbugs server specifiers.
51 Each entry is a list that contains a string identifying the port
52 name and the server parameters in keyword-value form. Allowed
55 `:wsdl' -- Location of WSDL. The value is a string with URL that
56 should return the WSDL specification of Debbugs/SOAP service.
58 `:bugreport-url' -- URL of the server script that returns mboxes
61 The list initially contains two predefined and configured Debbugs
62 servers: \"gnu.org\" and \"debian.org\"."
64 :link '(custom-manual "(debbugs)Debbugs server specifiers")
69 (string :tag "Port name")
70 (checklist :tag "Options" :greedy t
72 (const :format "" :value :wsdl)
75 (const :format "" :value :bugreport-url)
76 (string :tag "Bugreport URL")))))))
78 (defcustom debbugs-port "gnu.org"
79 "The port instance to be applied from `debbugs-wsdl'.
80 This corresponds to the Debbugs server to be accessed, either
81 \"gnu.org\", or \"debian.org\", or user defined port name."
82 ;; Maybe we should create an own group?
84 :type '(choice :tag "Debbugs server" (const "gnu.org") (const "debian.org")
85 (string :tag "user defined port name")))
87 ;; It would be nice if we could retrieve it from the debbugs server.
89 (defconst debbugs-wsdl
94 (file-name-directory load-file-name)
96 "The WSDL object to be used describing the SOAP interface.")
98 (defun debbugs-get-bugs (&rest query)
99 "Return a list of bug numbers which match QUERY.
101 QUERY is a keyword value sequence, whereby the values are strings.
102 All queries are concatenated via AND.
106 :package -- The value is the name of the package a bug belongs
107 to, like \"emacs\", \"coreutils\", \"gnus\", or \"tramp\".
109 :severity -- This is the severity of the bug. Currently,
110 there exists the severities \"important\", \"grave\",
111 \"normal\", \"minor\" and \"wishlist\".
113 :tag -- An arbitrary string the bug is annotated with.
114 Usually, this is used to mark the status of the bug, like
115 \"fixed\", \"moreinfo\", \"notabug\", \"patch\",
116 \"unreproducible\" or \"wontfix\".
118 :owner -- This is used to identify bugs by the owner's email
119 address. The special email address \"me\" is used as pattern,
120 replaced with `user-mail-address'.
122 :submitter -- With this keyword it is possible to filter bugs
123 by the submitter's email address. The special email address
124 \"me\" is used as pattern, replaced with `user-mail-address'.
126 :archive -- A keyword to filter for bugs which are already
127 archived, or not. Valid values are \"0\" (not archived),
128 \"1\" (archived) or \"both\". If this keyword is not given in
129 the query, `:archive \"0\"' is assumed by default.
133 \(debbugs-get-bugs :submitter \"me\" :archive \"both\")
134 => \(5516 5551 5645 7259)"
138 (while (and (consp query) (<= 2 (length query)))
139 (setq key (pop query)
141 vec (vconcat vec (list (substring (symbol-name key) 1))))
142 (unless (and (keywordp key) (stringp val))
143 (error "Wrong query: %s %s" key val))
145 ((:package :severity :tag)
146 ;; Value shall be one word.
147 (if (string-match "\\`[A-Za-z]+\\'" val)
148 (setq vec (vconcat vec (list val)))
149 (error "Wrong %s: %s" (car (last vec)) val)))
150 ;; Value is an email address.
152 (if (string-match "\\`\\S-+\\'" val)
154 (when (string-equal "me" val)
155 (setq val user-mail-address))
156 (when (string-match "<\\(.+\\)>" val)
157 (setq val (match-string 1 val)))
158 (setq vec (vconcat vec (list val))))
159 (error "Wrong %s: %s" (car (last vec)) val)))
161 ;; Value is `0' or `1' or `both'.
162 (if (string-match "\\`\\(0\\|1\\|both\\)\\'" val)
163 (setq vec (vconcat vec (list val)))
164 (error "Wrong %s: %s" (car (last vec)) val)))
165 (t (error "Unknown key: %s" (car (last vec))))))
168 (error "Unknown key: %s" (car query)))
170 (sort (car (soap-invoke debbugs-wsdl debbugs-port "get_bugs" vec)) '<)))
172 (defun debbugs-newest-bugs (amount)
173 "Return the list of bug numbers, according to AMOUNT (a number) latest bugs."
174 (sort (car (soap-invoke debbugs-wsdl debbugs-port "newest_bugs" amount)) '<))
176 (defun debbugs-get-status (&rest bug-numbers)
177 "Return a list of status entries for the bugs identified by BUG-NUMBERS.
179 Every returned entry is an association list with the following attributes:
181 `bug_num': The bug number.
183 `package': A list of package names the bug belongs to.
185 `severity': The severity of the bug report. This can be
186 \"important\", \"grave\", \"normal\", \"minor\" or \"wishlist\".
188 `tags': The status of the bug report, a list of strings. This
189 can be \"fixed\", \"notabug\", \"wontfix\", \"unreproducible\",
190 \"moreinfo\" or \"patch\".
192 `pending': The string \"pending\", \"forwarded\" or \"done\".
194 `subject': Subject/Title of the bugreport.
196 `originator': Submitter of the bugreport.
198 `mergedwith': A list of bug numbers this bug was merged with.
200 `source': Source package name of the bug report.
202 `date': Date of bug creation.
204 `log_modified', `last_modified': Date of last update.
206 `found_date', `fixed_date': Date of bug report / bug fix
209 `done': The email address of the worker who has closed the bug (if done).
211 `archived': `t' if the bug is archived, `nil' otherwise.
213 `unarchived': The date the bug has been unarchived, if ever.
215 `found_versions', `fixed_versions': List of version strings.
217 `forwarded': A URL or an email address.
219 `blocks': A list of bug numbers this bug blocks.
221 `blockedby': A list of bug numbers this bug is blocked by.
223 `msgid': The message id of the initial bug report.
225 `owner': Who is responsible for fixing.
227 `location': Always the string \"db-h\" or \"archive\".
229 `affects': A list of package names.
231 `summary': Arbitrary text.
235 \(debbugs-get-status 10)
237 => ;; Attributes with empty values are not show
239 \(source . \"unknown\")
240 \(date . 1203606305.0)
241 \(msgid . \"<87zltuz7eh.fsf@freemail.hu>\")
242 \(severity . \"wishlist\")
243 \(owner . \"Magnus Henoch <mange@freemail.hu>\")
244 \(log_modified . 1261079402.0)
245 \(location . \"db-h\")
246 \(subject . \"url-gw should support HTTP CONNECT proxies\")
247 \(originator . \"Magnus Henoch <mange@freemail.hu>\")
248 \(last_modified . 1271200046.0)
249 \(pending . \"pending\")
250 \(package \"emacs\")))"
254 debbugs-wsdl debbugs-port "get_status"
255 (apply 'vector bug-numbers)))))
259 ;; "archived" is the number 1 or 0.
260 (setq y (assoc 'archived (cdr (assoc 'value x))))
261 (setcdr y (= (cdr y) 1))
262 ;; "found_versions" and "fixed_versions" are lists,
263 ;; containing strings or numbers.
264 (dolist (attribute '(found_versions fixed_versions))
265 (setq y (assoc attribute (cdr (assoc 'value x))))
267 (lambda (z) (if (numberp z) (number-to-string z) z))
269 ;; "mergedwith" is a string, containing blank separated bug numbers.
270 (setq y (assoc 'mergedwith (cdr (assoc 'value x))))
271 (when (stringp (cdr y))
272 (setcdr y (mapcar 'string-to-number (split-string (cdr y) " " t))))
273 ;; "package" is a string, containing comma separated package names.
274 ;; "keywords" and "tags" are strings, containing blank
275 ;; separated package names.
276 (dolist (attribute '(package keywords tags))
277 (setq y (assoc attribute (cdr (assoc 'value x))))
278 (when (stringp (cdr y))
279 (setcdr y (split-string (cdr y) ",\\| " t))))
280 (cdr (assoc 'value x))))
283 (defun debbugs-get-bug-log (bug-number)
284 "Return a list of messages related to BUG-NUMBER.
286 Every message is an association list with the following attributes:
288 `msg_num': The number of the message inside the bug log. The
289 numbers are ascending, newer messages have a higher number.
291 `header': The message header lines, as arrived at the bug tracker.
293 `body': The message body.
295 `attachments' A list of possible attachments, or `nil'. Not
296 implemented yet server side."
297 (car (soap-invoke debbugs-wsdl debbugs-port "get_bug_log" bug-number)))
299 (defun debbugs-get-attribute (bug-or-message attribute)
300 "Return the value of key ATTRIBUTE.
302 BUG-OR-MESSAGE must be list element returned by either
303 `debbugs-get-status' or `debbugs-get-bug-log'.
305 Example: Return the originator of last submitted bug.
307 \(debbugs-get-attribute
308 \(car \(apply 'debbugs-get-status \(debbugs-newest-bugs 1))) 'originator)"
309 (cdr (assoc attribute bug-or-message)))
311 (defun debbugs-get-message-numbers (messages)
312 "Return the message numbers of MESSAGES.
313 MESSAGES must be the result of a `debbugs-get-bug-log' call."
314 (mapcar (lambda (x) (debbugs-get-attribute x 'msg_num)) messages))
316 (defun debbugs-get-message (messages message-number)
317 "Return the message MESSAGE-NUMBER of MESSAGES.
318 MESSAGES must be the result of a `debbugs-get-bug-log' call.
320 The returned message is a list of strings. The first element are
321 the header lines of the message, the second element is the body
322 of the message. Further elements of the list, if any, are
323 attachments of the message.
325 If there is no message with MESSAGE-NUMBER, the function returns `nil'.
327 Example: Return the first message of last submitted bug.
329 \(let \(\(messages \(apply 'debbugs-get-bug-log \(debbugs-newest-bugs 1))))
330 \(debbugs-get-message messages
331 \(car \(debbugs-get-message-numbers messages))))"
333 (/= (debbugs-get-attribute (car messages) 'msg_num)
335 (setq messages (cdr messages)))
337 (append (list (debbugs-get-attribute (car messages) 'header)
338 (debbugs-get-attribute (car messages) 'body))
339 (debbugs-get-attribute (car messages) 'attachments))))
341 (defun debbugs-get-mbox (bug-number mbox-type &optional filename)
342 "Download mbox with messages of bug BUG-NUMBER from Debbugs server.
343 BUG-NUMBER is a number of bug. It must be of integer type.
345 MBOX-TYPE specifies a type of mbox and can be one of the
348 `mboxfolder': Download mbox folder.
350 `mboxmaint': Download maintainer's mbox.
352 `mboxstat', `mboxstatus': Download status mbox. The use of
353 either symbol depends on actual Debbugs server
354 configuration. For gnu.org, use the former; for debian.org -
357 FILENAME, if non-nil, is the name of file to store mbox. If
358 FILENAME is nil, the downloaded mbox is inserted into the current
360 (let (url (mt "") bn)
361 (unless (setq url (plist-get
362 (cdr (assoc debbugs-port debbugs-servers))
364 (error "URL of bugreport script for port %s is not specified"
366 (setq bn (format "bug=%s;" (number-to-string bug-number)))
367 (unless (eq mbox-type 'mboxfolder)
368 (if (memq mbox-type '(mboxmaint mboxstat mboxstatus))
369 (setq mt (concat (symbol-name mbox-type) "=yes;"))
370 (error "Unknown mbox type: %s" mbox-type)))
371 (setq url (concat url (format "?%s%smbox=yes" bn mt)))
373 (url-copy-file url filename t)
374 (url-insert-file-contents url))))
376 ;; Interface for the Emacs bug tracker.
378 (autoload 'gnus-read-ephemeral-emacs-bug-group "gnus-group")
379 (autoload 'mail-header-subject "nnheader")
380 (autoload 'gnus-summary-article-header "gnus-sum")
381 (autoload 'message-make-from "message")
383 (defface debbugs-new '((t (:foreground "red")))
384 "Face for new reports that nobody has answered.")
386 (defface debbugs-handled '((t (:foreground "ForestGreen")))
387 "Face for new reports that nobody has answered.")
389 (defface debbugs-stale '((t (:foreground "orange")))
390 "Face for new reports that nobody has answered.")
392 (defun debbugs-emacs (severities &optional package list-done)
393 "List all outstanding Emacs bugs."
396 (completing-read "Severity: "
397 '("important" "normal" "minor" "wishlist")
399 (unless (consp severities)
400 (setq severities (list severities)))
401 (pop-to-buffer (get-buffer-create "*Emacs Bugs*"))
403 (let ((buffer-read-only nil)
405 (dolist (severity severities)
407 (debbugs-get-bugs :package (or package "emacs")
408 :severity severity))))
410 (dolist (status (sort (apply 'debbugs-get-status ids)
412 (< (cdr (assq 'id s1))
413 (cdr (assq 'id s2))))))
415 (not (equal (cdr (assq 'pending status)) "done")))
416 (let ((address (mail-header-parse-address
417 (decode-coding-string (cdr (assq 'originator status))
420 ;; Prefer the name over the address.
424 (format "%5d %-20s [%-23s] %s\n"
425 (cdr (assq 'id status))
429 (cons (cdr (assq 'severity status))
430 (cdr (assq 'keywords status)))
432 (unless (equal (cdr (assq 'pending status)) "pending")
433 (setq words (concat words "," (cdr (assq 'pending status)))))
434 (if (> (length words) 20)
435 (substring words 0 20)
437 (if (> (length address) 23)
438 (substring address 0 23)
440 (decode-coding-string (cdr (assq 'subject status))
444 (+ (point) 5) (+ (point) 26)
447 ((= (cdr (assq 'date status))
448 (cdr (assq 'log_modified status)))
451 (cdr (assq 'log_modified status)))
457 (goto-char (point-min)))
459 (defvar debbugs-mode-map nil)
460 (unless debbugs-mode-map
461 (setq debbugs-mode-map (make-sparse-keymap))
462 (define-key debbugs-mode-map "\r" 'debbugs-select-report))
464 (defun debbugs-mode ()
465 "Major mode for listing bug reports.
467 All normal editing commands are switched off.
470 The following commands are available:
472 \\{debbugs-mode-map}"
474 (kill-all-local-variables)
475 (setq major-mode 'debbugs-mode)
476 (setq mode-name "Debbugs")
477 (use-local-map debbugs-mode-map)
478 (buffer-disable-undo)
479 (setq truncate-lines t)
480 (setq buffer-read-only t))
482 (defun debbugs-select-report ()
483 "Select the report on the current line."
488 (if (not (looking-at " *\\([0-9]+\\)"))
489 (error "No bug report on the current line")
490 (setq id (string-to-number (match-string 1)))))
491 (gnus-read-ephemeral-emacs-bug-group
492 id (cons (current-buffer)
493 (current-window-configuration)))
494 (with-current-buffer (window-buffer (selected-window))
495 (debbugs-summary-mode 1))))
497 (defvar debbugs-summary-mode-map
498 (let ((map (make-sparse-keymap)))
499 (define-key map "C" 'debbugs-send-control-message)
502 (define-minor-mode debbugs-summary-mode
503 "Minor mode for providing a debbugs interface in Gnus summary buffers.
505 \\{debbugs-summary-mode-map}"
506 :lighter " Debbugs" :keymap debbugs-summary-mode-map
509 (defun debbugs-send-control-message (message)
510 "Send a control message for the current bug report.
511 You can set the severity or add a tag, or close the report. If
512 you use the special \"done\" MESSAGE, the report will be marked as
513 fixed, and then closed."
515 (list (completing-read
517 '("important" "normal" "minor" "wishlist"
519 "patch" "wontfix" "moreinfo" "unreproducible" "fixed" "notabug")
521 (let* ((subject (mail-header-subject (gnus-summary-article-header)))
523 (if (string-match "bug#\\([0-9]+\\)" subject)
524 (string-to-number (match-string 1 subject))
525 (error "No bug number present"))))
527 (insert "To: control@debbugs.gnu.org\n"
528 "From: " (message-make-from) "\n"
529 (format "Subject: control message for bug #%d\n" id)
532 ((equal message "close")
533 (format "close %d\n" id))
534 ((equal message "done")
535 (format "tags %d fixed\bclose %d\n" id id))
536 ((member message '("important" "normal" "minor" "wishlist"))
537 (format "severity %d %s\n" id message))
539 (format "tags %d %s\n" id message))))
540 (funcall send-mail-function))))
546 ;; * SOAP interface extensions (wishlist).
547 ;; - Server-side sorting.
548 ;; - Regexp and/or wildcards search.
549 ;; - Fulltext search.
550 ;; - Returning message attachments.
551 ;; * Widget-oriented bug overview like webDDTs.
552 ;; * Actions on bugs.
553 ;; * Integration into gnus (nnir).
555 ;;; debbugs.el ends here