Skip to content

improve repo validation error message #1764

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@ impl Data {
}
result
}

pub(crate) fn is_team_archived(&self, team_name: &str, org: &str) -> bool {
self.archived_teams()
.filter_map(|team| team.github_teams(self).ok())
.flatten()
.any(|github_team| github_team.name == team_name && github_team.org == org)
}
}

fn load_file<T: DeserializeOwned>(path: &Path) -> Result<T, Error> {
Expand Down
19 changes: 12 additions & 7 deletions src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,20 +868,25 @@ fn validate_repos(data: &Data, errors: &mut Vec<String>) {
}
for team_name in repo.access.teams.keys() {
if !github_teams.contains(&(repo.org.clone(), team_name.clone())) {
let error_reason = if data.is_team_archived(team_name, &repo.org) {
"is archived. Please remove the team access from the `[access.teams]` section of the repo"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if something like this wouldn't be even easier to understand. Might require a change to the data model, though, to deserialize a repository without the access.teams field set. 🤔

Suggested change
"is archived. Please remove the team access from the `[access.teams]` section of the repo"
"is archived. Please remove the `[access.teams]` section in the repo's toml"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change sounds more like #1754
Why should we suggest removing the entire [access.teams] section of the repo here?
That particular team is archived, but not the repo.

} else {
"is not present in the `/teams/` folder"
};

bail!(
"access for {}/{} is invalid: '{}' is not configured as a GitHub team for the '{}' org",
repo.org,
repo.name,
team_name,
repo.org
)
"Access for the repo {}/{} is invalid: the team '{}/{team_name}' {error_reason}.",
repo.org,
repo.name,
repo.org,
);
}
}

for name in repo.access.individuals.keys() {
if data.person(name).is_none() {
bail!(
"access for {}/{} is invalid: '{}' is not the name of a person in the team repo",
"Access for the repo {}/{} is invalid: '{}' is not the name of a person in the team repo",
repo.org,
repo.name,
name
Expand Down