Skip to content

Commit 9a118d8

Browse files
committed
use relative instead of absolute paths when displaying team mismatch error messages
1 parent d67c3bb commit 9a118d8

File tree

7 files changed

+41
-40
lines changed

7 files changed

+41
-40
lines changed

src/ownership.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::rc::Rc;
1+
use std::sync::Arc;
22
use tracing::{debug, instrument};
33

44
mod file_generator;
@@ -19,7 +19,7 @@ use self::{
1919
};
2020

2121
pub struct Ownership {
22-
project: Rc<Project>,
22+
project: Arc<Project>,
2323
}
2424

2525
pub struct Entry {
@@ -36,7 +36,9 @@ impl Entry {
3636

3737
impl Ownership {
3838
pub fn build(project: Project) -> Self {
39-
Self { project: Rc::new(project) }
39+
Self {
40+
project: Arc::new(project),
41+
}
4042
}
4143

4244
#[instrument(level = "debug", skip_all)]

src/ownership/mapper/package_mapper.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
use std::rc::Rc;
1+
use std::sync::Arc;
22

33
use super::Entry;
44
use super::{Mapper, OwnerMatcher};
55
use crate::project::{Package, PackageType, Project};
66
use itertools::Itertools;
77

88
pub struct RubyPackageMapper {
9-
project: Rc<Project>,
9+
project: Arc<Project>,
1010
}
1111

1212
pub struct JavascriptPackageMapper {
13-
project: Rc<Project>,
13+
project: Arc<Project>,
1414
}
1515

1616
struct PackageMapper {
17-
project: Rc<Project>,
17+
project: Arc<Project>,
1818
}
1919

2020
impl RubyPackageMapper {
21-
pub fn build(project: Rc<Project>) -> Self {
21+
pub fn build(project: Arc<Project>) -> Self {
2222
Self { project }
2323
}
2424
}
@@ -38,7 +38,7 @@ impl Mapper for RubyPackageMapper {
3838
}
3939

4040
impl JavascriptPackageMapper {
41-
pub fn build(project: Rc<Project>) -> Self {
41+
pub fn build(project: Arc<Project>) -> Self {
4242
Self { project }
4343
}
4444
}
@@ -58,7 +58,7 @@ impl Mapper for JavascriptPackageMapper {
5858
}
5959

6060
impl PackageMapper {
61-
pub fn build(project: Rc<Project>) -> Self {
61+
pub fn build(project: Arc<Project>) -> Self {
6262
Self { project }
6363
}
6464
}

src/ownership/mapper/team_file_mapper.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
use std::collections::HashMap;
22
use std::path::PathBuf;
3-
use std::rc::Rc;
3+
use std::sync::Arc;
44

55
use super::Entry;
66
use super::{Mapper, OwnerMatcher};
77
use crate::project::Project;
88

99
pub struct TeamFileMapper {
10-
project: Rc<Project>,
10+
project: Arc<Project>,
1111
}
1212

1313
impl TeamFileMapper {
14-
pub fn build(project: Rc<Project>) -> Self {
14+
pub fn build(project: Arc<Project>) -> Self {
1515
Self { project }
1616
}
1717
}

src/ownership/mapper/team_gem_mapper.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
use std::rc::Rc;
1+
use std::sync::Arc;
22

33
use super::Entry;
44
use super::{Mapper, OwnerMatcher};
55
use crate::project::Project;
66

77
pub struct TeamGemMapper {
8-
project: Rc<Project>,
8+
project: Arc<Project>,
99
}
1010

1111
impl TeamGemMapper {
12-
pub fn build(project: Rc<Project>) -> Self {
12+
pub fn build(project: Arc<Project>) -> Self {
1313
Self { project }
1414
}
1515
}

src/ownership/mapper/team_glob_mapper.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
use std::rc::Rc;
1+
use std::sync::Arc;
22

33
use super::Entry;
44
use super::{Mapper, OwnerMatcher};
55
use crate::project::Project;
66

77
pub struct TeamGlobMapper {
8-
project: Rc<Project>,
8+
project: Arc<Project>,
99
}
1010

1111
impl TeamGlobMapper {
12-
pub fn build(project: Rc<Project>) -> Self {
12+
pub fn build(project: Arc<Project>) -> Self {
1313
Self { project }
1414
}
1515
}

src/ownership/mapper/team_yml_mapper.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
use std::collections::HashMap;
22
use std::path::PathBuf;
3-
use std::rc::Rc;
3+
use std::sync::Arc;
44

55
use super::Entry;
66
use super::{Mapper, OwnerMatcher};
77
use crate::project::Project;
88

99
pub struct TeamYmlMapper {
10-
project: Rc<Project>,
10+
project: Arc<Project>,
1111
}
1212

1313
impl TeamYmlMapper {
14-
pub fn build(project: Rc<Project>) -> Self {
14+
pub fn build(project: Arc<Project>) -> Self {
1515
Self { project }
1616
}
1717
}

src/ownership/validator.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1+
use crate::project::{Project, ProjectFile};
12
use core::fmt;
23
use std::collections::HashMap;
34
use std::collections::HashSet;
45
use std::fmt::Display;
5-
use std::path::Path;
6-
76
use std::path::PathBuf;
8-
use std::rc::Rc;
9-
10-
use crate::project::{Project, ProjectFile};
7+
use std::sync::Arc;
118

129
use error_stack::Context;
1310
use itertools::Itertools;
@@ -20,7 +17,7 @@ use super::file_generator::FileGenerator;
2017
use super::mapper::{Mapper, OwnerMatcher};
2118

2219
pub struct Validator {
23-
pub project: Rc<Project>,
20+
pub project: Arc<Project>,
2421
pub mappers: Vec<Box<dyn Mapper>>,
2522
pub file_generator: FileGenerator,
2623
}
@@ -76,6 +73,8 @@ impl Validator {
7673
}
7774

7875
fn invalid_team_annotation(&self, team_names: &HashSet<&String>) -> Vec<Error> {
76+
let project = self.project.clone();
77+
7978
self.project
8079
.files
8180
.par_iter()
@@ -84,7 +83,7 @@ impl Validator {
8483
if !team_names.contains(owner) {
8584
return Some(Error::InvalidTeam {
8685
name: owner.clone(),
87-
path: file.path.clone(),
86+
path: project.relative_path(&file.path).to_owned(),
8887
});
8988
}
9089
}
@@ -102,7 +101,7 @@ impl Validator {
102101
if !team_names.contains(&package.owner) {
103102
Some(Error::InvalidTeam {
104103
name: package.owner.clone(),
105-
path: package.path.clone(),
104+
path: self.project.relative_path(&package.path).to_owned(),
106105
})
107106
} else {
108107
None
@@ -142,20 +141,20 @@ impl Validator {
142141

143142
fn file_to_owners(&self) -> Vec<(&ProjectFile, Vec<Owner>)> {
144143
let owner_matchers: Vec<OwnerMatcher> = self.mappers.iter().flat_map(|mapper| mapper.owner_matchers()).collect();
144+
let project = self.project.clone();
145145

146-
let files: Vec<(&ProjectFile, &Path)> = self
147-
.project
146+
self.project
148147
.files
149-
.iter()
150-
.filter(|file| !self.project.skip_file(file))
151-
.map(|file| (file, self.project.relative_path(&file.path)))
152-
.collect();
153-
154-
files
155148
.par_iter()
156-
.map(|(project_file, relative_path)| {
149+
.filter_map(|project_file| {
157150
let mut owners_and_source: HashMap<&String, Vec<String>> = HashMap::new();
158151

152+
if project.skip_file(project_file) {
153+
return None;
154+
}
155+
156+
let relative_path = project.relative_path(&project_file.path);
157+
159158
for owner_matcher in &owner_matchers {
160159
let owner = owner_matcher.owner_for(relative_path);
161160

@@ -174,7 +173,7 @@ impl Validator {
174173
})
175174
.collect_vec();
176175

177-
(*project_file, owners)
176+
Some((project_file, owners))
178177
})
179178
.collect()
180179
}

0 commit comments

Comments
 (0)