Skip to content

Commit 1c0fa31

Browse files
committed
Include executable name in validator errors and messages
1 parent 4886abb commit 1c0fa31

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

src/ownership.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ impl Ownership {
123123
project: self.project.clone(),
124124
mappers: self.mappers(),
125125
file_generator: FileGenerator { mappers: self.mappers() },
126+
executable_name: self.project.executable_name.clone(),
126127
};
127128

128129
validator.validate()

src/ownership/validator.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ pub struct Validator {
2121
pub project: Arc<Project>,
2222
pub mappers: Vec<Box<dyn Mapper>>,
2323
pub file_generator: FileGenerator,
24+
pub executable_name: String,
2425
}
2526

2627
#[derive(Debug)]
2728
enum Error {
2829
InvalidTeam { name: String, path: PathBuf },
2930
FileWithoutOwner { path: PathBuf },
3031
FileWithMultipleOwners { path: PathBuf, owners: Vec<Owner> },
31-
CodeownershipFileIsStale,
32+
CodeownershipFileIsStale { executable_name: String },
3233
}
3334

3435
#[derive(Debug)]
@@ -130,12 +131,16 @@ impl Validator {
130131
match self.project.get_codeowners_file() {
131132
Ok(current_file) => {
132133
if generated_file != current_file {
133-
vec![Error::CodeownershipFileIsStale]
134+
vec![Error::CodeownershipFileIsStale {
135+
executable_name: self.executable_name.to_string(),
136+
}]
134137
} else {
135138
vec![]
136139
}
137140
}
138-
Err(_) => vec![Error::CodeownershipFileIsStale], // Treat any read error as stale file
141+
Err(_) => vec![Error::CodeownershipFileIsStale {
142+
executable_name: self.executable_name.to_string(),
143+
}],
139144
}
140145
}
141146

@@ -161,13 +166,13 @@ impl Validator {
161166
impl Error {
162167
pub fn category(&self) -> String {
163168
match self {
164-
Error::FileWithoutOwner { path: _ } => "Some files are missing ownership".to_owned(),
165-
Error::FileWithMultipleOwners { path: _, owners: _ } => "Code ownership should only be defined for each file in one way. The following files have declared ownership in multiple ways".to_owned(),
166-
Error::CodeownershipFileIsStale => {
167-
"CODEOWNERS out of date. Run `codeowners generate` to update the CODEOWNERS file".to_owned()
169+
Error::FileWithoutOwner { path: _ } => "Some files are missing ownership".to_owned(),
170+
Error::FileWithMultipleOwners { path: _, owners: _ } => "Code ownership should only be defined for each file in one way. The following files have declared ownership in multiple ways".to_owned(),
171+
Error::CodeownershipFileIsStale { executable_name } => {
172+
format!("CODEOWNERS out of date. Run `{} generate` to update the CODEOWNERS file", executable_name.to_string())
173+
}
174+
Error::InvalidTeam { name: _, path: _ } => "Found invalid team annotations".to_owned(),
168175
}
169-
Error::InvalidTeam { name: _, path: _ } => "Found invalid team annotations".to_owned(),
170-
}
171176
}
172177

173178
pub fn messages(&self) -> Vec<String> {
@@ -187,7 +192,7 @@ impl Error {
187192

188193
vec![messages.join("\n")]
189194
}
190-
Error::CodeownershipFileIsStale => vec![],
195+
Error::CodeownershipFileIsStale { executable_name: _ } => vec![],
191196
Error::InvalidTeam { name, path } => vec![format!("- {} is referencing an invalid team - '{}'", path.to_string_lossy(), name)],
192197
}
193198
}

src/project.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub struct Project {
1717
pub codeowners_file_path: PathBuf,
1818
pub directory_codeowner_files: Vec<DirectoryCodeownersFile>,
1919
pub teams_by_name: HashMap<String, Team>,
20+
pub executable_name: String,
2021
}
2122

2223
#[derive(Clone, Debug)]

src/project_builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ impl<'a> ProjectBuilder<'a> {
294294
codeowners_file_path: self.codeowners_file_path.to_path_buf(),
295295
directory_codeowner_files: directory_codeowners,
296296
teams_by_name,
297+
executable_name: self.config.executable_name.clone(),
297298
})
298299
}
299300
}

0 commit comments

Comments
 (0)