Skip to content
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

fix: remove list owners feature of info subcommand #14418

Merged
merged 1 commit into from
Aug 18, 2024
Merged
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
67 changes: 1 addition & 66 deletions src/cargo/ops/registry/info/mod.rs
Copy link
Member

Choose a reason for hiding this comment

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

So we cannot simply 'fix' it

Does this mean owner information may not be added back when cargo info hits stable? If it is the case, should we need a regression test ensuring this not happen again?

Copy link
Member Author

Choose a reason for hiding this comment

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

I will open a new issue to discuss this, as we need to consider including the download number in this PR. It may also be worth considering using a special API to fetch the owners list. However, we need to discuss this in the new issue.

When I say "fix it," I refer to not requiring authentication for this API. We cannot simply change that because, in our document, we state that it does require authentication. See owners list

Copy link
Member

Choose a reason for hiding this comment

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

I understood that. I was talking about the necessity of adding regression tests in this PR. If the feature requires more discussions and is not expected to be handled in a short term, maybe regression tests are worthy. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure what kind of regression tests you are referring to. Do you mean to check there is no owners output or check for no credential operation output?

Copy link
Member Author

Choose a reason for hiding this comment

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

If it is the latter one, I guess we can check it in the 'verbose' case.

Copy link
Member

@weihanglo weihanglo Aug 18, 2024

Choose a reason for hiding this comment

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

#14418 (review)

The command won't fail under the reproduction step described in #14409

Copy link
Member Author

@Rustin170506 Rustin170506 Aug 18, 2024

Choose a reason for hiding this comment

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

Oh, I understand now. I was mistaken(stupid). I forgot that we can use that case. 😆 I will add a regression test for it.

Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
//! Implementation of `cargo info`.

use anyhow::bail;
use cargo_credential::Operation;
use cargo_util_schemas::core::{PackageIdSpec, PartialVersion};
use crates_io::User;

use crate::core::registry::PackageRegistry;
use crate::core::{Dependency, Package, PackageId, PackageIdSpecQuery, Registry, Workspace};
Expand All @@ -12,7 +10,6 @@ use crate::ops::registry::{get_source_id_with_package_id, RegistryOrIndex, Regis
use crate::ops::resolve_ws;
use crate::sources::source::QueryKind;
use crate::sources::{IndexSummary, SourceConfigMap};
use crate::util::auth::AuthorizationErrorReason;
use crate::util::cache_lock::CacheLockMode;
use crate::util::command_prelude::root_manifest;
use crate::{CargoResult, GlobalContext};
Expand Down Expand Up @@ -79,19 +76,7 @@ pub fn info(

let package = registry.get(&[package_id])?;
let package = package.get_one(package_id)?;
let owners = try_list_owners(
gctx,
&source_ids,
reg_or_index.as_ref(),
package_id.name().as_str(),
)?;
pretty_view(
package,
&summaries,
&owners,
suggest_cargo_tree_command,
gctx,
)?;
pretty_view(package, &summaries, suggest_cargo_tree_command, gctx)?;

Ok(())
}
Expand Down Expand Up @@ -207,56 +192,6 @@ fn query_summaries(
}
}

// Try to list the login and name of all owners of a crate.
fn try_list_owners(
gctx: &GlobalContext,
source_ids: &RegistrySourceIds,
reg_or_index: Option<&RegistryOrIndex>,
package_name: &str,
) -> CargoResult<Option<Vec<String>>> {
// Only remote registries support listing owners.
if !source_ids.original.is_remote_registry() {
return Ok(None);
}
match super::registry(
gctx,
source_ids,
None,
reg_or_index,
false,
Some(Operation::Read),
) {
Ok(mut registry) => {
let owners = registry.list_owners(package_name)?;
let names = owners.iter().map(get_username).collect();
return Ok(Some(names));
}
Err(err) => {
// If the token is missing, it means the user is not logged in.
// We don't want to show an error in this case.
if err.to_string().contains(
(AuthorizationErrorReason::TokenMissing)
.to_string()
.as_str(),
) {
return Ok(None);
}
return Err(err);
}
}
}

fn get_username(u: &User) -> String {
format!(
"{}{}",
u.login,
u.name
.as_ref()
.map(|name| format!(" ({})", name))
.unwrap_or_default(),
)
}

fn validate_locked_and_frozen_options(
in_workspace: bool,
gctx: &GlobalContext,
Expand Down
18 changes: 0 additions & 18 deletions src/cargo/ops/registry/info/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use crate::{
pub(super) fn pretty_view(
package: &Package,
summaries: &[IndexSummary],
owners: &Option<Vec<String>>,
suggest_cargo_tree_command: bool,
gctx: &GlobalContext,
) -> CargoResult<()> {
Expand Down Expand Up @@ -153,10 +152,6 @@ pub(super) fn pretty_view(
gctx,
)?;

if let Some(owners) = owners {
pretty_owners(owners, stdout)?;
}

if suggest_cargo_tree_command {
suggest_cargo_tree(package_id, stdout)?;
}
Expand Down Expand Up @@ -399,19 +394,6 @@ fn pretty_features(
Ok(())
}

fn pretty_owners(owners: &Vec<String>, stdout: &mut dyn Write) -> CargoResult<()> {
let header = HEADER;

if !owners.is_empty() {
writeln!(stdout, "{header}owners:{header:#}",)?;
for owner in owners {
writeln!(stdout, " {}", owner)?;
}
}

Ok(())
}

// Suggest the cargo tree command to view the dependency tree.
fn suggest_cargo_tree(package_id: PackageId, stdout: &mut dyn Write) -> CargoResult<()> {
let literal = LITERAL;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 2 additions & 4 deletions tests/testsuite/cargo_info/verbose/stderr.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 2 additions & 4 deletions tests/testsuite/cargo_info/within_ws/stderr.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.