mirror of
https://github.com/chshersh/github-tui.git
synced 2024-09-11 18:37:56 +03:00
Add GitHub GraphQL client
This commit is contained in:
parent
9da5108e34
commit
5d55263bd7
17
bin/main.ml
17
bin/main.ml
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|}
|
||||
|
@ -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)))
|
||||
|
||||
|
@ -12,6 +12,7 @@ bug-reports: "https://github.com/chshersh/github-tui/issues"
|
||||
depends: [
|
||||
"ocaml"
|
||||
"dune" {>= "3.12"}
|
||||
"ezcurl"
|
||||
"odoc" {with-doc}
|
||||
]
|
||||
build: [
|
||||
|
6
lib/dune
6
lib/dune
@ -1,2 +1,6 @@
|
||||
(library
|
||||
(name github_tui))
|
||||
(name github_tui)
|
||||
(libraries
|
||||
ezcurl
|
||||
)
|
||||
)
|
||||
|
19
lib/gh.ml
Normal file
19
lib/gh.ml
Normal 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
|
Loading…
Reference in New Issue
Block a user