Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
Disable GitHub repo team settings
Browse files Browse the repository at this point in the history
  • Loading branch information
augustuswm committed Aug 16, 2024
1 parent c8b877b commit a0d1d17
Showing 1 changed file with 72 additions and 72 deletions.
144 changes: 72 additions & 72 deletions cio/src/repos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,78 +449,78 @@ impl GithubRepo {
}
}

// Get this repository's teams.
let mut ts: Vec<octorust::types::Team> = Default::default();
match github
.repos()
.list_all_teams(&company.github_org, &self.name)
.await
.map(|response| response.body)
{
Ok(v) => ts = v,
Err(e) => {
info!("Failed to get teams for repo {}. err: {:?}", self.name, e);

// If we get a 404 for teams then likely the repo is new, we can just move on and
// add the teams.
if !e.to_string().contains("404") && !e.to_string().contains("Not Found") {
bail!("could not list teams for repo {}: {}", self.name, e);
}
}
}
// Create the BTreeMap of teams.
let mut teams: BTreeMap<String, octorust::types::Team> = Default::default();
for t in ts {
teams.insert(t.name.to_string(), t);
}

// For each team id, add the team to the permissions.
for team_name in &default_teams {
let perms = octorust::types::TeamsAddUpdateRepoPermissionsInOrgRequestPermission::Push;

// Check if the team already has the permission.
if let Some(val) = teams.get(team_name) {
if val.permission == perms.to_string() || val.permission.to_lowercase() == *"admin" {
// Continue since they already have permission.
info!(
"team {} already has push access to {}/{}",
team_name, company.github_org, self.name
);

continue;
}
}

match github
.teams()
.add_or_update_repo_permissions_in_org(
&company.github_org,
team_name,
&company.github_org,
&self.name,
&octorust::types::TeamsAddUpdateRepoPermissionsInOrgRequest {
permission: Some(perms),
},
)
.await
{
Ok(_) => (),
Err(e) => {
info!("Failed to update repo permissions on {}. err: {:?}", self.name, e);
bail!(
"adding repo permission for team {} in repo {} failed: {}",
team_name,
self.name,
e
)
}
}

info!(
"gave team {} push access to {}/{}",
team_name, company.github_org, self.name
);
}
// // Get this repository's teams.
// let mut ts: Vec<octorust::types::Team> = Default::default();
// match github
// .repos()
// .list_all_teams(&company.github_org, &self.name)
// .await
// .map(|response| response.body)
// {
// Ok(v) => ts = v,
// Err(e) => {
// info!("Failed to get teams for repo {}. err: {:?}", self.name, e);

// // If we get a 404 for teams then likely the repo is new, we can just move on and
// // add the teams.
// if !e.to_string().contains("404") && !e.to_string().contains("Not Found") {
// bail!("could not list teams for repo {}: {}", self.name, e);
// }
// }
// }
// // Create the BTreeMap of teams.
// let mut teams: BTreeMap<String, octorust::types::Team> = Default::default();
// for t in ts {
// teams.insert(t.name.to_string(), t);
// }

// // For each team id, add the team to the permissions.
// for team_name in &default_teams {
// let perms = octorust::types::TeamsAddUpdateRepoPermissionsInOrgRequestPermission::Push;

// // Check if the team already has the permission.
// if let Some(val) = teams.get(team_name) {
// if val.permission == perms.to_string() || val.permission.to_lowercase() == *"admin" {
// // Continue since they already have permission.
// info!(
// "team {} already has push access to {}/{}",
// team_name, company.github_org, self.name
// );

// continue;
// }
// }

// match github
// .teams()
// .add_or_update_repo_permissions_in_org(
// &company.github_org,
// team_name,
// &company.github_org,
// &self.name,
// &octorust::types::TeamsAddUpdateRepoPermissionsInOrgRequest {
// permission: Some(perms),
// },
// )
// .await
// {
// Ok(_) => (),
// Err(e) => {
// info!("Failed to update repo permissions on {}. err: {:?}", self.name, e);
// bail!(
// "adding repo permission for team {} in repo {} failed: {}",
// team_name,
// self.name,
// e
// )
// }
// }

// info!(
// "gave team {} push access to {}/{}",
// team_name, company.github_org, self.name
// );
// }

Ok(())
}
Expand Down

0 comments on commit a0d1d17

Please sign in to comment.