Skip to content

Commit 3b05bc1

Browse files
authored
adding github team to for-file results (#48)
1 parent daacced commit 3b05bc1

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

src/ownership.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ mod file_owner_finder;
1414
pub(crate) mod mapper;
1515
mod validator;
1616

17-
use crate::{ownership::mapper::DirectoryMapper, project::Project};
17+
use crate::{
18+
ownership::mapper::DirectoryMapper,
19+
project::{Project, Team},
20+
};
1821

1922
pub use validator::Errors as ValidatorErrors;
2023

@@ -29,7 +32,7 @@ pub struct Ownership {
2932
}
3033

3134
pub struct FileOwner {
32-
pub team_name: TeamName,
35+
pub team: Team,
3336
pub team_config_file_path: String,
3437
pub sources: Vec<Source>,
3538
}
@@ -64,17 +67,21 @@ impl Display for FileOwner {
6467

6568
write!(
6669
f,
67-
"Team: {}\nTeam YML: {}\nDescription:\n- {}",
68-
self.team_name, self.team_config_file_path, sources
70+
"Team: {}\nGithub Team: {}\nTeam YML: {}\nDescription:\n- {}",
71+
self.team.name, self.team.github_team, self.team_config_file_path, sources
6972
)
7073
}
7174
}
7275

7376
impl Default for FileOwner {
7477
fn default() -> Self {
7578
Self {
76-
team_name: "Unowned".to_string(),
77-
team_config_file_path: "Unowned".to_string(),
79+
team: Team {
80+
name: "Unowned".to_string(),
81+
github_team: "Unowned".to_string(),
82+
..Default::default()
83+
},
84+
team_config_file_path: "".to_string(),
7885
sources: vec![],
7986
}
8087
}
@@ -132,7 +139,7 @@ impl Ownership {
132139
.sorted_by_key(|owner| owner.team_name.to_lowercase())
133140
.map(|owner| match self.project.get_team(&owner.team_name) {
134141
Some(team) => FileOwner {
135-
team_name: owner.team_name.clone(),
142+
team: team.clone(),
136143
team_config_file_path: team
137144
.path
138145
.strip_prefix(&self.project.base_path)
@@ -220,7 +227,7 @@ mod tests {
220227
let ownership = build_ownership_with_all_mappers()?;
221228
let file_owners = ownership.for_file("app/consumers/directory_owned.rb").unwrap();
222229
assert_eq!(file_owners.len(), 1);
223-
assert_eq!(file_owners[0].team_name, "Bar");
230+
assert_eq!(file_owners[0].team.name, "Bar");
224231
assert_eq!(file_owners[0].team_config_file_path, "config/teams/bar.yml");
225232
Ok(())
226233
}

src/project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub struct ProjectFile {
2929
pub path: PathBuf,
3030
}
3131

32-
#[derive(Clone, Debug)]
32+
#[derive(Clone, Debug, Default)]
3333
pub struct Team {
3434
pub path: PathBuf,
3535
pub name: String,

tests/invalid_project_test.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ fn test_for_file() -> Result<(), Box<dyn Error>> {
5353
.success()
5454
.stdout(predicate::eq(indoc! {"
5555
Team: Unowned
56-
Team YML: Unowned
56+
Github Team: Unowned
57+
Team YML:
5758
Description:
5859
- Unowned
5960
"}));
@@ -72,13 +73,15 @@ fn test_for_file_multiple_owners() -> Result<(), Box<dyn Error>> {
7273
.success()
7374
.stdout(predicate::eq(indoc! {"
7475
Error: file is owned by multiple teams!
75-
76+
7677
Team: Payments
78+
Github Team: @PaymentTeam
7779
Team YML: config/teams/payments.yml
7880
Description:
7981
- Owner annotation at the top of the file
80-
82+
8183
Team: Payroll
84+
Github Team: @PayrollTeam
8285
Team YML: config/teams/payroll.yml
8386
Description:
8487
- Owner specified in `ruby/app/services/.codeowner`

tests/valid_project_test.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ fn test_for_file() -> Result<(), Box<dyn Error>> {
4848
.success()
4949
.stdout(predicate::eq(indoc! {"
5050
Team: Payroll
51+
Github Team: @PayrollTeam
5152
Team YML: config/teams/payroll.yml
5253
Description:
5354
- Owner annotation at the top of the file
@@ -67,6 +68,7 @@ fn test_for_file_same_team_multiple_ownerships() -> Result<(), Box<dyn Error>> {
6768
.success()
6869
.stdout(predicate::eq(indoc! {"
6970
Team: Payroll
71+
Github Team: @PayrollTeam
7072
Team YML: config/teams/payroll.yml
7173
Description:
7274
- Owner annotation at the top of the file
@@ -87,6 +89,7 @@ fn test_for_file_with_2_ownerships() -> Result<(), Box<dyn Error>> {
8789
.success()
8890
.stdout(predicate::eq(indoc! {"
8991
Team: Payroll
92+
Github Team: @PayrollTeam
9093
Team YML: config/teams/payroll.yml
9194
Description:
9295
- Owner annotation at the top of the file

0 commit comments

Comments
 (0)