Skip to content

Commit

Permalink
restore behavior to print config when it is refreshed
Browse files Browse the repository at this point in the history
  • Loading branch information
yasunariw committed Dec 22, 2020
1 parent 86bd8c8 commit ab23e00
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/action.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ let action_error msg = raise (Action_error msg)
let log = Log.from "action"

module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
(* this should move to context.ml once rule.ml is refactored to not depend on it *)
let print_config ctx =
let cfg = Context.get_config_exn ctx in
let secrets = Context.get_secrets_exn ctx in
log#info "using prefix routing:";
Rule.Prefix.print_prefix_routing cfg.prefix_rules.rules;
log#info "using label routing:";
Rule.Label.print_label_routing cfg.label_rules.rules;
log#info "signature checking %s" (if Option.is_some secrets.gh_hook_token then "enabled" else "disabled")

let partition_push cfg n =
let default = Option.to_list cfg.prefix_rules.default_channel in
let rules = cfg.prefix_rules.rules in
Expand Down Expand Up @@ -203,6 +213,7 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
let repo = Github.repo_of_notification notification in
match%lwt Github_api.get_config ~ctx ~repo with
| Ok config ->
print_config ctx;
(* can remove this wrapper once status_rules doesn't depend on Config.t *)
ctx.config <- Some (Config.make config);
Lwt.return @@ Ok ()
Expand Down
30 changes: 30 additions & 0 deletions lib/rule.ml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ module Prefix = struct
|> List.filter_map ~f:match_rule
|> List.max_elt ~compare
|> Option.map ~f:(fun (res : prefix_rule * int) -> (fst res).channel_name)

let print_prefix_routing rules =
let show_match l = String.concat ~sep:" or " @@ List.map ~f:(fun s -> s ^ "*") l in
rules
|> List.iter ~f:(fun (rule : prefix_rule) ->
begin
match rule.allow, rule.ignore with
| None, None -> Stdio.printf " any"
| None, Some [] -> Stdio.printf " any"
| None, Some l -> Stdio.printf " not %s" (show_match l)
| Some l, None -> Stdio.printf " %s" (show_match l)
| Some l, Some [] -> Stdio.printf " %s" (show_match l)
| Some l, Some i -> Stdio.printf " %s and not %s" (show_match l) (show_match i)
end;
Stdio.printf " -> #%s\n%!" rule.channel_name)
end

module Label = struct
Expand All @@ -83,4 +98,19 @@ module Label = struct
| Some allow_list -> if List.exists allow_list ~f:label_name_equal then Some rule.channel_name else None
in
rules |> List.filter_map ~f:match_rule |> List.dedup_and_sort ~compare:String.compare

let print_label_routing rules =
let show_match l = String.concat ~sep:" or " l in
rules
|> List.iter ~f:(fun (rule : label_rule) ->
begin
match rule.allow, rule.ignore with
| None, None -> Stdio.printf " any"
| None, Some [] -> Stdio.printf " any"
| None, Some l -> Stdio.printf " not %s" (show_match l)
| Some l, None -> Stdio.printf " %s" (show_match l)
| Some l, Some [] -> Stdio.printf " %s" (show_match l)
| Some l, Some i -> Stdio.printf " %s and not %s" (show_match l) (show_match i)
end;
Stdio.printf " -> #%s\n%!" rule.channel_name)
end

0 comments on commit ab23e00

Please sign in to comment.