Factor out a function for building a NewCrate.

Co-Authored-By: Tor Hovland <55164+torhovland@users.noreply.github.com>
This commit is contained in:
Joe Neeman 2024-06-13 15:10:50 -05:00
parent 7f2079838a
commit 8771230eb8

View File

@ -321,14 +321,11 @@ fn verify_dependencies(
Ok(())
}
fn transmit(
pub(crate) fn prepare_transmit(
gctx: &GlobalContext,
pkg: &Package,
tarball: &File,
registry: &mut Registry,
registry_id: SourceId,
dry_run: bool,
) -> CargoResult<()> {
) -> CargoResult<NewCrate> {
let deps = pkg
.dependencies()
.iter()
@ -410,12 +407,6 @@ fn transmit(
}
}
// Do not upload if performing a dry run
if dry_run {
gctx.shell().warn("aborting upload due to dry run")?;
return Ok(());
}
let deps_set = deps
.iter()
.map(|dep| dep.name.clone())
@ -447,30 +438,46 @@ fn transmit(
None => BTreeMap::new(),
};
Ok(NewCrate {
name: pkg.name().to_string(),
vers: pkg.version().to_string(),
deps,
features: string_features,
authors: authors.clone(),
description: description.clone(),
homepage: homepage.clone(),
documentation: documentation.clone(),
keywords: keywords.clone(),
categories: categories.clone(),
readme: readme_content,
readme_file: readme.clone(),
repository: repository.clone(),
license: license.clone(),
license_file: license_file.clone(),
badges: badges.clone(),
links: links.clone(),
rust_version,
})
}
fn transmit(
gctx: &GlobalContext,
pkg: &Package,
tarball: &File,
registry: &mut Registry,
registry_id: SourceId,
dry_run: bool,
) -> CargoResult<()> {
let new_crate = prepare_transmit(gctx, pkg, registry_id)?;
// Do not upload if performing a dry run
if dry_run {
gctx.shell().warn("aborting upload due to dry run")?;
return Ok(());
}
let warnings = registry
.publish(
&NewCrate {
name: pkg.name().to_string(),
vers: pkg.version().to_string(),
deps,
features: string_features,
authors: authors.clone(),
description: description.clone(),
homepage: homepage.clone(),
documentation: documentation.clone(),
keywords: keywords.clone(),
categories: categories.clone(),
readme: readme_content,
readme_file: readme.clone(),
repository: repository.clone(),
license: license.clone(),
license_file: license_file.clone(),
badges: badges.clone(),
links: links.clone(),
rust_version,
},
tarball,
)
.publish(&new_crate, tarball)
.with_context(|| format!("failed to publish to registry at {}", registry.host()))?;
if !warnings.invalid_categories.is_empty() {