Skip to content

Commit 3eb8b8d

Browse files
committed
use more descriptive names in atd files and cli options
1 parent 5420096 commit 3eb8b8d

File tree

11 files changed

+154
-147
lines changed

11 files changed

+154
-147
lines changed

documentation/config_docs.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ Config file is where the variables affecting the behaviour of notabot are define
1010
"offline": "github-api-cache",
1111
"main_branch_name": "develop",
1212
"status_rules": {
13-
...
13+
...
1414
},
1515
"prefix_rules": {
16-
...
16+
...
1717
},
1818
"label_rules": {
19-
...
19+
...
2020
},
2121
"suppress_cancelled_events": true
2222
}
@@ -36,7 +36,7 @@ Config file is where the variables affecting the behaviour of notabot are define
3636
**example**
3737
```json
3838
"status_rules": {
39-
"title": [
39+
"allowed_pipelines": [
4040
"default",
4141
"buildkite/pipeline2"
4242
],
@@ -75,54 +75,54 @@ Label rules apply to PR and issues notifications.
7575
**example**
7676
```json
7777
"label_rules": {
78-
"default": "default",
78+
"default_channel": "default",
7979
"rules": [
8080
{
81-
"label_name": [
81+
"allow": [
8282
"backend"
8383
],
8484
"ignore": [],
85-
"chan": "backend"
85+
"channel": "backend"
8686
},
8787
{
88-
"label_name": [
88+
"allow": [
8989
"a1"
9090
],
9191
"ignore": [],
92-
"chan": "a1-bot"
92+
"channel": "a1-bot"
9393
},
9494
{
95-
"label_name": [
95+
"allow": [
9696
"a3"
9797
],
9898
"ignore": [],
99-
"chan": "a3"
99+
"channel": "a3"
100100
},
101101
{
102-
"label_name": [],
102+
"allow": [],
103103
"ignore": [
104104
"backend",
105105
"a1",
106106
"a3"
107107
],
108-
"chan": "frontend-bot"
108+
"channel": "frontend-bot"
109109
}
110110
]
111111
},
112112
```
113113

114114
| value | description | optional | default |
115115
|-|-|-|-|
116-
| `default` | default channel to notify if no rules match | Yes | no channels will be notified on default |
116+
| `default_channel` | default channel to notify if no rules match | Yes | no channels will be notified on default |
117117
| `rules` | list of `label_rule` objects | No | - |
118118

119119
### Label Rule
120120

121121
| value | description | optional | default |
122122
|-|-|-|-|
123-
| `label_name` | whitelist of label values that match this rule; if list is empty it vacuously satisfies the rule | No | - |
123+
| `allow` | whitelist of label values that match this rule; if list is empty it vacuously satisfies the rule | No | - |
124124
| `ignore` | blacklist of label values; any labels matching will not match the rule | No | - |
125-
| `chan` | channel to use as webhook if matching this label rule | No | - |
125+
| `channel` | channel to use as webhook if matching this label rule | No | - |
126126

127127
## Prefix Config
128128

@@ -133,27 +133,27 @@ The prefix config object is exactly the same as **Label Config** except its `rul
133133
**example**
134134
```json
135135
"prefix_rules": {
136-
"default": "default",
136+
"default_channel": "default",
137137
"rules": [
138138
{
139-
"prefix": [
139+
"allow": [
140140
"backend/a1"
141141
],
142142
"ignore": [],
143-
"chan": "a1"
143+
"channel": "a1"
144144
},
145145
{
146-
"prefix": [
146+
"allow": [
147147
"backend/a5",
148148
"backend/a4"
149149
],
150150
"ignore": [],
151-
"chan": "backend"
151+
"channel": "backend"
152152
},
153153
{
154-
"prefix": [],
154+
"allow": [],
155155
"ignore": [],
156-
"chan": "all-push-events"
156+
"channel": "all-push-events"
157157
}
158158
]
159159
},
@@ -164,6 +164,6 @@ The prefix config object is exactly the same as **Label Config** except its `rul
164164

165165
| value | description | optional | default |
166166
|-|-|-|-|
167-
| `prefix` | whitelist of strings that if prefixed in the filename matches the rule | No | - |
167+
| `allow` | whitelist of strings that if prefixed in the filename matches the rule | No | - |
168168
| `ignore` | blacklist of strings that if prefixed in the filename does not match the rule | No | - |
169-
| `chan` | channel to use as webhook if matching this prefix rule | No | - |
169+
| `channel` | channel to use as webhook if matching this prefix rule | No | - |

documentation/secret_docs.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Secret file is where sensitive information such as the urls used for webhooks an
77
**example**
88
```json
99
{
10-
"slack_channels": [
10+
"slack_hooks": [
1111
{
1212
"url": "https://slack_webhook_url",
1313
"channel": "default"
@@ -42,7 +42,7 @@ Secret file is where sensitive information such as the urls used for webhooks an
4242

4343
| value | description | optional | default |
4444
|-|-|-|-|
45-
| `slack_channels` | list of webhook config objects | No | - |
45+
| `slack_hooks` | list of webhook config objects | No | - |
4646
| `gh_token` | must not be specified for public repositories | Yes | - |
4747
| `gh_webhook_secret` | if not specified signatures will not be checked | Yes | - |
4848

lib/action.ml

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type prefix_match =
1313
| Match of int
1414
| NoMatch
1515

16-
let chan_of_prefix_rule (r : prefix_rule) = r.chan
16+
let chan_of_prefix_rule (r : prefix_rule) = r.channel_name
1717

1818
let touching_prefix (rule : Notabot_t.prefix_rule) name =
1919
let match_lengths filename prefixes =
@@ -24,10 +24,10 @@ let touching_prefix (rule : Notabot_t.prefix_rule) name =
2424
match match_lengths name rule.ignore with
2525
| _ :: _ -> NoMatch
2626
| [] ->
27-
match rule.prefix with
27+
match rule.allow with
2828
| [] -> Match 0
2929
| _ ->
30-
match List.max_elt (match_lengths name rule.prefix) ~compare:Int.compare with
30+
match List.max_elt (match_lengths name rule.allow) ~compare:Int.compare with
3131
| Some x -> Match x
3232
| None -> NoMatch
3333

@@ -58,7 +58,7 @@ let unique_chans_of_files rules files =
5858

5959
let touching_label rule name =
6060
let name_lc = String.lowercase name in
61-
let label_lc = List.map rule.label_name ~f:(fun l -> String.lowercase l) in
61+
let label_lc = List.map rule.allow ~f:(fun l -> String.lowercase l) in
6262
let ignore_lc = List.map rule.ignore ~f:(fun l -> String.lowercase l) in
6363
(* convert both labels and config into lowe-case to make label matching case-insensitive *)
6464
(List.is_empty label_lc || List.mem ~equal:String.equal label_lc name_lc)
@@ -93,7 +93,9 @@ let group_commit chan l =
9393
| true -> Some commit)
9494

9595
let partition_push cfg n =
96-
let default commit = Option.value_map cfg.prefix_rules.default ~default:[] ~f:(fun webhook -> [ webhook, commit ]) in
96+
let default commit =
97+
Option.value_map cfg.prefix_rules.default_channel ~default:[] ~f:(fun webhook -> [ webhook, commit ])
98+
in
9799
let rules = cfg.prefix_rules.rules in
98100
let channels =
99101
n.commits
@@ -110,7 +112,10 @@ let partition_push cfg n =
110112
|> List.concat
111113
in
112114
let prefix_chans =
113-
let chans = Option.to_list cfg.prefix_rules.default @ List.map rules ~f:(fun (rule : prefix_rule) -> rule.chan) in
115+
let chans =
116+
Option.to_list cfg.prefix_rules.default_channel
117+
@ List.map rules ~f:(fun (rule : prefix_rule) -> rule.channel_name)
118+
in
114119
List.dedup_and_sort chans ~compare:String.compare
115120
in
116121
List.filter_map prefix_chans ~f:(fun chan ->
@@ -123,10 +128,10 @@ let filter_label rules (label : Github_j.label) =
123128
|> List.filter_map ~f:(fun rule ->
124129
match touching_label rule label.name with
125130
| false -> None
126-
| true -> Some rule.chan)
131+
| true -> Some rule.channel_name)
127132

128133
let partition_label cfg (labels : Github_j.label list) =
129-
let default = Option.to_list cfg.label_rules.default in
134+
let default = Option.to_list cfg.label_rules.default_channel in
130135
match labels with
131136
| [] -> default
132137
| labels ->
@@ -180,7 +185,7 @@ let partition_commit cfg files =
180185
let names = List.map ~f:(fun f -> f.filename) files in
181186
match unique_chans_of_files cfg.prefix_rules.rules names with
182187
| _ :: _ as xs -> xs
183-
| [] -> Option.to_list cfg.prefix_rules.default
188+
| [] -> Option.to_list cfg.prefix_rules.default_channel
184189

185190
let hide_cancelled (notification : status_notification) cfg =
186191
let find_cancelled status_state =
@@ -216,7 +221,7 @@ let hide_success (n : status_notification) (ctx : Context.t) =
216221
let partition_status (ctx : Context.t) (n : status_notification) =
217222
let cfg = ctx.cfg in
218223
let get_commit_info () =
219-
let default () = Lwt.return @@ Option.to_list cfg.prefix_rules.default in
224+
let default () = Lwt.return @@ Option.to_list cfg.prefix_rules.default_channel in
220225
match cfg.main_branch_name with
221226
| None -> default ()
222227
| Some main_branch_name ->
@@ -263,7 +268,7 @@ let partition_status (ctx : Context.t) (n : status_notification) =
263268
res
264269

265270
let partition_commit_comment cfg n =
266-
let default = Option.to_list cfg.prefix_rules.default in
271+
let default = Option.to_list cfg.prefix_rules.default_channel in
267272
match n.comment.path with
268273
| None ->
269274
( match%lwt Github.generate_commit_from_commit_comment cfg n with
@@ -308,25 +313,25 @@ let generate_notifications (ctx : Context.t) req =
308313
let print_prefix_routing rules =
309314
let show_match l = String.concat ~sep:" or " @@ List.map ~f:(fun s -> s ^ "*") l in
310315
rules
311-
|> List.iter ~f:(fun rule ->
316+
|> List.iter ~f:(fun (rule : prefix_rule) ->
312317
begin
313-
match rule.prefix, rule.ignore with
318+
match rule.allow, rule.ignore with
314319
| [], [] -> Stdio.printf " any"
315320
| l, [] -> Stdio.printf " %s" (show_match l)
316321
| [], l -> Stdio.printf " not %s" (show_match l)
317322
| l, i -> Stdio.printf " %s and not %s" (show_match l) (show_match i)
318323
end;
319-
Stdio.printf " -> #%s\n%!" rule.chan)
324+
Stdio.printf " -> #%s\n%!" rule.channel_name)
320325

321326
let print_label_routing rules =
322327
let show_match l = String.concat ~sep:" or " l in
323328
rules
324-
|> List.iter ~f:(fun rule ->
329+
|> List.iter ~f:(fun (rule : label_rule) ->
325330
begin
326-
match rule.label_name, rule.ignore with
331+
match rule.allow, rule.ignore with
327332
| [], [] -> Stdio.printf " any"
328333
| l, [] -> Stdio.printf " %s" (show_match l)
329334
| [], l -> Stdio.printf " not %s" (show_match l)
330335
| l, i -> Stdio.printf " %s and not %s" (show_match l) (show_match i)
331336
end;
332-
Stdio.printf " -> #%s\n%!" rule.chan)
337+
Stdio.printf " -> #%s\n%!" rule.channel_name)

lib/config.ml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ type status_rules = {
1313

1414
type t = {
1515
chans : string Chan_map.t;
16-
prefix_rules : Notabot_t.prefix_config;
17-
label_rules : Notabot_t.label_config;
16+
prefix_rules : Notabot_t.prefix_rules;
17+
label_rules : Notabot_t.label_rules;
1818
gh_webhook_secret : string option;
1919
main_branch_name : string option;
2020
gh_token : string option;
@@ -29,44 +29,44 @@ let make (json_config : Notabot_t.config) (secrets : Notabot_t.secrets) =
2929
match Chan_map.find_opt webhook.channel acc with
3030
| None -> Chan_map.add webhook.channel webhook.url acc
3131
| Some c -> Exn.fail "chan %s is defined multiple time in the config" c)
32-
Chan_map.empty secrets.slack_channels
32+
Chan_map.empty secrets.slack_hooks
3333
in
3434
let () =
3535
List.iteri
36-
(fun i ({ chan; _ } : Notabot_t.prefix_rule) ->
37-
match Chan_map.find_opt chan chans with
38-
| None -> Exn.fail "chan %s in prefix_rules %d is missing from slack_channels" chan i
36+
(fun i ({ channel_name; _ } : Notabot_t.prefix_rule) ->
37+
match Chan_map.find_opt channel_name chans with
38+
| None -> Exn.fail "chan %s in prefix_rules %d is missing from slack_hooks" channel_name i
3939
| Some _ -> ())
4040
json_config.prefix_rules.rules
4141
in
4242
let () =
4343
List.iteri
44-
(fun i ({ chan; _ } : Notabot_t.label_rule) ->
45-
match Chan_map.find_opt chan chans with
46-
| None -> Exn.fail "chan %s in labels_rules %d is missing from slack_channels" chan i
44+
(fun i ({ channel_name; _ } : Notabot_t.label_rule) ->
45+
match Chan_map.find_opt channel_name chans with
46+
| None -> Exn.fail "chan %s in labels_rules %d is missing from slack_hooks" channel_name i
4747
| Some _ -> ())
4848
json_config.label_rules.rules
4949
in
5050
let () =
51-
match json_config.prefix_rules.default with
51+
match json_config.prefix_rules.default_channel with
5252
| None -> ()
5353
| Some d ->
5454
match Chan_map.find_opt d chans with
55-
| None -> Exn.fail "default chan %s in prefix_rules is missing from slack_channels" d
55+
| None -> Exn.fail "default chan %s in prefix_rules is missing from slack_hooks" d
5656
| Some _ -> ()
5757
in
5858
let () =
59-
match json_config.label_rules.default with
59+
match json_config.label_rules.default_channel with
6060
| None -> ()
6161
| Some d ->
6262
match Chan_map.find_opt d chans with
63-
| None -> Exn.fail "default chan %s in label_rules is missing from slack_channels" d
63+
| None -> Exn.fail "default chan %s in label_rules is missing from slack_hooks" d
6464
| Some _ -> ()
6565
in
6666
let status_rules =
6767
let status =
6868
let open Github_t in
69-
let j = json_config.status_rules.status in
69+
let j = json_config.status_rules.rules in
7070
List.filter_map id
7171
[
7272
( match j.success with
@@ -83,7 +83,7 @@ let make (json_config : Notabot_t.config) (secrets : Notabot_t.secrets) =
8383
);
8484
]
8585
in
86-
{ title = json_config.status_rules.title; status }
86+
{ title = json_config.status_rules.allowed_pipelines; status }
8787
in
8888
{
8989
chans;

0 commit comments

Comments
 (0)