Add GitHub GraphQL client

This commit is contained in:
Dmitrii Kovanikov 2024-01-06 15:23:50 +00:00
parent 9da5108e34
commit 5d55263bd7
5 changed files with 46 additions and 3 deletions

View File

@ -1 +1,16 @@
let () = print_endline "Hello, World!"
let () = print_endline @@ Github_tui.Gh.query
{|
query {
repository(owner: "chshersh", name: "zbg") {
issues(last: 2, states: [OPEN], orderBy: {field: CREATED_AT, direction: DESC}) {
nodes {
number
title
author {
login
}
}
}
}
}
|}

View File

@ -18,7 +18,11 @@
(name github_tui)
(synopsis "A short synopsis")
(description "A longer description")
(depends ocaml dune)
(depends
ocaml
dune
ezcurl
)
(tags
(topics "to describe" your project)))

View File

@ -12,6 +12,7 @@ bug-reports: "https://github.com/chshersh/github-tui/issues"
depends: [
"ocaml"
"dune" {>= "3.12"}
"ezcurl"
"odoc" {with-doc}
]
build: [

View File

@ -1,2 +1,6 @@
(library
(name github_tui))
(name github_tui)
(libraries
ezcurl
)
)

19
lib/gh.ml Normal file
View File

@ -0,0 +1,19 @@
let github_api_url = "https://api.github.com/graphql"
let query query_body =
let token = Sys.getenv "GITHUB_TOKEN" in
let response =
Ezcurl.post
~params:[]
~headers:
[
("Authorization", "bearer " ^ token) ;
("User-Agent", "chshersh/github-tui")
]
~content:(`String (Printf.sprintf "{ \"query\": %S }" query_body))
~url:github_api_url
()
in
match response with
| Error (_code, msg) -> Printf.sprintf "Error: %s" msg
| Ok response -> response.body