File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,20 @@ pub fn generate_codeowners_file() -> anyhow::Result<()> {
11
11
Ok ( ( ) )
12
12
}
13
13
14
+ /// Check if `.github/CODEOWNERS` are up-to-date, based on the
15
+ /// `infra-admins.toml` file.
16
+ pub fn check_codeowners ( ) -> anyhow:: Result < ( ) > {
17
+ let admins = load_infra_admins ( ) ?;
18
+ let expected_codeowners = generate_codeowners_content ( admins) ;
19
+ let actual_codeowners =
20
+ std:: fs:: read_to_string ( codeowners_path ( ) ) . context ( "cannot read CODEOWNERS" ) ?;
21
+ if expected_codeowners != actual_codeowners {
22
+ return Err ( anyhow:: anyhow!( "CODEOWNERS content is not up-to-date. Regenerate it using `cargo run ci generate-codeowners`." ) ) ;
23
+ }
24
+
25
+ Ok ( ( ) )
26
+ }
27
+
14
28
fn generate_codeowners_content ( admins : Vec < String > ) -> String {
15
29
use std:: fmt:: Write ;
16
30
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ use data::Data;
16
16
use schema:: { Email , Team , TeamKind } ;
17
17
use zulip:: ZulipApi ;
18
18
19
- use crate :: ci:: generate_codeowners_file;
19
+ use crate :: ci:: { check_codeowners , generate_codeowners_file} ;
20
20
use crate :: schema:: RepoPermission ;
21
21
use anyhow:: { bail, format_err, Error } ;
22
22
use log:: { error, info, warn} ;
@@ -121,6 +121,8 @@ enum Cli {
121
121
enum CiOpts {
122
122
#[ structopt( help = "Generate the .github/CODEOWNERS file" ) ]
123
123
GenerateCodeowners ,
124
+ #[ structopt( help = "Check if the .github/CODEOWNERS file is up-to-date" ) ]
125
+ CheckCodeowners ,
124
126
}
125
127
126
128
fn main ( ) {
@@ -434,6 +436,7 @@ fn run() -> Result<(), Error> {
434
436
}
435
437
Cli :: Ci ( opts) => match opts {
436
438
CiOpts :: GenerateCodeowners => generate_codeowners_file ( ) ?,
439
+ CiOpts :: CheckCodeowners => check_codeowners ( ) ?,
437
440
} ,
438
441
}
439
442
You can’t perform that action at this time.
0 commit comments