emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Orgmode] Easier integration of org-mode and Bugzilla


From: John Wiegley
Subject: [Orgmode] Easier integration of org-mode and Bugzilla
Date: Thu, 20 May 2010 18:45:24 -0400

I use Org-mode for tracking all tasks, including Bugzilla issues.  But I also 
use remember.el for quickyl creating new tasks, some of which should then go 
into BZ.

The following setup lets me just type "x z" on a task in the Agenda, and a 
related Bugzilla task is automatically created.  Note that this code will have 
to be edited to work in your environment.

First, I have a special link name for these bugs:

#+LINK: cegbug https://portal/bugzilla/show_bug.cgi?id=

Second, you need the bugzilla-submit script, attached to this mail.  You can 
also find this script in the Bugzilla distribution.

Third is this function, several ports of which you will need to edit (though it 
should be pretty obvious):

(defun make-bugzilla-bug (product component version priority severity)
  (interactive
   (let ((omk (get-text-property (point) 'org-marker)))
     (with-current-buffer (marker-buffer omk)
       (save-excursion
         (goto-char omk)
         (let ((products
                (list (list "ABC" (list "Admin" "User" "Other" "CSR")
                            (list "3.0"))
                      (list "Bizcard" (list "Catalog" "Content Section"
                                            "Uploader" "Visual Aesthetics"
                                            "webui")
                            (list "unspecified"))
                      (list "Adagio" (list "DTSX" "PTS" "Satellite" "Zips"
                                           "Core")
                            (list "unspecified"))
                      (list "IT" (list "install" "network" "repair" "misc")
                            (list "unspecified"))
                      (list "EVAprint" (list "misc")
                            (list "1.0"))))
               (priorities (list "P1" "P2" "P3" "P4" "P5"))
               (severities (list "blocker" "critical" "major"
                                 "normal" "minor" "trivial"))
               (product (org-get-category)))
           (list product
                 (let ((components (nth 1 (assoc product products))))
                   (if (= 1 (length components))
                       (car components)
                     (ido-completing-read "Component: " components
                                          nil t nil nil (car (last 
components)))))
                 (let ((versions (nth 2 (assoc product products))))
                   (if (= 1 (length versions))
                       (car versions)
                     (ido-completing-read "Version: " versions
                                          nil t nil nil (car (last versions)))))
                 (let ((orgpri (nth 3 (org-heading-components))))
                   (if (and orgpri (= ?A orgpri))
                       "P1"
                     (ido-completing-read "Priority: " priorities
                                          nil t nil nil "P3")))
                 (ido-completing-read "Severity: " severities nil t nil nil
                                      "normal") ))))))
  (if (string= product "Bizcard")
      (setq product "BizCard"))
  (let ((omk (get-text-property (point) 'org-marker)))
    (with-current-buffer (marker-buffer omk)
      (save-excursion
        (goto-char omk)
        (let ((heading (nth 4 (org-heading-components)))
              (contents (buffer-substring-no-properties
                         (org-entry-beginning-position)
                         (org-entry-end-position)))
              bug)
          (with-temp-buffer
            (insert contents)
            (goto-char (point-min))
            (delete-region (point) (1+ (line-end-position)))
            (search-forward ":PROP")
            (delete-region (match-beginning 0) (point-max))
            (goto-char (point-min))
            (while (re-search-forward "^   " nil t)
              (delete-region (match-beginning 0) (match-end 0)))
            (goto-char (point-min))
            (while (re-search-forward "^SCHE" nil t)
              (delete-region (match-beginning 0) (1+ (line-end-position))))
            (goto-char (point-min))
            (when (eobp)
              (insert "No description file.")
              (goto-char (point-min)))
            (insert (format "Product: %s
Component: %s
Version: %s
Priority: %s
Severity: %s
Hardware: Other
OS: Other
Summary: %s" product component version priority severity heading) ?\n ?\n)
            (let ((buf (current-buffer)))
              (with-temp-buffer
                (let ((tmpbuf (current-buffer)))
                  (if nil
                      (insert "Bug 999 posted.")
                    (with-current-buffer buf
                      (shell-command-on-region
                       (point-min) (point-max)
                       "~/bin/bugzilla-submit https://portal/bugzilla/";
                       tmpbuf)))
                  (goto-char (point-min))
                  (re-search-forward "Bug \\([0-9]+\\) posted.")
                  (setq bug (match-string 1))))))
          (save-excursion
            (org-back-to-heading t)
            (re-search-forward "\\(TODO\\|STARTED\\|WAITING\\|DELEGATED\\) 
\\(\\[#[ABC]\\] \\)?")
            (insert (format "[[cegbug:%s][#%s]] " bug bug)))))))
  (org-agenda-redo))

Fourth is the agenda keybinding, some of which you may prefer to delete:

(eval-after-load "org-agenda"
  '(progn
     (dolist (map (list org-agenda-keymap org-agenda-mode-map))
       (define-prefix-command 'org-todo-state-map)

       (define-key map "x" 'org-todo-state-map)

       (define-key org-todo-state-map "d"
         #'(lambda nil (interactive) (org-agenda-todo "DONE")))
       (define-key org-todo-state-map "r"
         #'(lambda nil (interactive) (org-agenda-todo "DEFERRED")))
       (define-key org-todo-state-map "y"
         #'(lambda nil (interactive) (org-agenda-todo "SOMEDAY")))
       (define-key org-todo-state-map "g"
         #'(lambda nil (interactive) (org-agenda-todo "DELEGATED")))
       (define-key org-todo-state-map "n"
         #'(lambda nil (interactive) (org-agenda-todo "NOTE")))
       (define-key org-todo-state-map "s"
         #'(lambda nil (interactive) (org-agenda-todo "STARTED")))
       (define-key org-todo-state-map "t"
         #'(lambda nil (interactive) (org-agenda-todo "TODO")))
       (define-key org-todo-state-map "w"
         #'(lambda nil (interactive) (org-agenda-todo "WAITING")))
       (define-key org-todo-state-map "x"
         #'(lambda nil (interactive) (org-agenda-todo "CANCELLED")))

       (define-key org-todo-state-map "z" #'make-bugzilla-bug))))

John

Attachment: bugzilla-submit
Description: Binary data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]