@@ -18,7 +18,9 @@ type t =
18
18
19
19
(* all other events *)
20
20
21
- exception Remote_Config_Error of string
21
+ exception Remote_config_error of string
22
+
23
+ let remote_config_error fmt = ksprintf (fun s -> raise (Remote_config_error s)) fmt
22
24
23
25
let to_repo = function
24
26
| Push n -> Some n.repository
@@ -34,8 +36,8 @@ let to_repo = function
34
36
let api_url_of_repo (repo : repository ) =
35
37
Option. map ~f: (fun host ->
36
38
match host with
37
- | "api.github.com" -> Printf. sprintf " https://%s" host
38
- | _ -> Printf. sprintf " https://%s/api/v3" host)
39
+ | "api.github.com" -> sprintf " https://%s" host
40
+ | _ -> sprintf " https://%s/api/v3" host)
39
41
@@ Uri. host
40
42
@@ Uri. of_string repo.url
41
43
@@ -51,24 +53,25 @@ let name_of_full_name_parts full_name_parts =
51
53
52
54
let get_remote_config_json_url filename ?token req =
53
55
match to_repo req with
54
- | None -> raise @@ Remote_Config_Error " unable to resolve repository from request"
56
+ | None -> remote_config_error " unable to resolve repository from request"
55
57
| Some repo ->
56
58
match String. split ~on: '/' repo.full_name with
57
59
| full_name_parts ->
58
60
match user_of_full_name_parts full_name_parts with
59
- | None -> raise @@ Remote_Config_Error " unable to resolve repository owner"
61
+ | None -> remote_config_error " unable to resolve repository owner"
60
62
| Some owner ->
61
63
match name_of_full_name_parts full_name_parts with
62
- | None -> raise @@ Remote_Config_Error " unable to resolve repository name"
64
+ | None -> remote_config_error " unable to resolve repository name"
63
65
| Some repo_name ->
64
66
match api_url_of_repo repo with
65
- | None -> raise @@ Remote_Config_Error " unable to resolve github api url from repository url"
67
+ | None -> remote_config_error " unable to resolve github api url from repository url"
66
68
| Some base_url ->
67
- match Printf. sprintf " %s/repos/%s/%s/contents/%s" base_url owner repo_name filename with
68
- | url ->
69
- match token with
70
- | None -> url
71
- | Some token -> Printf. sprintf " %s?access_token=%s" url token
69
+ let url = sprintf " %s/repos/%s/%s/contents/%s" base_url owner repo_name filename in
70
+ begin
71
+ match token with
72
+ | None -> url
73
+ | Some token -> sprintf " %s?access_token=%s" url token
74
+ end
72
75
73
76
let config_of_content_api_response response =
74
77
match response.encoding with
@@ -79,12 +82,12 @@ let config_of_content_api_response response =
79
82
@@ String. concat
80
83
@@ String. split ~on: '\n'
81
84
@@ response.content
82
- | e -> raise @@ Remote_Config_Error ( Printf. sprintf " unknown encoding format '%s'. " e)
85
+ | e -> remote_config_error " unknown encoding format '%s'" e
83
86
84
87
let load_config_json url =
85
- let headers = Some [ " Accept: application/vnd.github.v3+json" ] in
86
- match % lwt Web. http_request_lwt ? headers `GET url with
87
- | `Error e -> raise @@ Remote_Config_Error ( Printf. sprintf " error while querying github api %s: %s" url e)
88
+ let headers = [ " Accept: application/vnd.github.v3+json" ] in
89
+ match % lwt Web. http_request_lwt ~ headers `GET url with
90
+ | `Error e -> remote_config_error " error while querying github api %s: %s" url e
88
91
| `Ok s -> config_of_content_api_response @@ Github_j. content_api_response_of_string s
89
92
90
93
let is_valid_signature ~secret headers_sig body =
@@ -93,7 +96,7 @@ let is_valid_signature ~secret headers_sig body =
93
96
Cstruct. to_string @@ Nocrypto.Hash.SHA1. hmac ~key (Cstruct. of_string body)
94
97
in
95
98
let (`Hex request_hash) = Hex. of_string request_hash in
96
- String. equal headers_sig (Printf. sprintf " sha1=%s" request_hash)
99
+ String. equal headers_sig (sprintf " sha1=%s" request_hash)
97
100
98
101
(* Parse a payload. The type of the payload is detected from the headers. *)
99
102
let parse_exn ~secret headers body =
@@ -135,7 +138,7 @@ let query_api ?token ~url parse =
135
138
log#error ~exn " impossible to parse github api answer to %s" url;
136
139
Lwt. return_none
137
140
138
- let generate_query_commmit cfg ~url ~sha =
141
+ let generate_query_commit cfg ~url ~sha =
139
142
(* the expected output is a payload containing content about commits *)
140
143
match cfg.Config. offline with
141
144
| None -> query_api ?token:cfg.Config. gh_token ~url api_commit_of_string
@@ -168,4 +171,4 @@ let generate_commit_from_commit_comment cfg n =
168
171
in
169
172
let commit_url = String. sub ~pos: 0 ~len: url_length url ^ " /" ^ sha in
170
173
(* add sha hash to get the full api link *)
171
- generate_query_commmit cfg ~url: commit_url ~sha
174
+ generate_query_commit cfg ~url: commit_url ~sha
0 commit comments