summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYoni Rabkin <yoni@rabkins.net>2020-11-17 13:22:17 -0500
committerYoni Rabkin <yoni@rabkins.net>2020-11-17 13:22:17 -0500
commit53e56b798c77ee4f244688490332d6a93d53be81 (patch)
tree72f892521390e3a865a2aca53e7ad64d4e408297
parent237b11d4507ee8b1208cab40eddf9d2c6747a183 (diff)
* rt-liberation-viewer.el: history parse
-rw-r--r--rt-liberation-viewer.el32
1 files changed, 32 insertions, 0 deletions
diff --git a/rt-liberation-viewer.el b/rt-liberation-viewer.el
index bc0e15d..359e600 100644
--- a/rt-liberation-viewer.el
+++ b/rt-liberation-viewer.el
@@ -43,6 +43,38 @@
'font-lock-comment-face)))
"Expressions to font-lock for RT ticket viewer.")
+(defun rt-liber-viewer-reduce (section-list f acc)
+ "A Not Invented Here tail-recursive reduce function."
+ (cond ((null (cdr section-list)) acc)
+ (t (rt-liber-viewer-reduce (cdr section-list)
+ f
+ (append acc (list
+ (funcall f
+ (car section-list)
+ (cadr section-list))))))))
+
+;; According to:
+;; "https://rt-wiki.bestpractical.com/wiki/REST#Ticket_History" is of
+;; the form: "# <n>/<n> (id/<history-id>/total)"
+(defun rt-liber-viewer-parse-history (ticket-history)
+ "Parse the string TICKET-HISTORY."
+ (when (not (stringp ticket-history))
+ (error "invalid ticket-history"))
+ (with-temp-buffer
+ (insert ticket-history)
+ (goto-char (point-min))
+ ;; find history detail sections and procude a list of section
+ ;; (start . end) pairs
+ (let (section-point-list)
+ (while (re-search-forward "^# [0-9]+/[0-9]+ (id/[0-9]+/total)" (point-max) t)
+ (setq section-point-list (append section-point-list
+ (list (point)))))
+ (when (not section-point-list)
+ (error "no history detail sections found"))
+ (setq section-point-list (append section-point-list
+ (list (point-max)))
+ section-point-list (rt-liber-viewer-reduce section-point-list #'cons nil))
+ section-point-list)))
(defun rt-liber-display-ticket-history (ticket-alist &optional assoc-browser)
"Display history for ticket.