@@ -10,6 +10,12 @@ module Github : Api.Github = struct
10
10
let contents_url ~(repo : Github_t.repository ) ~path =
11
11
String. substr_replace_first ~pattern: " {+path}" ~with_: path repo.contents_url
12
12
13
+ let pulls_url ~(repo : Github_t.repository ) ~number =
14
+ String. substr_replace_first ~pattern: " {/number}" ~with_: (sprintf " /%d" number) repo.pulls_url
15
+
16
+ let issues_url ~(repo : Github_t.repository ) ~number =
17
+ String. substr_replace_first ~pattern: " {/number}" ~with_: (sprintf " /%d" number) repo.issues_url
18
+
13
19
let build_headers ?token () =
14
20
let headers = [ " Accept: application/vnd.github.v3+json" ] in
15
21
Option. value_map token ~default: headers ~f: (fun v -> sprintf " Authorization: token %s" v :: headers)
@@ -38,13 +44,24 @@ module Github : Api.Github = struct
38
44
@@ fmt_error " unexpected encoding '%s' in Github response\n failed to get config from file %s" encoding url
39
45
)
40
46
41
- let get_api_commit ~ (ctx : Context.t ) ~ repo ~ sha =
47
+ let get_resource (ctx : Context.t ) url =
42
48
let secrets = Context. get_secrets_exn ctx in
43
- let url = commits_url ~repo ~sha in
44
49
let headers = build_headers ?token:secrets.gh_token () in
45
50
match % lwt http_request ~headers `GET url with
46
- | Ok res -> Lwt. return @@ Ok (Github_j. api_commit_of_string res)
47
- | Error e -> Lwt. return @@ fmt_error " error while querying remote: %s\n failed to get api commit from file %s" e url
51
+ | Ok res -> Lwt. return @@ Ok res
52
+ | Error e -> Lwt. return @@ fmt_error " error while querying remote: %s\n failed to get resource from %s" e url
53
+
54
+ let get_api_commit ~(ctx : Context.t ) ~repo ~sha =
55
+ let % lwt res = commits_url ~repo ~sha |> get_resource ctx in
56
+ Lwt. return @@ Result. map res ~f: Github_j. api_commit_of_string
57
+
58
+ let get_pull_request ~(ctx : Context.t ) ~repo ~number =
59
+ let % lwt res = pulls_url ~repo ~number |> get_resource ctx in
60
+ Lwt. return @@ Result. map res ~f: Github_j. pull_request_of_string
61
+
62
+ let get_issue ~(ctx : Context.t ) ~repo ~number =
63
+ let % lwt res = issues_url ~repo ~number |> get_resource ctx in
64
+ Lwt. return @@ Result. map res ~f: Github_j. issue_of_string
48
65
end
49
66
50
67
module Slack : Api .Slack = struct
0 commit comments