Remove individual devs from crate ownership in crates.io (#1396)

This commit is contained in:
John DiSanti 2022-05-18 16:26:30 -07:00 committed by GitHub
parent 5881feaf8f
commit 2cd82cb862
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 91 additions and 0 deletions

View File

@ -8,11 +8,13 @@
mod add_owner;
mod get_owners;
mod publish;
mod remove_owner;
mod yank;
pub use add_owner::AddOwner;
pub use get_owners::GetOwners;
pub use publish::Publish;
pub use remove_owner::RemoveOwner;
pub use yank::Yank;
use anyhow::{Context, Result};

View File

@ -0,0 +1,78 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
use anyhow::Result;
use smithy_rs_tool_common::shell::{handle_failure, ShellOperation};
use std::process::Command;
pub struct RemoveOwner {
program: &'static str,
package_name: String,
owner: String,
}
impl RemoveOwner {
pub fn new(package_name: impl Into<String>, owner: impl Into<String>) -> RemoveOwner {
RemoveOwner {
program: "cargo",
package_name: package_name.into(),
owner: owner.into(),
}
}
}
impl ShellOperation for RemoveOwner {
type Output = ();
fn run(&self) -> Result<()> {
let mut command = Command::new(self.program);
command
.arg("owner")
.arg("--remove")
.arg(&self.owner)
.arg(&self.package_name);
let output = command.output()?;
handle_failure("remove owner", &output)?;
Ok(())
}
}
#[cfg(all(test, not(target_os = "windows")))]
mod tests {
use super::*;
use smithy_rs_tool_common::shell::ShellOperation;
#[tokio::test]
async fn remove_owner_success() {
RemoveOwner {
program: "./fake_cargo/cargo_success",
package_name: "aws-sdk-s3".into(),
owner: "incorrect_owner".into(),
}
.spawn()
.await
.unwrap();
}
#[tokio::test]
async fn remove_owner_failed() {
let result = RemoveOwner {
program: "./fake_cargo/cargo_fails",
package_name: "aws-sdk-s3".into(),
owner: "incorrect_owner".into(),
}
.spawn()
.await;
assert!(result.is_err(), "expected error, got {:?}", result);
assert_eq!(
"Failed to remove owner:\n\
Status: 1\n\
Stdout: some stdout failure message\n\n\
Stderr: some stderr failure message\n\n",
format!("{}", result.err().unwrap())
);
}
}

View File

@ -177,6 +177,17 @@ async fn correct_owner(package: &Package) -> Result<()> {
Duration::from_secs(5),
|| async {
let owners = cargo::GetOwners::new(&package.handle.name).spawn().await?;
let incorrect_owners = owners.iter().filter(|&owner| owner != CRATE_OWNER);
for incorrect_owner in incorrect_owners {
cargo::RemoveOwner::new(&package.handle.name, incorrect_owner)
.spawn()
.await
.context("remove incorrect owner")?;
info!(
"Removed incorrect owner `{}` from crate `{}`",
incorrect_owner, package.handle
);
}
if !owners.iter().any(|owner| owner == CRATE_OWNER) {
cargo::AddOwner::new(&package.handle.name, CRATE_OWNER)
.spawn()