Skip to content

publish: Use homepage, documentation and repository fields from embedded Cargo.toml file #7201

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

Merged
merged 2 commits into from
Sep 28, 2023
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
20 changes: 11 additions & 9 deletions src/controllers/krate/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
let description = package.description.map(|it| it.as_local().unwrap());
let mut license = package.license.map(|it| it.as_local().unwrap());
let license_file = package.license_file.map(|it| it.as_local().unwrap());
let homepage = package.homepage.map(|it| it.as_local().unwrap());
let documentation = package.documentation.map(|it| it.as_local().unwrap());
let repository = package.repository.map(|it| it.as_local().unwrap());

// Make sure required fields are provided
fn empty(s: Option<&String>) -> bool {
Expand Down Expand Up @@ -150,13 +153,16 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
license = Some(String::from("non-standard"));
}

validate_url(homepage.as_deref(), "homepage")?;
validate_url(documentation.as_deref(), "documentation")?;
validate_url(repository.as_deref(), "repository")?;

// Create a transaction on the database, if there are no errors,
// commit the transactions to record a new or updated crate.
conn.transaction(|conn| {
let name = metadata.name;
let vers = &*metadata.vers;
let links = metadata.links;
let repo = metadata.repository;
let features = metadata
.features
.into_iter()
Expand All @@ -177,17 +183,13 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
let persist = NewCrate {
name: &name,
description: description.as_deref(),
homepage: metadata.homepage.as_deref(),
documentation: metadata.documentation.as_deref(),
homepage: homepage.as_deref(),
documentation: documentation.as_deref(),
readme: metadata.readme.as_deref(),
repository: repo.as_deref(),
repository: repository.as_deref(),
max_upload_size: None,
};

validate_url(persist.homepage, "homepage")?;
validate_url(persist.documentation, "documentation")?;
validate_url(persist.repository, "repository")?;

if is_reserved_name(persist.name, conn)? {
return Err(cargo_err("cannot upload a crate with a reserved name"));
}
Expand Down Expand Up @@ -271,7 +273,7 @@ pub async fn publish(app: AppState, req: BytesRequest) -> AppResult<Json<GoodCra
metadata
.readme_file
.unwrap_or_else(|| String::from("README.md")),
repo,
repository,
pkg_path_in_vcs,
)
.enqueue_with_priority(conn, PRIORITY_RENDER_README)?;
Expand Down
3 changes: 0 additions & 3 deletions src/tests/builders/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ impl PublishBuilder {
vers: u::EncodableCrateVersion(self.version.clone()),
features: self.features.clone(),
deps: self.deps.clone(),
homepage: None,
documentation: self.doc_url.clone(),
readme: self.readme,
readme_file: None,
keywords: u::EncodableKeywordList(
Expand All @@ -160,7 +158,6 @@ impl PublishBuilder {
.map(u::EncodableCategory)
.collect(),
),
repository: None,
links: None,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: response.into_json()
{
"errors": [
{
"detail": "invalid upload request: invalid length 6, expected at most 5 categories per crate at line 1 column 191"
"detail": "invalid upload request: invalid length 6, expected at most 5 categories per crate at line 1 column 154"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: response.into_json()
{
"errors": [
{
"detail": "invalid upload request: invalid value: string \"?@?%\", expected a valid keyword specifier at line 1 column 150"
"detail": "invalid upload request: invalid value: string \"?@?%\", expected a valid keyword specifier at line 1 column 113"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: response.into_json()
{
"errors": [
{
"detail": "invalid upload request: invalid value: string \"áccênts\", expected a valid keyword specifier at line 1 column 155"
"detail": "invalid upload request: invalid value: string \"áccênts\", expected a valid keyword specifier at line 1 column 118"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: response.into_json()
{
"errors": [
{
"detail": "invalid upload request: invalid length 29, expected a keyword with less than 20 characters at line 1 column 175"
"detail": "invalid upload request: invalid length 29, expected a keyword with less than 20 characters at line 1 column 138"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: response.into_json()
{
"errors": [
{
"detail": "invalid upload request: invalid length 6, expected at most 5 keywords per crate at line 1 column 175"
"detail": "invalid upload request: invalid length 6, expected at most 5 keywords per crate at line 1 column 138"
}
]
}
3 changes: 0 additions & 3 deletions src/views/krate_publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@ pub struct PublishMetadata {
pub vers: EncodableCrateVersion,
pub deps: Vec<EncodableCrateDependency>,
pub features: BTreeMap<EncodableFeatureName, Vec<EncodableFeature>>,
pub homepage: Option<String>,
pub documentation: Option<String>,
pub readme: Option<String>,
pub readme_file: Option<String>,
#[serde(default)]
pub keywords: EncodableKeywordList,
#[serde(default)]
pub categories: EncodableCategoryList,
pub repository: Option<String>,
#[serde(default)]
pub links: Option<String>,
}
Expand Down