Created
December 6, 2022 08:52
-
-
Save MrGung/29d0547fe45316c3438032fd164d42c6 to your computer and use it in GitHub Desktop.
Get paginated list of issues from gitlab with clojure/babashka
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn get-all-issues | |
"Holt alle Issues. Verwendet `iteration` für die Pagination." | |
[gitlab-config project-id] | |
(let [{:keys [gitlab-token gitlab-root]} gitlab-config | |
curl-options {:raw-args ["--insecure"] | |
:debug true | |
:throw false | |
:headers {:PRIVATE-TOKEN gitlab-token | |
:Content-Type "application/json; charset=utf-8"}} | |
step (fn step [marker-token] | |
(let [url (str gitlab-root (format "/projects/%s/issues?per_page=100&page=%s" project-id marker-token)) | |
response (b-curl/get url curl-options) | |
data (j response)] | |
{:response response :data data})) | |
somef (fn somef [{:keys [data]}] (not (empty? data))) | |
vf (fn vf [{:keys [data]}] data) | |
kf (fn kf [{:keys [response]}] (let [next-page (-> response :headers (get "x-next-page")) | |
next-marker (if (str/blank? next-page) | |
nil | |
(Integer/parseInt next-page))] | |
next-marker))] | |
(into [] cat (iteration step | |
:initk 1 | |
:kf kf | |
:vf vf | |
:somef somef)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment