Skip to content

Commit 547934d

Browse files
committed
config: wrap match condition regex as re2
1 parent d9bdfc2 commit 547934d

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

lib/common.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ module StringMap = struct
1515
let unwrap = to_list
1616
end
1717

18+
module Re2 = struct
19+
include Re2
20+
21+
let wrap s = create_exn s
22+
23+
let unwrap = Re2.to_string
24+
end
25+
1826
let fmt_error fmt = Printf.ksprintf (fun s -> Error s) fmt
1927

2028
let first_line s =

lib/rule.atd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
type regex = string wrap <ocaml module="Common.Re2">
2+
13
(* Text fields from the GitHub payload that can be used in a condition *)
24
type comparable_field = [
35
| Context <json name="context">
@@ -8,7 +10,7 @@ type comparable_field = [
810
(* Checks whether a payload field matches the provided regex pattern *)
911
type match_condition = {
1012
field : comparable_field;
11-
re : string; (* expects a regex pattern *)
13+
re : regex;
1214
}
1315

1416
(* Specifies additional conditions the payload must meet for the status rule to match *)

lib/rule.ml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ module Status = struct
2121
| Target_url -> notification.target_url
2222
in
2323
let rec match_condition = function
24-
| Match { field; re } ->
25-
value_of_field field
26-
|> Option.map ~f:(fun f -> Re.Str.string_match (Re.Str.regexp_case_fold re) f 0)
27-
|> Option.value ~default:false
24+
| Match { field; re } -> value_of_field field |> Option.map ~f:(Re2.matches re) |> Option.value ~default:false
2825
| All_of conditions -> List.for_all conditions ~f:match_condition
2926
| One_of conditions -> List.exists conditions ~f:match_condition
3027
| Not condition -> not @@ match_condition condition

0 commit comments

Comments
 (0)