diff --git a/bin/main.ml b/bin/main.ml index 7bf6048..697271a 100644 --- a/bin/main.ml +++ b/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 + } + } + } + } +} +|} diff --git a/dune-project b/dune-project index ce70994..8f0c659 100644 --- a/dune-project +++ b/dune-project @@ -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))) diff --git a/github_tui.opam b/github_tui.opam index d2248a6..e5a1e4a 100644 --- a/github_tui.opam +++ b/github_tui.opam @@ -12,6 +12,7 @@ bug-reports: "https://github.com/chshersh/github-tui/issues" depends: [ "ocaml" "dune" {>= "3.12"} + "ezcurl" "odoc" {with-doc} ] build: [ diff --git a/lib/dune b/lib/dune index 2cb9bf9..ffbb4ad 100644 --- a/lib/dune +++ b/lib/dune @@ -1,2 +1,6 @@ (library - (name github_tui)) + (name github_tui) + (libraries + ezcurl + ) +) diff --git a/lib/gh.ml b/lib/gh.ml new file mode 100644 index 0000000..b4247f9 --- /dev/null +++ b/lib/gh.ml @@ -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 \ No newline at end of file