Skip to content

Commit cf43ba7

Browse files
committed
rule: use main_branch_name for global filtering
1 parent 694895f commit cf43ba7

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

documentation/config_docs.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Refer [here](https://docs.github.com/en/free-pro-team@latest/developers/webhooks
2929

3030
| value | description | optional | default |
3131
|-|-|-|-|
32-
| `main_branch_name` | main branch used for the repo; filtering notifications about merges of main into other branches | Yes | - |
32+
| `main_branch_name` | main branch used for the repo; filtering notifications about merges of main into other branches, and constraining prefix rule application | Yes | - |
3333
| `label_rules` | label rules config object | No | - |
3434
| `prefix_rules` | prefix rules config object | No | - |
3535
| `status_rules` | status rules config object | No | - |
@@ -97,7 +97,7 @@ A **label rule** specifies whether or not a Slack channel should be notified, ba
9797
```json
9898
"prefix_rules": {
9999
"default_channel": "default",
100-
"default_branch_filters": ["develop"],
100+
"filter_main_branch": true,
101101
"rules": [
102102
{
103103
"match": [
@@ -122,7 +122,7 @@ A **label rule** specifies whether or not a Slack channel should be notified, ba
122122
| value | description | if absent |
123123
|-|-|-|
124124
| `default_channel` | same behavior as label rule `default_channel` | |
125-
| `default_branch_filters` | fallback branch filters (see below) if none are declared locally for a rule | don't apply branch filtering and show `distinct` commits only |
125+
| `filter_main_branch` | if true and `main_branch_name` is declared, use main branch to filter rules that have no local filter; otherwise, don't apply branch filtering and show `distinct` commits only | false |
126126
| `rules` | list of `prefix_rule` objects | required field |
127127

128128
### Prefix Rule
@@ -131,14 +131,14 @@ A **prefix rule** specifies whether or not a Slack channel should be notified, b
131131

132132
Default behavior is to apply each rule regardless of what branch is pushed, and when a rule is matched, show its `distinct` commits only.
133133
Branch filters limit rule application to selected branches, and shows _all_ commits on match.
134-
The filters can be declared globally with `default_branch_filters` (see above), or locally per rule with `branch_filters`, where the latter takes precedence.
134+
The filters can be declared globally with `filter_main_branch` (see above), or locally per rule with `branch_filters`, where the latter takes precedence.
135135
To ignore a globally declared filter for a single rule, declare one locally with an empty list, as shown in the example above.
136136

137137
| value | description | if absent |
138138
|-|-|-|
139139
| `match` | if commit files have any prefix in this list, they should be routed to the channel | all prefixes matched |
140140
| `ignore` | if commit files have any prefix in this list, they shouldn't be routed to the channel (even if they have any `match` prefixes) | fall back on `match` field behavior |
141-
| `branch_filters` | consider commits only if pushed ref branch is in this list | fall back on `default_branch_filters` field behavior (see above) |
141+
| `branch_filters` | consider commits only if pushed ref branch is in this list | fall back on `filter_main_branch` field behavior (see above) |
142142
| `channel` | channel to notify if the rule is matched | required field |
143143

144144
## Status Options

lib/action.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
1616
let default = Option.to_list cfg.prefix_rules.default_channel in
1717
let rules = cfg.prefix_rules.rules in
1818
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+
let main_branch = if cfg.prefix_rules.filter_main_branch then cfg.main_branch_name else None in
20+
let filter_by_branch = Rule.Prefix.filter_by_branch ~branch ~main_branch in
2121
n.commits
2222
|> List.filter ~f:(fun c ->
2323
let skip = Github.is_main_merge_message ~msg:c.message ~branch cfg in

lib/config.atd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type status_rules = {
1212
files they are related to. *)
1313
type prefix_rules = {
1414
?default_channel: string nullable; (* if none of the rules is matching *)
15-
~default_branch_filters <ocaml default="[]">: string list;
15+
~filter_main_branch <ocaml default="false">: bool;
1616
rules: prefix_rule list;
1717
}
1818

lib/rule.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ end
4040

4141
module Prefix = struct
4242
(** Filters prefix rules based on branch filtering config and current commit.
43-
Prioritizes local filters over default ones. Only allows distinct commits
43+
Prioritizes local filters over main branch one. Only allows distinct commits
4444
if no filter is matched. *)
45-
let filter_by_branch ~branch ~default_branch_filters ~distinct rule =
45+
let filter_by_branch ~branch ~main_branch ~distinct rule =
4646
match rule.branch_filters with
4747
| Some (_ :: _ as filters) -> List.mem filters branch ~equal:String.equal
4848
| Some [] -> distinct
4949
| None ->
50-
match default_branch_filters with
51-
| _ :: _ as filters -> List.mem filters branch ~equal:String.equal
52-
| [] -> distinct
50+
match main_branch with
51+
| Some main_branch -> String.equal main_branch branch
52+
| None -> distinct
5353

5454
(** `match_rules f rs` returns the channel name of a rule in `rs` that matches
5555
file name `f` with the longest prefix, if one exists. A rule `r` matches

0 commit comments

Comments
 (0)