Skip to content

Instantly share code, notes, and snippets.

@MrGung
Created December 6, 2022 08:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrGung/29d0547fe45316c3438032fd164d42c6 to your computer and use it in GitHub Desktop.
Save MrGung/29d0547fe45316c3438032fd164d42c6 to your computer and use it in GitHub Desktop.
Get paginated list of issues from gitlab with clojure/babashka
(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