@@ -3,12 +3,6 @@ open Devkit
3
3
open Printf
4
4
open Github_j
5
5
6
- exception Remote_config_error of string
7
-
8
- let remote_config_error fmt = ksprintf (fun s -> raise (Remote_config_error s)) fmt
9
-
10
- let log = Log. from " github"
11
-
12
6
type t =
13
7
| Push of commit_pushed_notification
14
8
| Pull_request of pr_notification
@@ -38,63 +32,10 @@ let commits_branch_of_ref ref =
38
32
| _ -> ref
39
33
40
34
let event_of_filename filename =
41
- match String. split_on_chars filename ~on: [ '.' ] with
42
- | [ kind; _name; ext ] when String. equal ext " json" -> Some kind
43
- | _ -> None
44
-
45
- let api_url_of_repo (repo : repository ) =
46
- Option. map ~f: (fun host ->
47
- match host with
48
- | "api.github.com" -> sprintf " https://%s" host
49
- | _ -> sprintf " https://%s/api/v3" host)
50
- @@ Uri. host
51
- @@ Uri. of_string repo.url
52
-
53
- let user_of_full_name_parts full_name_parts =
54
- match full_name_parts with
55
- | user :: _ -> Some user
35
+ match String. split_on_chars ~on: [ '.' ] filename with
36
+ | [ kind; _; " json" ] -> Some kind
56
37
| _ -> None
57
38
58
- let name_of_full_name_parts full_name_parts =
59
- match full_name_parts with
60
- | _ :: repo_name :: _ -> Some repo_name
61
- | _ -> None
62
-
63
- let get_remote_config_json_url filename ?token req =
64
- let repo = repo_of_notification req in
65
- match String. split ~on: '/' repo.full_name with
66
- | full_name_parts ->
67
- match user_of_full_name_parts full_name_parts with
68
- | None -> remote_config_error " unable to resolve repository owner"
69
- | Some owner ->
70
- match name_of_full_name_parts full_name_parts with
71
- | None -> remote_config_error " unable to resolve repository name"
72
- | Some repo_name ->
73
- match api_url_of_repo repo with
74
- | None -> remote_config_error " unable to resolve github api url from repository url"
75
- | Some base_url ->
76
- let url = sprintf " %s/repos/%s/%s/contents/%s" base_url owner repo_name filename in
77
- begin
78
- match token with
79
- | None -> url
80
- | Some token -> sprintf " %s?access_token=%s" url token
81
- end
82
-
83
- let config_of_content_api_response response =
84
- try % lwt
85
- match response.encoding with
86
- | "base64" ->
87
- Lwt. return
88
- @@ Config_j. config_of_string
89
- @@ Common. decode_string_pad
90
- @@ String. concat
91
- @@ String. split_lines
92
- @@ response.content
93
- | e -> remote_config_error " unknown encoding format '%s'" e
94
- with
95
- | Base64. Invalid_char -> remote_config_error " unable to decode configuration file from base64"
96
- | Yojson. Json_error msg -> remote_config_error " unable to parse configuration file as valid JSON (%s)" msg
97
-
98
39
let is_main_merge_message ~msg :message ~branch (cfg : Config.t ) =
99
40
match cfg.main_branch_name with
100
41
| Some main_branch when String. equal branch main_branch ->
@@ -123,24 +64,6 @@ let is_valid_signature ~secret headers_sig body =
123
64
let (`Hex request_hash) = Hex. of_string request_hash in
124
65
String. equal headers_sig (sprintf " sha1=%s" request_hash)
125
66
126
- let load_config_json url =
127
- let headers = [ " Accept: application/vnd.github.v3+json" ] in
128
- match % lwt Web. http_request_lwt ~headers `GET url with
129
- | `Error e -> remote_config_error " error while querying github api %s: %s" url e
130
- | `Ok s -> config_of_content_api_response @@ Github_j. content_api_response_of_string s
131
-
132
- let query_api ?token ~url parse =
133
- let headers = Option. map token ~f: (fun t -> [ sprintf " Authorization: token %s" t ]) in
134
- match % lwt Web. http_request_lwt ~ua: " notabot" ~verbose: true ?headers `GET url with
135
- | `Error e ->
136
- log#error " error while querying github api %s: %s" url e;
137
- Lwt. return_none
138
- | `Ok s ->
139
- try Lwt. return_some (parse s)
140
- with exn ->
141
- log#error ~exn " impossible to parse github api answer to %s" url;
142
- Lwt. return_none
143
-
144
67
(* Parse a payload. The type of the payload is detected from the headers. *)
145
68
let parse_exn ~secret headers body =
146
69
begin
0 commit comments