forked from patricoferris/get-activity
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
153 additions
and
145 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
version = 0.26.1 | ||
profile = conventional |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
(lang dune 2.8) | ||
(name get-activity) | ||
(formatting disabled) | ||
(generate_opam_files true) | ||
(source (github tarides/get-activity)) | ||
(authors "[email protected]") | ||
|
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
open Lwt.Infix | ||
|
||
let graphql_endpoint = Uri.of_string "https://api.github.com/graphql" | ||
|
||
let ( / ) a b = Yojson.Safe.Util.member b a | ||
|
||
let exec ?variables ~token ~query () = | ||
let body = | ||
`Assoc ( | ||
("query", `String query) :: | ||
`Assoc | ||
(("query", `String query) | ||
:: | ||
(match variables with | ||
| None -> [] | ||
| Some v -> ["variables", `Assoc v]) | ||
) | ||
|> Yojson.Safe.to_string | ||
|> Cohttp_lwt.Body.of_string | ||
| None -> [] | ||
| Some v -> [ ("variables", `Assoc v) ])) | ||
|> Yojson.Safe.to_string |> Cohttp_lwt.Body.of_string | ||
in | ||
let headers = Cohttp.Header.init_with "Authorization" ("bearer " ^ token) in | ||
Cohttp_lwt_unix.Client.post ~headers ~body graphql_endpoint >>= | ||
fun (resp, body) -> | ||
Cohttp_lwt_unix.Client.post ~headers ~body graphql_endpoint | ||
>>= fun (resp, body) -> | ||
Cohttp_lwt.Body.to_string body >|= fun body -> | ||
match Cohttp.Response.status resp with | ||
| `OK -> | ||
let json = Yojson.Safe.from_string body in | ||
begin match json / "errors" with | ||
| `OK -> ( | ||
let json = Yojson.Safe.from_string body in | ||
match json / "errors" with | ||
| `Null -> json | ||
| _errors -> | ||
Fmt.failwith "@[<v2>GitHub returned errors: %a@]" (Yojson.Safe.pretty_print ~std:true) json; | ||
end | ||
| err -> Fmt.failwith "@[<v2>Error performing GraphQL query on GitHub: %s@,%s@]" | ||
(Cohttp.Code.string_of_status err) | ||
body | ||
Fmt.failwith "@[<v2>GitHub returned errors: %a@]" | ||
(Yojson.Safe.pretty_print ~std:true) | ||
json) | ||
| err -> | ||
Fmt.failwith "@[<v2>Error performing GraphQL query on GitHub: %s@,%s@]" | ||
(Cohttp.Code.string_of_status err) | ||
body |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
val exec : ?variables:(string * Yojson.Safe.t) list -> token:string -> query:string -> unit -> Yojson.Safe.t Lwt.t | ||
val exec : | ||
?variables:(string * Yojson.Safe.t) list -> | ||
token:string -> | ||
query:string -> | ||
unit -> | ||
Yojson.Safe.t Lwt.t |
Oops, something went wrong.