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

feat: set documentation_url to None when url starts with https://docs.rs #2657

Merged
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
5 changes: 5 additions & 0 deletions src/test/fakes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ impl<'a> FakeRelease<'a> {
self
}

pub(crate) fn documentation_url(mut self, documentation_url: Option<String>) -> Self {
self.package.documentation = documentation_url;
self
}

pub(crate) fn create(self) -> Result<i32> {
let runtime = self.runtime.clone();
runtime.block_on(self.create_async())
Expand Down
53 changes: 52 additions & 1 deletion src/web/crate_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@ impl CrateDetails {
.transpose()?,
};

// When documentation_url points to docs.rs itself, then we don't need to
// show it on the page because user is already on docs.rs website
let documentation_url = match krate.documentation_url {
Some(url) if url.starts_with("https://docs.rs/") => None,
Some(url) => Some(url),
None => None,
};

let mut crate_details = CrateDetails {
name: krate.name,
version: version.clone(),
Expand All @@ -241,9 +249,9 @@ impl CrateDetails {
releases: prefetched_releases,
repository_metadata,
metadata,
documentation_url,
is_library: krate.is_library,
license: krate.license,
documentation_url: krate.documentation_url,
documented_items: krate.documented_items,
total_items: krate.total_items,
total_items_needing_examples: krate.total_items_needing_examples,
Expand Down Expand Up @@ -892,6 +900,49 @@ mod tests {
Ok(())
}

#[test]
fn test_crate_details_documentation_url_is_none_when_url_is_docs_rs() {
async_wrapper(|env| async move {
let db = env.async_db().await;
let mut conn = db.async_conn().await;

env.async_fake_release()
.await
.name("foo")
.version("0.1.0")
.documentation_url(Some("https://foo.com".into()))
.create_async()
.await?;
env.async_fake_release()
.await
.name("foo")
.version("0.2.0")
.documentation_url(Some("https://docs.rs/foo/".into()))
.create_async()
.await?;
env.async_fake_release()
.await
.name("foo")
.version("0.3.0")
.documentation_url(None)
.create_async()
.await?;

let details_0_1 = crate_details(&mut conn, "foo", "0.1.0", None).await;
let details_0_2 = crate_details(&mut conn, "foo", "0.2.0", None).await;
let details_0_3 = crate_details(&mut conn, "foo", "0.3.0", None).await;

assert_eq!(
details_0_1.documentation_url,
Some("https://foo.com".into())
);
assert_eq!(details_0_2.documentation_url, None);
assert_eq!(details_0_3.documentation_url, None);

Ok(())
});
}

#[test]
fn test_last_successful_build_when_last_releases_failed_or_yanked() {
async_wrapper(|env| async move {
Expand Down
Loading