Skip to content

Commit 85161a1

Browse files
committed
cfg: change project owner syntax to record list
1 parent e53467a commit 85161a1

File tree

5 files changed

+36
-11
lines changed

5 files changed

+36
-11
lines changed

documentation/config_docs.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,16 @@ Note that the owner of the personal access token cannot be a project owner, as G
258258
{
259259
...,
260260
"project_owners": {
261-
"Label 1": ["user1", "user2", "org/team1"],
262-
"Label 2": ["org/team2", "user3"]
261+
"rules": [
262+
{
263+
"label": "Label 1",
264+
"owners": ["user1", "user2", "org/team1"]
265+
},
266+
{
267+
"label": "Label 2",
268+
"owners": ["org/team2", "user3"]
269+
}
270+
]
263271
},
264272
...
265273
}

lib/config.atd

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
type status_rule <ocaml from="Rule"> = abstract
22
type prefix_rule <ocaml from="Rule"> = abstract
33
type label_rule <ocaml from="Rule"> = abstract
4-
type 'v map_as_object <ocaml from="Common"> = abstract
4+
type project_owners_rule <ocaml from="Rule"> = abstract
55

66
(* This type of rule is used for CI build notifications. *)
77
type status_rules = {
@@ -23,13 +23,18 @@ type label_rules = {
2323
rules: label_rule list;
2424
}
2525

26+
(* This type of rule is used for routing PR review requests to users. *)
27+
type project_owners = {
28+
rules: project_owners_rule list;
29+
}
30+
2631
(* This is the structure of the repository configuration file. It should be at the
2732
root of the monorepo, on the main branch. *)
2833
type config = {
2934
prefix_rules : prefix_rules;
3035
label_rules : label_rules;
3136
~status_rules <ocaml default="{allowed_pipelines = Some []; rules = []}"> : status_rules;
32-
~project_owners <ocaml default="Common.StringMap.empty"> : string list map_as_object;
37+
~project_owners <ocaml default="{rules = []}"> : project_owners;
3338
?main_branch_name : string nullable; (* the name of the main branch; used to filter out notifications about merges of main branch into other branches *)
3439
}
3540

lib/github.ml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,8 @@ let gh_link_of_string url_str =
140140
end
141141
| _ | (exception Re2.Exceptions.Regex_match_failed _) -> None
142142

143-
let get_project_owners (labels : label list) project_owners_map =
144-
List.fold_left labels ~init:[] ~f:(fun acc label ->
145-
match Map.find_multi project_owners_map label.name with
146-
| [] -> acc
147-
| reviewers -> List.rev_append reviewers acc
148-
)
143+
let get_project_owners (labels : label list) ({ rules } : Config_t.project_owners) =
144+
List.fold_left labels ~init:[] ~f:(fun acc l -> List.rev_append (Rule.Project_owners.match_rules l ~rules) acc)
149145
|> List.dedup_and_sort ~compare:String.compare
150146
|> List.partition_map ~f:(fun reviewer ->
151147
try

lib/rule.atd

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,13 @@ type label_rule = {
7979
?allow <json name="match"> : string list nullable;
8080
?ignore : string list nullable;
8181
channel_name <json name="channel"> : string;
82-
}
82+
}
83+
84+
(* Requests reviews from [owners] if a PR is labeled with [label]. Owner format:
85+
- users: "username"
86+
- teams: "org/team"
87+
*)
88+
type project_owners_rule = {
89+
label: string;
90+
owners: string list;
91+
}

lib/rule.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,10 @@ module Label = struct
125125
Stdio.printf " -> #%s\n%!" rule.channel_name
126126
)
127127
end
128+
129+
module Project_owners = struct
130+
let match_rules (l : Github_t.label) ~rules =
131+
match List.find rules ~f:(fun { label; _ } -> String.equal label l.name) with
132+
| Some { owners = []; _ } | None -> []
133+
| Some { owners; _ } -> owners
134+
end

0 commit comments

Comments
 (0)