Skip to content

Commit d424206

Browse files
committed
revert unrelated drive-by changes
1 parent 43dff46 commit d424206

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

lib/action.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
1919
|> List.filter ~f:(fun c -> c.distinct)
2020
|> List.filter ~f:(fun c ->
2121
let branch = Github.commits_branch_of_ref n.ref in
22-
let skip = Github.is_main_merge_message ~msg:c.message ?main_branch:cfg.main_branch_name ~branch in
22+
let skip = Github.is_main_merge_message ~msg:c.message ~branch cfg in
2323
if skip then log#info "main branch merge, ignoring %s: %s" c.id (first_line c.message);
2424
not skip)
2525
|> List.concat_map ~f:(fun commit ->
@@ -217,7 +217,7 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
217217
let process_github_notification (ctx : Context.t) headers body =
218218
try%lwt
219219
let secrets = Context.get_secrets_exn ctx in
220-
match Github.parse_exn ?hook_token:secrets.gh_hook_token headers body with
220+
match Github.parse_exn ~secret:secrets.gh_hook_token headers body with
221221
| exception exn -> Exn_lwt.fail ~exn "failed to parse payload"
222222
| payload ->
223223
( match%lwt refresh_config_of_context ctx payload with

lib/github.ml

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
open Base
2-
open Printf
3-
open Common
42
open Devkit
3+
open Printf
54
open Github_j
65

76
type t =
@@ -37,42 +36,44 @@ let event_of_filename filename =
3736
| [ kind; _; "json" ] -> Some kind
3837
| _ -> None
3938

40-
let is_main_merge_message ~msg:message ?main_branch ~branch =
41-
match main_branch with
39+
let is_main_merge_message ~msg:message ~branch (cfg : Config_t.config) =
40+
match cfg.main_branch_name with
4241
| Some main_branch when String.equal branch main_branch ->
4342
(*
4443
handle "Merge <main branch> into <feature branch>" commits when they are merged into main branch
4544
we should have already seen these commits on the feature branch but for some reason they are distinct:true
4645
*)
4746
let prefix = sprintf "Merge branch '%s' into " main_branch in
4847
let prefix2 = sprintf "Merge remote-tracking branch 'origin/%s' into " main_branch in
49-
let title = first_line message in
48+
let title = Common.first_line message in
5049
String.is_prefix title ~prefix || String.is_prefix title ~prefix:prefix2
5150
| Some main_branch ->
5251
let expect = sprintf "Merge branch '%s' into %s" main_branch branch in
5352
let expect2 = sprintf "Merge remote-tracking branch 'origin/%s' into %s" main_branch branch in
54-
let title = first_line message in
53+
let title = Common.first_line message in
5554
String.equal title expect || String.equal title expect2
5655
| _ -> false
5756

5857
let modified_files_of_commit commit = List.concat [ commit.added; commit.removed; commit.modified ]
5958

60-
let has_valid_signature ~hook_token ~headers ~body =
61-
match List.Assoc.find headers "x-hub-signature" ~equal:String.equal with
62-
| None -> Exn.fail "unable to find header x-hub-signature"
63-
| Some signature ->
64-
let key = Cstruct.of_string hook_token in
65-
let request_hash = Cstruct.to_string @@ Nocrypto.Hash.SHA1.hmac ~key (Cstruct.of_string body) in
66-
let (`Hex request_hash) = Hex.of_string request_hash in
67-
String.equal signature (sprintf "sha1=%s" request_hash)
59+
let is_valid_signature ~secret headers_sig body =
60+
let request_hash =
61+
let key = Cstruct.of_string secret in
62+
Cstruct.to_string @@ Nocrypto.Hash.SHA1.hmac ~key (Cstruct.of_string body)
63+
in
64+
let (`Hex request_hash) = Hex.of_string request_hash in
65+
String.equal headers_sig (sprintf "sha1=%s" request_hash)
6866

6967
(* Parse a payload. The type of the payload is detected from the headers. *)
70-
let parse_exn ?hook_token headers body =
71-
match
72-
Option.value_map hook_token ~default:true ~f:(fun hook_token -> has_valid_signature ~hook_token ~headers ~body)
73-
with
74-
| false -> failwith "request signature invalid"
75-
| true ->
68+
let parse_exn ~secret headers body =
69+
begin
70+
match secret with
71+
| None -> ()
72+
| Some secret ->
73+
match List.Assoc.find headers "x-hub-signature" ~equal:String.equal with
74+
| None -> Exn.fail "unable to find header x-hub-signature"
75+
| Some req_sig -> if not @@ is_valid_signature ~secret req_sig body then failwith "request signature invalid"
76+
end;
7677
match List.Assoc.find_exn headers "x-github-event" ~equal:String.equal with
7778
| exception exn -> Exn.fail ~exn "unable to read x-github-event"
7879
| "push" -> Push (commit_pushed_notification_of_string body)

0 commit comments

Comments
 (0)