Skip to content

Commit d28c3a4

Browse files
committed
revert differentiation of empty allow/ignore list from undefined list
Restore earlier behavior that treated empty list `[]` as “include everything” for compatibility with existing deployments.
1 parent a60760a commit d28c3a4

File tree

3 files changed

+38
-13
lines changed

3 files changed

+38
-13
lines changed

documentation/config_docs.md

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,28 @@ A json object with fields of bools for each status type.
8080
"default_channel": "default",
8181
"rules": [
8282
{
83-
"allow": ["backend"],
83+
"allow": [
84+
"backend"
85+
],
86+
"ignore": [],
8487
"channel": "backend"
8588
},
8689
{
87-
"allow": ["a1"],
90+
"allow": [
91+
"a1"
92+
],
93+
"ignore": [],
8894
"channel": "a1-bot"
8995
},
9096
{
91-
"allow": ["a3"],
97+
"allow": [
98+
"a3"
99+
],
100+
"ignore": [],
92101
"channel": "a3"
93102
},
94103
{
104+
"allow": [],
95105
"ignore": [
96106
"backend",
97107
"a1",
@@ -110,12 +120,12 @@ A json object with fields of bools for each status type.
110120

111121
### Label Rule
112122

113-
A **label rule** specifies whether or not a Slack channel should be notified, based on the labels present in the given payload. For each rule, `ignore` is a blacklist of labels that should not notify the rule's channel, and `allow` is a whitelist of labels that should. The `ignore` list takes precedence over the `allow` list. Both are optional; if neither are provided, the rule will always generate a notification for its channel.
123+
A **label rule** specifies whether or not a Slack channel should be notified, based on the labels present in the given payload. For each rule, `ignore` is a blacklist of labels that should not notify the rule's channel, and `allow` is a whitelist of labels that should. If a label exists in both lists, the `ignore` list takes precedence. If an empty `ignore` list is provided, nothing is ignored. If an empty `allow` list is provided, everything is allowed. Both are optional; if neither are provided, the rule will always generate a notification for its channel.
114124

115125
| value | description | optional | default |
116126
|-|-|-|-|
117-
| `allow` | whitelist of labels that should match the rule | Yes | all labels allowed if no list provided |
118-
| `ignore` | blacklist of labels that shouldn't match the rule | Yes | - |
127+
| `allow` | if notifications match any label in this list, they should be routed to the channel | Yes | all labels allowed if no list provided |
128+
| `ignore` | if notifications match any label in this list, they shouldn't be routed to the channel (even if they match any allow labels) | Yes | - |
119129
| `channel` | channel to use as webhook if the rule is matched | No | - |
120130

121131
## Prefix Options
@@ -128,17 +138,23 @@ A **label rule** specifies whether or not a Slack channel should be notified, ba
128138
"default_channel": "default",
129139
"rules": [
130140
{
131-
"allow": ["backend/a1"],
141+
"allow": [
142+
"backend/a1"
143+
],
144+
"ignore": [],
132145
"channel": "a1"
133146
},
134147
{
135148
"allow": [
136149
"backend/a5",
137150
"backend/a4"
138151
],
152+
"ignore": [],
139153
"channel": "backend"
140154
},
141155
{
156+
"allow": [],
157+
"ignore": [],
142158
"channel": "all-push-events"
143159
}
144160
]
@@ -151,6 +167,6 @@ A **prefix rule** specifies whether or not a Slack channel should be notified, b
151167

152168
| value | description | optional | default |
153169
|-|-|-|-|
154-
| `allow` | whitelist of file prefixes that should match the rule | Yes | all prefixes allowed if no list provided |
155-
| `ignore` | blacklist of file prefixes that shouldn't match the rule | Yes | - |
170+
| `allow` | if commit files match any prefix in this list, they should be routed to the channel | Yes | all prefixes allowed if no list provided |
171+
| `ignore` | if commit files match any prefix in this list, they shouldn't be routed to the channel (even if they match any allow prefixes) | Yes | - |
156172
| `channel` | channel to use as webhook if the rule is matched | No | - |

lib/rule.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ module Prefix = struct
4242
(** `match_rules f rs` returns the channel name of a rule in `rs` that matches
4343
file name `f` with the longest prefix, if one exists. A rule `r` matches
4444
`f` with prefix length `l`, if `f` has no prefix in `r.ignore` and `l` is
45-
the length of the longest prefix of `f` in `r.allow`. An undefined allow
46-
list is considered a prefix match of length 0. The ignore list is
45+
the length of the longest prefix of `f` in `r.allow`. An undefined or empty
46+
allow list is considered a prefix match of length 0. The ignore list is
4747
evaluated before the allow list. *)
4848
let match_rules filename ~rules =
4949
let compare a b = Int.compare (snd a) (snd b) in
@@ -53,7 +53,7 @@ module Prefix = struct
5353
| Some ignore_list when List.exists ignore_list ~f:is_prefix -> None
5454
| _ ->
5555
match rule.allow with
56-
| None -> Some (rule, 0)
56+
| None | Some [] -> Some (rule, 0)
5757
| Some allow_list ->
5858
allow_list
5959
|> List.filter_map ~f:(fun p -> if is_prefix p then Some (rule, String.length p) else None)
@@ -94,7 +94,7 @@ module Label = struct
9494
| Some ignore_list when List.exists ignore_list ~f:label_name_equal -> None
9595
| _ ->
9696
match rule.allow with
97-
| None -> Some rule.channel_name
97+
| None | Some [] -> Some rule.channel_name
9898
| Some allow_list -> if List.exists allow_list ~f:label_name_equal then Some rule.channel_name else None
9999
in
100100
rules |> List.filter_map ~f:match_rule |> List.dedup_and_sort ~compare:String.compare

test/notabot.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,27 @@
2020
"allow": [
2121
"backend/a1"
2222
],
23+
"ignore": [],
2324
"channel": "a1"
2425
},
2526
{
2627
"allow": [
2728
"backend/a1/longest"
2829
],
30+
"ignore": [],
2931
"channel": "longest-a1"
3032
},
3133
{
3234
"allow": [
3335
"backend/a5",
3436
"backend/a4"
3537
],
38+
"ignore": [],
3639
"channel": "backend"
3740
},
3841
{
42+
"allow": [],
43+
"ignore": [],
3944
"channel": "all-push-events"
4045
}
4146
]
@@ -47,21 +52,25 @@
4752
"allow": [
4853
"backend"
4954
],
55+
"ignore": [],
5056
"channel": "backend"
5157
},
5258
{
5359
"allow": [
5460
"a1"
5561
],
62+
"ignore": [],
5663
"channel": "a1-bot"
5764
},
5865
{
5966
"allow": [
6067
"a3"
6168
],
69+
"ignore": [],
6270
"channel": "a3"
6371
},
6472
{
73+
"allow": [],
6574
"ignore": [
6675
"backend",
6776
"a1",

0 commit comments

Comments
 (0)