Skip to content

Commit a60760a

Browse files
committed
restore behavior to print config when it is refreshed
1 parent 875c73e commit a60760a

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

lib/action.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ let action_error msg = raise (Action_error msg)
1313
let log = Log.from "action"
1414

1515
module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
16+
(* this should move to context.ml once rule.ml is refactored to not depend on it *)
17+
let print_config ctx =
18+
let cfg = Context.get_config_exn ctx in
19+
let secrets = Context.get_secrets_exn ctx in
20+
log#info "using prefix routing:";
21+
Rule.Prefix.print_prefix_routing cfg.prefix_rules.rules;
22+
log#info "using label routing:";
23+
Rule.Label.print_label_routing cfg.label_rules.rules;
24+
log#info "signature checking %s" (if Option.is_some secrets.gh_hook_token then "enabled" else "disabled")
25+
1626
let partition_push cfg n =
1727
let default = Option.to_list cfg.prefix_rules.default_channel in
1828
let rules = cfg.prefix_rules.rules in
@@ -203,6 +213,7 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
203213
let repo = Github.repo_of_notification notification in
204214
match%lwt Github_api.get_config ~ctx ~repo with
205215
| Ok config ->
216+
print_config ctx;
206217
(* can remove this wrapper once status_rules doesn't depend on Config.t *)
207218
ctx.config <- Some (Config.make config);
208219
Lwt.return @@ Ok ()

lib/rule.ml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ module Prefix = struct
6363
|> List.filter_map ~f:match_rule
6464
|> List.max_elt ~compare
6565
|> Option.map ~f:(fun (res : prefix_rule * int) -> (fst res).channel_name)
66+
67+
let print_prefix_routing rules =
68+
let show_match l = String.concat ~sep:" or " @@ List.map ~f:(fun s -> s ^ "*") l in
69+
rules
70+
|> List.iter ~f:(fun (rule : prefix_rule) ->
71+
begin
72+
match rule.allow, rule.ignore with
73+
| None, None -> Stdio.printf " any"
74+
| None, Some [] -> Stdio.printf " any"
75+
| None, Some l -> Stdio.printf " not %s" (show_match l)
76+
| Some l, None -> Stdio.printf " %s" (show_match l)
77+
| Some l, Some [] -> Stdio.printf " %s" (show_match l)
78+
| Some l, Some i -> Stdio.printf " %s and not %s" (show_match l) (show_match i)
79+
end;
80+
Stdio.printf " -> #%s\n%!" rule.channel_name)
6681
end
6782

6883
module Label = struct
@@ -83,4 +98,19 @@ module Label = struct
8398
| Some allow_list -> if List.exists allow_list ~f:label_name_equal then Some rule.channel_name else None
8499
in
85100
rules |> List.filter_map ~f:match_rule |> List.dedup_and_sort ~compare:String.compare
101+
102+
let print_label_routing rules =
103+
let show_match l = String.concat ~sep:" or " l in
104+
rules
105+
|> List.iter ~f:(fun (rule : label_rule) ->
106+
begin
107+
match rule.allow, rule.ignore with
108+
| None, None -> Stdio.printf " any"
109+
| None, Some [] -> Stdio.printf " any"
110+
| None, Some l -> Stdio.printf " not %s" (show_match l)
111+
| Some l, None -> Stdio.printf " %s" (show_match l)
112+
| Some l, Some [] -> Stdio.printf " %s" (show_match l)
113+
| Some l, Some i -> Stdio.printf " %s and not %s" (show_match l) (show_match i)
114+
end;
115+
Stdio.printf " -> #%s\n%!" rule.channel_name)
86116
end

0 commit comments

Comments
 (0)