File tree Expand file tree Collapse file tree 3 files changed +12
-3
lines changed Expand file tree Collapse file tree 3 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -15,20 +15,22 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
15
15
let partition_push (cfg : Config_t.config ) n =
16
16
let default = Option. to_list cfg.prefix_rules.default_channel in
17
17
let rules = cfg.prefix_rules.rules in
18
+ let branch = Github. commits_branch_of_ref n.ref in
18
19
n.commits
19
- |> List. filter ~f: (fun c -> c.distinct)
20
20
|> List. filter ~f: (fun c ->
21
- let branch = Github. commits_branch_of_ref n.ref in
22
21
let skip = Github. is_main_merge_message ~msg: c.message ~branch cfg in
23
22
if skip then log#info " main branch merge, ignoring %s: %s" c.id (first_line c.message);
24
23
not skip)
25
24
|> List. concat_map ~f: (fun commit ->
25
+ let rules = List. filter ~f: (Rule.Prefix. filter_by_branch ~branch ~distinct: commit.distinct) rules in
26
26
let matched_channel_names =
27
27
Github. modified_files_of_commit commit
28
28
|> List. filter_map ~f: (Rule.Prefix. match_rules ~rules )
29
29
|> List. dedup_and_sort ~compare: String. compare
30
30
in
31
- let channel_names = if List. is_empty matched_channel_names then default else matched_channel_names in
31
+ let channel_names =
32
+ if List. is_empty matched_channel_names && commit.distinct then default else matched_channel_names
33
+ in
32
34
List. map channel_names ~f: (fun n -> n, commit))
33
35
|> Map. of_alist_multi (module String )
34
36
|> Map. map ~f: (fun commits -> { n with commits })
Original file line number Diff line number Diff line change @@ -66,6 +66,7 @@ type status_rule = {
66
66
type prefix_rule = {
67
67
?allow <json name="match"> : string list nullable;
68
68
?ignore : string list nullable;
69
+ ~branch_filters <ocaml default="[]"> : string list;
69
70
channel_name <json name="channel"> : string;
70
71
}
71
72
Original file line number Diff line number Diff line change @@ -39,6 +39,12 @@ 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
47
+
42
48
(* * `match_rules f rs` returns the channel name of a rule in `rs` that matches
43
49
file name `f` with the longest prefix, if one exists. A rule `r` matches
44
50
`f` with prefix length `l`, if `f` has no prefix in `r.ignore` and `l` is
You can’t perform that action at this time.
0 commit comments