File tree Expand file tree Collapse file tree 3 files changed +14
-6
lines changed Expand file tree Collapse file tree 3 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -16,13 +16,15 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
16
16
let default = Option. to_list cfg.prefix_rules.default_channel in
17
17
let rules = cfg.prefix_rules.rules in
18
18
let branch = Github. commits_branch_of_ref n.ref in
19
+ let default_branch_filters = cfg.prefix_rules.default_branch_filters in
20
+ let filter_by_branch = Rule.Prefix. filter_by_branch ~branch ~default_branch_filters in
19
21
n.commits
20
22
|> List. filter ~f: (fun c ->
21
23
let skip = Github. is_main_merge_message ~msg: c.message ~branch cfg in
22
24
if skip then log#info " main branch merge, ignoring %s: %s" c.id (first_line c.message);
23
25
not skip)
24
26
|> List. concat_map ~f: (fun commit ->
25
- let rules = List. filter ~f: (Rule.Prefix. filter_by_branch ~branch ~distinct: commit.distinct) rules in
27
+ let rules = List. filter ~f: (filter_by_branch ~distinct: commit.distinct) rules in
26
28
let matched_channel_names =
27
29
Github. modified_files_of_commit commit
28
30
|> List. filter_map ~f: (Rule.Prefix. match_rules ~rules )
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ type status_rules = {
12
12
files they are related to. *)
13
13
type prefix_rules = {
14
14
?default_channel: string nullable; (* if none of the rules is matching *)
15
+ ~default_branch_filters <ocaml default="[]">: string list;
15
16
rules: prefix_rule list;
16
17
}
17
18
Original file line number Diff line number Diff line change @@ -39,11 +39,16 @@ module Status = struct
39
39
end
40
40
41
41
module Prefix = struct
42
- (* * Filters prefix rules based on config and current commit. Returns true if
43
- `branch_filters` includes the commit branch, or if it's empty but the
44
- commit is `distinct`. *)
45
- let filter_by_branch ~branch ~distinct rule =
46
- (List. is_empty rule.branch_filters && distinct) || List. mem rule.branch_filters branch ~equal: String. equal
42
+ (* * Filters prefix rules based on branch filtering config and current commit.
43
+ Prioritizes local filters over default ones. Only allows distinct commits
44
+ if no filter is matched. *)
45
+ let filter_by_branch ~branch ~default_branch_filters ~distinct rule =
46
+ match rule.branch_filters with
47
+ | _ :: _ as filters -> List. mem filters branch ~equal: String. equal
48
+ | [] ->
49
+ match default_branch_filters with
50
+ | _ :: _ as filters -> List. mem filters branch ~equal: String. equal
51
+ | [] -> distinct
47
52
48
53
(* * `match_rules f rs` returns the channel name of a rule in `rs` that matches
49
54
file name `f` with the longest prefix, if one exists. A rule `r` matches
You can’t perform that action at this time.
0 commit comments