@@ -44,11 +44,16 @@ let is_main_merge_message ~msg:message ~branch (cfg : Config_t.config) =
44
44
we should have already seen these commits on the feature branch but for some reason they are distinct:true
45
45
*)
46
46
let re =
47
- Str. regexp (sprintf {|^ Merge \( remote- tracking\)? branch '\(origin/ \)?% s'\( of .+ \)? into \(.+ \)$| } main_branch)
47
+ Re2. create_exn
48
+ (sprintf {|^ Merge (?: remote- tracking)? branch '(?: origin/ )?% s'(?: of .+ )? into (.+ )$| } (Re2. escape main_branch))
48
49
in
49
50
let title = Common. first_line message in
50
- let matched = Str. string_match re title 0 in
51
- matched && (String. equal branch main_branch || String. equal branch (Str. matched_group 4 title))
51
+ begin
52
+ try
53
+ let other_branch = Re2. find_first_exn ~sub: (`Index 1 ) re title in
54
+ String. equal branch main_branch || String. equal branch other_branch
55
+ with Re2.Exceptions. Regex_match_failed _ -> false
56
+ end
52
57
| _ -> false
53
58
54
59
let modified_files_of_commit commit = List. concat [ commit.added; commit.removed; commit.modified ]
@@ -89,6 +94,8 @@ type gh_link =
89
94
| Issue of repository * int
90
95
| Commit of repository * commit_hash
91
96
97
+ let gh_re = Re2. create_exn {|^ (.* )/ (.+ )/ (.+ )/ (commit| pull| issues)/ ([a- z0-9 ]+ )/?$| }
98
+
92
99
(* * `gh_link_of_string s` parses a URL string `s` to try to match a supported
93
100
GitHub link type, generating repository endpoints if necessary *)
94
101
let gh_link_of_string url_str =
@@ -100,18 +107,12 @@ let gh_link_of_string url_str =
100
107
let custom_api_base ?(scheme = " https" ) base owner name =
101
108
sprintf " %s://%s/api/v3/repos/%s/%s" scheme base owner name
102
109
in
103
- let re = Re.Str. regexp {|^ \(.* \)/ \(.+ \)/ \(.+ \)/ \(commit\| pull\| issues\)/ \([a- z0-9 ]+ \)/?$| } in
104
110
match Uri. host url with
105
111
| None -> None
106
112
| Some host ->
107
- match Re.Str. string_match re path 0 with
108
- | false -> None
109
- | true ->
110
- let base = host ^ Re.Str. matched_group 1 path in
111
- let owner = Re.Str. matched_group 2 path in
112
- let name = Re.Str. matched_group 3 path in
113
- let link_type = Re.Str. matched_group 4 path in
114
- let item = Re.Str. matched_group 5 path in
113
+ match Re2. find_submatches_exn gh_re path with
114
+ | [| _; prefix; Some owner; Some name; Some link_type; Some item |] ->
115
+ let base = Option. value_map prefix ~default: host ~f: (fun p -> String. concat [ host; p ]) in
115
116
let scheme = Uri. scheme url in
116
117
let html_base, api_base =
117
118
if String. is_suffix base ~suffix: " github.com" then gh_com_html_base owner name, gh_com_api_base owner name
@@ -137,3 +138,4 @@ let gh_link_of_string url_str =
137
138
| _ -> None
138
139
with _ -> None
139
140
end
141
+ | _ | (exception Re2.Exceptions. Regex_match_failed _ ) -> None
0 commit comments