B0_githubSourceGitHub interaction.
See an example.
The type for content types.
The type for GitHub V3 request bodies. Either JSON or something else tagged with its content type or nothing.
val req_json_v3 :
?headers:B0_http.Http.headers ->
B0_http.Http_client.t ->
Auth.t ->
path:string ->
B0_http.Http.method' ->
v3_body ->
(B0_json.Json.t, string) resultreq_json_v3 auth path m ~headers body performs the request for json on path using method m, additional headers headers, body body and authentication auth.
query_v4 auth q performs the the GitHub GraphQL V4 query q using authentication auth.
Pull requests
This example opens an issue on the repo of a owner given an URL. The owner and repo is determined from the URL with Repo.of_url, it works with links to git repos on github repos or their landing page.
open B0_std
open Result.Syntax
let open_issue ~user ~repo_url ~title ~body =
let* httpc = B0_http.Http_client.make () in
let* auth = B0_github.Auth.make ~user () in
let* repo = B0_github.Repo.of_url repo_url in
let* num, url = B0_github.Issue.open' httpc auth repo ~title ~body () in
let* path = match B0_url.path url with
| None -> Fmt.error "No path in returned url %s" url
| Some path -> Ok path
in
let* json = B0_github.req_json_v3 httpc auth ~path `GET `Empty in
let* html_url = B0_json.Jsonq.(query (mem "html_url" string)) json in
Log.stdout (fun m -> m "@[%s@]" html_url);
Ok ()
let user = None (* See B0_github.Auth.make to see how one is looked up. *)
let title = "TODO"
let body =
{|TODO|}
let main () =
Log.if_error ~use:1 @@
let* () = open_issue ~user ~repo_url:Sys.argv.(1) ~title ~body in
Ok 0
let () = if !Sys.interactive then () else exit (main ())