Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding github team to for-file results #48

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/ownership.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ mod file_owner_finder;
pub(crate) mod mapper;
mod validator;

use crate::{ownership::mapper::DirectoryMapper, project::Project};
use crate::{
ownership::mapper::DirectoryMapper,
project::{Project, Team},
};

pub use validator::Errors as ValidatorErrors;

Expand All @@ -29,7 +32,7 @@ pub struct Ownership {
}

pub struct FileOwner {
pub team_name: TeamName,
pub team: Team,
pub team_config_file_path: String,
pub sources: Vec<Source>,
}
Expand Down Expand Up @@ -64,17 +67,21 @@ impl Display for FileOwner {

write!(
f,
"Team: {}\nTeam YML: {}\nDescription:\n- {}",
self.team_name, self.team_config_file_path, sources
"Team: {}\nGithub Team: {}\nTeam YML: {}\nDescription:\n- {}",
self.team.name, self.team.github_team, self.team_config_file_path, sources
)
}
}

impl Default for FileOwner {
fn default() -> Self {
Self {
team_name: "Unowned".to_string(),
team_config_file_path: "Unowned".to_string(),
team: Team {
name: "Unowned".to_string(),
github_team: "Unowned".to_string(),
..Default::default()
},
team_config_file_path: "".to_string(),
sources: vec![],
}
}
Expand Down Expand Up @@ -132,7 +139,7 @@ impl Ownership {
.sorted_by_key(|owner| owner.team_name.to_lowercase())
.map(|owner| match self.project.get_team(&owner.team_name) {
Some(team) => FileOwner {
team_name: owner.team_name.clone(),
team: team.clone(),
team_config_file_path: team
.path
.strip_prefix(&self.project.base_path)
Expand Down Expand Up @@ -220,7 +227,7 @@ mod tests {
let ownership = build_ownership_with_all_mappers()?;
let file_owners = ownership.for_file("app/consumers/directory_owned.rb").unwrap();
assert_eq!(file_owners.len(), 1);
assert_eq!(file_owners[0].team_name, "Bar");
assert_eq!(file_owners[0].team.name, "Bar");
assert_eq!(file_owners[0].team_config_file_path, "config/teams/bar.yml");
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct ProjectFile {
pub path: PathBuf,
}

#[derive(Clone, Debug)]
#[derive(Clone, Debug, Default)]
pub struct Team {
pub path: PathBuf,
pub name: String,
Expand Down
9 changes: 6 additions & 3 deletions tests/invalid_project_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ fn test_for_file() -> Result<(), Box<dyn Error>> {
.success()
.stdout(predicate::eq(indoc! {"
Team: Unowned
Team YML: Unowned
Github Team: Unowned
Team YML:
Description:
- Unowned
"}));
Expand All @@ -72,13 +73,15 @@ fn test_for_file_multiple_owners() -> Result<(), Box<dyn Error>> {
.success()
.stdout(predicate::eq(indoc! {"
Error: file is owned by multiple teams!

Team: Payments
Github Team: @PaymentTeam
Team YML: config/teams/payments.yml
Description:
- Owner annotation at the top of the file

Team: Payroll
Github Team: @PayrollTeam
Team YML: config/teams/payroll.yml
Description:
- Owner specified in `ruby/app/services/.codeowner`
Expand Down
3 changes: 3 additions & 0 deletions tests/valid_project_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ fn test_for_file() -> Result<(), Box<dyn Error>> {
.success()
.stdout(predicate::eq(indoc! {"
Team: Payroll
Github Team: @PayrollTeam
Team YML: config/teams/payroll.yml
Description:
- Owner annotation at the top of the file
Expand All @@ -67,6 +68,7 @@ fn test_for_file_same_team_multiple_ownerships() -> Result<(), Box<dyn Error>> {
.success()
.stdout(predicate::eq(indoc! {"
Team: Payroll
Github Team: @PayrollTeam
Team YML: config/teams/payroll.yml
Description:
- Owner annotation at the top of the file
Expand All @@ -87,6 +89,7 @@ fn test_for_file_with_2_ownerships() -> Result<(), Box<dyn Error>> {
.success()
.stdout(predicate::eq(indoc! {"
Team: Payroll
Github Team: @PayrollTeam
Team YML: config/teams/payroll.yml
Description:
- Owner annotation at the top of the file
Expand Down
Loading