;;; BUGS.edb                                            -*- emacs-lisp -*-

;; Copyright (C) 2007,2008 Thien-Thi Nguyen
;;
;; This file is part of EDB.
;;
;; EDB is free software; you can redistribute it and/or modify it under
;; the terms of the GNU General Public License as published by the Free
;; Software Foundation; either version 3, or (at your option) any later
;; version.
;;
;; EDB is distributed in the hope that it will be useful, but WITHOUT
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
;; FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
;; for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with EDB; see the file COPYING.  If not, write to the Free
;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
;; MA 02110-1301, USA.

:EDB (single)

:name "EDB BUGS"

(edb-define-enumtype 'status '("unresolved" "fix-applied" "resolved"))

:record-separator "\f\n"
:cruft [[["\\([^\f]*\n\\)*\f\n" 0]
         ["\f\n[^\n]+\n" 0]]
        [nil nil]]

(require 'edb-t-timedate1)

(edb-define-recordfieldtype 'iso-date 'date
  :actual->stored 'edb-t-timedate1:format-date-iso
  :stored->actual 'edb-t-timedate1:parse-date-string)

:tagged-setup
`
(:fields
 ,(mapcar
   (lambda (args)
     (multiple-value-bind (desc name type) args
       (list (cons name type) (capitalize (symbol-name name)) desc)))
   '(("serial number of the bug"
      id integer)
     ("one-line description of the buggy behavior"
      summary one-line-string)
     ("one of: unresolved, fix-applied, resolved"
      status status)
     ("released version of EDB that demonstrates this bug"
      reported-version string)
     ("either \"ttn\" or someone's email address"
      reported-by string)
     ("when reported (and hopefully entered into BUGS :-)"
      reported-date iso-date)
     ("one-line description of the fix"
      fix-applied-summary one-line-string)
     ("when status changed to fix-applied"
      fix-applied-date iso-date)
     ("version at and after which no longer demonstrate the bug"
      fix-applied-version string)
     ("when status changed to resolved"
      resolved-date iso-date)
     ("notes"
      notes string)))
 ;; overriding attributes
 :pre-tag-regexp      ""
 :separator-regexp    ":[ \t]*"
 :separator-output    ": "
 :continuation-regexp "\a"
 :continuation-output ""
 :pre-parse-thunk (lambda ()
                    (let ((p (point-min)) q)
                      (search-forward "\n\n")
                      (delete-char -1)
                      (insert "Notes:")
                      (while (< (point) (point-max))
                        (forward-line 1)
                        (unless (eobp)
                          (insert "\a")))
                      (goto-char p)))
 :post-write-function (lambda (record)
                        (while (= ?\n (char-before))
                          (delete-char -1))
                        (insert "\n\n")
                        (save-excursion
                          (goto-char (point-min))
                          (when (search-forward "Notes: " nil t)
                            (replace-match "\n")))))

:record-defaults
(lambda ()
  (flet ((read/def (prompt def) (read-from-minibuffer
                                 prompt def nil nil nil def)))
    (let ((date (edb-t-timedate1:parse-date-string
                 (read/def "When: " (current-time-string))))
          (user (read/def "Reported by: " (format "%s@%s"
                                                  (user-login-name)
                                                  (system-name))))
          (v (read/def "EDB version: " edb-version)))
      (list 'id (1+ (database-no-of-records dbc-database))
            'reported-version v
            'reported-date date
            'reported-by user
            'status "unresolved"
            'notes (format "%s <%s> sez:\n"
                           (format-time-string "%F %T")
                           user)))))

:summary-format
(concat "\\id,width=3,right-justify"
        " \\status,width=12,right-justify"
        "  \\summary")

:display t
 Bug: \id / EDB \reported-version / \status
      \summary

Reported \reported-date,date-iso by <\reported-by\ >

Fix applied \fix-applied-date,date-iso EDB \fix-applied-version
            \fix-applied-summary

Resolved \resolved-date,date-iso

\notes
:EOTB

;;; BUGS.edb ends here
