Skip to content

Commit a661fc6

Browse files
committed
Add command for checking if CODEOWNERS are up-to-date
1 parent dea794c commit a661fc6

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/ci.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
1428
fn generate_codeowners_content(admins: Vec<String>) -> String {
1529
use std::fmt::Write;
1630

src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use data::Data;
1616
use schema::{Email, Team, TeamKind};
1717
use zulip::ZulipApi;
1818

19-
use crate::ci::generate_codeowners_file;
19+
use crate::ci::{check_codeowners, generate_codeowners_file};
2020
use crate::schema::RepoPermission;
2121
use anyhow::{bail, format_err, Error};
2222
use log::{error, info, warn};
@@ -121,6 +121,8 @@ enum Cli {
121121
enum 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

126128
fn 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

0 commit comments

Comments
 (0)