From 84ce235f133459dd06c2d1a0a1c6e0d90f5770f1 Mon Sep 17 00:00:00 2001 From: Yoni Rabkin Date: Wed, 5 Aug 2020 17:22:31 -0400 Subject: Syncronize with Stefan's changes --- rt-liberation-rest.el | 65 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 13 deletions(-) (limited to 'rt-liberation-rest.el') diff --git a/rt-liberation-rest.el b/rt-liberation-rest.el index 0b52211..7782665 100644 --- a/rt-liberation-rest.el +++ b/rt-liberation-rest.el @@ -1,6 +1,6 @@ ;;; rt-liberation-rest.el --- Interface to the RT REST API -;; Copyright (C) 2014, 2015 Free Software Foundation +;; Copyright (C) 2014-2015 Free Software Foundation, Inc. ;; ;; Authors: Yoni Rabkin ;; @@ -20,7 +20,9 @@ ;; License along with this program; if not, write to the Free ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, ;; MA 02111-1307, USA. - +;; +;; Note: Licensed under GPLv2+ and not GPLv3+ in order to be +;; compatible with the license of RT. ;;; History: ;; @@ -31,7 +33,9 @@ (require 'url) (require 'url-util) - +;; (require 'rt-liberation) ; FIXME: Circular dependency +(declare-function rt-liber-parse-answer "rt-liberation" (answer-string parser-f)) +(declare-function rt-liber-ticket-base-retriever-parser-f "rt-liberation" ()) (defvar rt-liber-rest-debug-buffer-name "*rt-liber-rest debug log*" "Buffer name of debug capture.") @@ -54,9 +58,6 @@ (defvar rt-liber-rest-verbose-p t "If non-nil, be verbose about what's happening.") -(defvar rt-liber-rest-response-buffer nil - "Buffer for manipulating server responses.") - (defun rt-liber-rest-write-debug (str) "Write to debug buffer." @@ -82,7 +83,7 @@ "format=i" "&" "orderby=+Created"))) -(defun rt-liber-rest-show-string (scheme url ticket-id-list username password query) +(defun rt-liber-rest-show-string (scheme url ticket-id-list username password _query) "Return the ticket show string." (let ((user (url-encode-url username)) (pass (url-encode-url password))) @@ -169,11 +170,29 @@ "Parse the HTTP header from the server." (let ((http-ok-regexp "^HTTP.*200 OK$") (rt-ok-regexp "^rt/.*200 ok$")) - (condition-case excep + (condition-case nil (progn (re-search-forward http-ok-regexp (point-max)) (re-search-forward rt-ok-regexp (point-max))) - (error "bad HTTP response from server")))) + (error "bad HTTP response from server")))) ;FIXME: Unused string! + +(defun rt-liber-rest-ticketsql-runner-parser-f () + "Parser function for a textual list of tickets." + (let (idsub-list) + (rt-liber-rest-parse-http-header) + (while (re-search-forward "ticket/\\([0-9].+\\)" (point-max) t) + ;; the output should be compatible with the input to + ;; `rt-liber-create-tickets-string' + (push (list (match-string-no-properties 1) + ".") + idsub-list)) + idsub-list)) + +(defun rt-liber-rest-run-ls-query (query) + "Run an \"ls\" type query against the server with QUERY." + (rt-liber-parse-answer + (rt-liber-rest-query-runner "ls" query) + 'rt-liber-rest-ticketsql-runner-parser-f)) (defun rt-liber-rest-show-process (response) "Process and return the show query response." @@ -209,9 +228,23 @@ (message "done retrieving %d tickets" l))) (buffer-substring (point-min) (point-max)))) +(defun rt-liber-rest-run-show-base-query (idsublist) + "Run \"show\" type query against the server with IDSUBLIST." + (rt-liber-parse-answer + (rt-liber-rest-show-query-runner idsublist) + #'rt-liber-ticket-base-retriever-parser-f)) + +(defun rt-liber-rest-run-ticket-history-base-query (ticket-id) + "Run history query against server for TICKET-ID." + (rt-liber-parse-answer + (rt-liber-rest-query-runner "history" ticket-id) + #'(lambda () + (rt-liber-rest-parse-http-header) + (buffer-substring (point) (point-max))))) + (defun rt-liber-rest-handle-response (buffer) "Handle the response provided in BUFFER." - (with-current-buffer rt-liber-rest-response-buffer + (with-current-buffer buffer (rt-liber-rest-write-debug (buffer-string)))) (defun rt-liber-rest-edit-runner (ticket-id field value) @@ -225,8 +258,8 @@ (rt-liber-rest-write-debug (concat request-data "\n")) (let ((url-request-method "POST") (url-request-data request-data) - rt-liber-rest-response-buffer) - (setq rt-liber-rest-response-buffer + response-buffer) + (setq response-buffer (url-retrieve-synchronously (rt-liber-rest-command-edit-string rt-liber-rest-scheme @@ -234,9 +267,15 @@ ticket-id rt-liber-rest-username rt-liber-rest-password))) - (rt-liber-rest-handle-response rt-liber-rest-response-buffer))) + (rt-liber-rest-handle-response response-buffer))) (message "edit command ended at %s" (current-time-string))) +(defun rt-liber-rest-command-set (id field status) + "Set ticket ID status to be STATUS." + (rt-liber-parse-answer + (rt-liber-rest-edit-runner id field status) + 'rt-liber-command-runner-parser-f)) + (provide 'rt-liberation-rest) -- cgit v1.2.3