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<()> {
1111 Ok ( ( ) )
1212}
1313
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+
1428fn generate_codeowners_content ( admins : Vec < String > ) -> String {
1529 use std:: fmt:: Write ;
1630
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ use data::Data;
1616use schema:: { Email , Team , TeamKind } ;
1717use zulip:: ZulipApi ;
1818
19- use crate :: ci:: generate_codeowners_file;
19+ use crate :: ci:: { check_codeowners , generate_codeowners_file} ;
2020use crate :: schema:: RepoPermission ;
2121use anyhow:: { bail, format_err, Error } ;
2222use log:: { error, info, warn} ;
@@ -121,6 +121,8 @@ enum Cli {
121121enum CiOpts {
122122 #[ structopt( help = "Generate the .github/CODEOWNERS file" ) ]
123123 GenerateCodeowners ,
124+ #[ structopt( help = "Check if the .github/CODEOWNERS file is up-to-date" ) ]
125+ CheckCodeowners ,
124126}
125127
126128fn main ( ) {
@@ -434,6 +436,7 @@ fn run() -> Result<(), Error> {
434436 }
435437 Cli :: Ci ( opts) => match opts {
436438 CiOpts :: GenerateCodeowners => generate_codeowners_file ( ) ?,
439+ CiOpts :: CheckCodeowners => check_codeowners ( ) ?,
437440 } ,
438441 }
439442
You can’t perform that action at this time.
0 commit comments