Forked from lagenorhynque/github_graphql_api_client.clj
Created
March 18, 2024 20:46
-
-
Save usametov/ce0d431c63fbe95af5f311680ae0201f to your computer and use it in GitHub Desktop.
A minimal GitHub GraphQL API client implemented as a babashka (Clojure) script
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
#!/usr/bin/env bb | |
(ns github-graphql-api-client | |
(:require | |
[babashka.curl :as curl] | |
[cheshire.core :as cheshire] | |
[clojure.pprint :refer [pprint]])) | |
(def auth-token (System/getenv "AUTH_TOKEN")) | |
(def graphql-query | |
" | |
query ($query: String!, $last: Int) { | |
search(type: ISSUE, query: $query, last: $last) { | |
nodes { | |
... on Issue { | |
title | |
url | |
repository { | |
name | |
} | |
labels(first: 10) { | |
nodes { | |
name | |
} | |
} | |
} | |
} | |
} | |
} | |
") | |
(defn run-query [query variables] | |
(-> (curl/post "https://api.github.com/graphql" | |
{:headers {"Content-Type" "application/json" | |
"Accept" "application/json" | |
"Authorization" (str "bearer " auth-token)} | |
:body (cheshire/generate-string {:query query | |
:variables variables})}) | |
:body | |
(cheshire/parse-string true))) | |
(defn -main [] | |
(pprint | |
(run-query graphql-query | |
{:query "org:my-org is:issue is:open label:\"docs\" sort:updated" | |
:last 100}))) | |
(when (= *file* (System/getProperty "babashka.file")) | |
(-main)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment