aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2022-05-08 02:23:12 +0200
committerTeddy Wing2022-05-08 02:23:12 +0200
commit4da960d49c4234d42a6ca12512b1e73678834e1f (patch)
treecfa8064c6330ee4eba6763a0b232fa70d2aaaf9d
parentd1eef12439e17dc20364ada07625d3fc7b28f119 (diff)
downloadwajir-4da960d49c4234d42a6ca12512b1e73678834e1f.tar.bz2
run: Loop over all pages of results
Use `startAt` to get fresh pages of results.
-rw-r--r--src/main.lisp59
1 files changed, 34 insertions, 25 deletions
diff --git a/src/main.lisp b/src/main.lisp
index 98fe754..8045e63 100644
--- a/src/main.lisp
+++ b/src/main.lisp
@@ -23,36 +23,45 @@
(token config)))))
(loop
- (let* ((response (fetch-issues
- (endpoint config)
- (jql config)
- :basic-auth-token basic-auth-token))
-
- (start-at (gethash "startAt" response))
- (max-results (gethash "maxResults" response))
- (total (gethash "total" response)))
-
- (format t "start-at: ~A max-results: ~A total: ~A~%"
- start-at
- max-results
- total)
-
- (loop for issue
- across (gethash "issues" response)
- do (watch-issue issue))
-
- ;; Stop looping if we're on the last page of results.
- (when (> start-at
- (- total max-results))
- (return))))))
-
-(defun fetch-issues (endpoint jql &key basic-auth-token)
+ with start-at = 0
+ with max-results = 0
+ do
+ (progn
+ (let* ((response (fetch-issues
+ (endpoint config)
+ (jql config)
+ start-at
+ :basic-auth-token basic-auth-token))
+
+ (total (gethash "total" response)))
+
+ (format t "start-at: ~A max-results: ~A total: ~A~%"
+ start-at
+ max-results
+ total)
+
+ (loop for issue
+ across (gethash "issues" response)
+ do (watch-issue issue))
+
+ ;; Stop looping if we're on the last page of results.
+ (when (> start-at
+ (- total max-results))
+ (return))
+
+ ;; Step `start-at` for next page.
+ (setf max-results (gethash "maxResults" response))
+ (setf start-at (+ (gethash "startAt" response)
+ max-results)))))))
+
+(defun fetch-issues (endpoint jql start-at &key basic-auth-token)
(jzon:parse
(dex:post (format nil "https://~A/rest/api/3/search" endpoint)
:content
(jzon:stringify
`((:jql . ,jql)
- (fields . ("id" "key" "self"))))
+ (:fields . ("id" "key" "self"))
+ (:|startAt| . ,start-at)))
:headers `((:content-type . "application/json")
(:authorization
. ,(format nil "Basic ~A" basic-auth-token))))))