diff --git a/src/db/add_package.rs b/src/db/add_package.rs index 940460e0a..5da6cafca 100644 --- a/src/db/add_package.rs +++ b/src/db/add_package.rs @@ -131,7 +131,6 @@ pub(crate) async fn add_package_into_database( &metadata_pkg.name, &metadata_pkg.version, &metadata_pkg.version, - None, ) .await .context("error when fetching crate-details")? diff --git a/src/repositories/updater.rs b/src/repositories/updater.rs index 728f9b9eb..4b41fbe1c 100644 --- a/src/repositories/updater.rs +++ b/src/repositories/updater.rs @@ -250,16 +250,6 @@ impl RepositoryStatsUpdater { Ok(()) } - pub fn get_icon_name(&self, host: &str) -> &'static str { - for updater in &self.updaters { - if updater.host() == host { - return updater.icon(); - } - } - // The default icon in case it doesn't match any of the "known" ones. - "code-branch" - } - async fn store_repository( &self, conn: &mut sqlx::PgConnection, @@ -346,7 +336,6 @@ pub struct RepositoryName<'a> { #[cfg(test)] mod test { use super::*; - use crate::context::Context; #[test] fn test_repository_name() { @@ -423,26 +412,4 @@ mod test { // Unknown host assert_name("https://git.sr.ht/~ireas/merge-rs", None); } - - #[test] - fn test_icon_name() { - crate::test::wrapper(|env| { - let mut config = env.base_config(); - config.github_accesstoken = Some("qsjdnfqdq".to_owned()); - let updater = RepositoryStatsUpdater::new(&config, env.pool()?); - - assert_eq!(updater.get_icon_name(""), "code-branch"); - assert_eq!(updater.get_icon_name("random"), "code-branch"); - assert_eq!(updater.get_icon_name("github"), "code-branch"); - assert_eq!(updater.get_icon_name("github.com"), "github"); - assert_eq!(updater.get_icon_name("gitlab"), "code-branch"); - assert_eq!(updater.get_icon_name("gitlab.com"), "gitlab"); - assert_eq!(updater.get_icon_name("gitlab.freedesktop.org"), "gitlab"); - assert_eq!( - updater.get_icon_name("a.gitlab.freedesktop.org"), - "code-branch" - ); - Ok(()) - }); - } } diff --git a/src/web/crate_details.rs b/src/web/crate_details.rs index 29c51b486..266d3544a 100644 --- a/src/web/crate_details.rs +++ b/src/web/crate_details.rs @@ -4,7 +4,6 @@ use crate::web::axum_cached_redirect; use crate::web::rustdoc::RustdocHtmlParams; use crate::{ impl_axum_webpage, - repositories::RepositoryStatsUpdater, storage::PathNotFoundError, web::{ cache::CachePolicy, @@ -74,7 +73,6 @@ struct RepositoryMetadata { forks: i32, issues: i32, name: Option, - icon: &'static str, } fn optional_markdown(markdown: &Option, serializer: S) -> Result @@ -104,7 +102,6 @@ impl CrateDetails { name: &str, version: &str, version_or_latest: &str, - up: Option<&RepositoryStatsUpdater>, ) -> Result, anyhow::Error> { let krate = match sqlx::query!( r#"SELECT @@ -168,12 +165,11 @@ impl CrateDetails { // get releases, sorted by semver let releases = releases_for_crate(conn, krate.crate_id).await?; - let repository_metadata = krate.repo_host.map(|host| RepositoryMetadata { + let repository_metadata = krate.repo_host.map(|_| RepositoryMetadata { issues: krate.repo_issues.unwrap(), stars: krate.repo_stars.unwrap(), forks: krate.repo_forks.unwrap(), name: krate.repo_name, - icon: up.map_or("code-branch", |u| u.get_icon_name(&host)), }); let metadata = MetaData { @@ -386,7 +382,6 @@ pub(crate) async fn crate_details_handler( Path(params): Path, Extension(storage): Extension>, mut conn: DbConnection, - Extension(repository_stats_updater): Extension>, ) -> AxumResult { // this handler must always called with a crate name if params.version.is_none() { @@ -413,15 +408,9 @@ pub(crate) async fn crate_details_handler( } }; - let mut details = CrateDetails::new( - &mut conn, - ¶ms.name, - &version, - &version_or_latest, - Some(&repository_stats_updater), - ) - .await? - .ok_or(AxumNope::VersionNotFound)?; + let mut details = CrateDetails::new(&mut conn, ¶ms.name, &version, &version_or_latest) + .await? + .ok_or(AxumNope::VersionNotFound)?; match details.fetch_readme(&storage).await { Ok(readme) => details.readme = readme.or(details.readme), @@ -712,7 +701,7 @@ mod tests { expected_last_successful_build: Option<&str>, ) -> Result<(), Error> { let mut conn = db.async_conn().await; - let details = CrateDetails::new(&mut conn, package, version, version, None) + let details = CrateDetails::new(&mut conn, package, version, version) .await .with_context(|| anyhow::anyhow!("could not fetch crate details"))? .unwrap(); @@ -880,7 +869,7 @@ mod tests { let details = env.runtime().block_on(async move { let mut conn = db.async_conn().await; - CrateDetails::new(&mut conn, "foo", "0.2.0", "0.2.0", None) + CrateDetails::new(&mut conn, "foo", "0.2.0", "0.2.0") .await .unwrap() .unwrap() @@ -1001,7 +990,7 @@ mod tests { for version in &["0.0.1", "0.0.2", "0.0.3"] { let details = env.runtime().block_on(async move { let mut conn = db.async_conn().await; - CrateDetails::new(&mut conn, "foo", version, version, None) + CrateDetails::new(&mut conn, "foo", version, version) .await .unwrap() .unwrap() @@ -1031,7 +1020,7 @@ mod tests { for version in &["0.0.1", "0.0.2", "0.0.3-pre.1"] { let details = env.runtime().block_on(async move { let mut conn = db.async_conn().await; - CrateDetails::new(&mut conn, "foo", version, version, None) + CrateDetails::new(&mut conn, "foo", version, version) .await .unwrap() .unwrap() @@ -1062,7 +1051,7 @@ mod tests { for version in &["0.0.1", "0.0.2", "0.0.3"] { let details = env.runtime().block_on(async move { let mut conn = db.async_conn().await; - CrateDetails::new(&mut conn, "foo", version, version, None) + CrateDetails::new(&mut conn, "foo", version, version) .await .unwrap() .unwrap() @@ -1101,7 +1090,7 @@ mod tests { for version in &["0.0.1", "0.0.2", "0.0.3"] { let details = env.runtime().block_on(async move { let mut conn = db.async_conn().await; - CrateDetails::new(&mut conn, "foo", version, version, None) + CrateDetails::new(&mut conn, "foo", version, version) .await .unwrap() .unwrap() @@ -1161,7 +1150,7 @@ mod tests { let details = env.runtime().block_on(async move { let mut conn = db.async_conn().await; - CrateDetails::new(&mut conn, "foo", "0.0.1", "0.0.1", None) + CrateDetails::new(&mut conn, "foo", "0.0.1", "0.0.1") .await .unwrap() .unwrap() @@ -1187,7 +1176,7 @@ mod tests { let details = env.runtime().block_on(async move { let mut conn = db.async_conn().await; - CrateDetails::new(&mut conn, "foo", "0.0.1", "0.0.1", None) + CrateDetails::new(&mut conn, "foo", "0.0.1", "0.0.1") .await .unwrap() .unwrap() @@ -1214,7 +1203,7 @@ mod tests { let details = env.runtime().block_on(async move { let mut conn = db.async_conn().await; - CrateDetails::new(&mut conn, "foo", "0.0.1", "0.0.1", None) + CrateDetails::new(&mut conn, "foo", "0.0.1", "0.0.1") .await .unwrap() .unwrap() @@ -1236,7 +1225,7 @@ mod tests { let details = env.runtime().block_on(async move { let mut conn = db.async_conn().await; - CrateDetails::new(&mut conn, "foo", "0.0.1", "0.0.1", None) + CrateDetails::new(&mut conn, "foo", "0.0.1", "0.0.1") .await .unwrap() .unwrap() @@ -1625,7 +1614,7 @@ mod tests { let details = env.runtime().block_on(async move { let mut conn = env.async_db().await.async_conn().await; - CrateDetails::new(&mut conn, "dummy", "0.5.0", "0.5.0", None) + CrateDetails::new(&mut conn, "dummy", "0.5.0", "0.5.0") .await .unwrap() .unwrap() diff --git a/src/web/mod.rs b/src/web/mod.rs index c0605cc53..86c099a52 100644 --- a/src/web/mod.rs +++ b/src/web/mod.rs @@ -273,7 +273,6 @@ fn apply_middleware( .layer(Extension(context.config()?)) .layer(Extension(context.storage()?)) .layer(Extension(async_storage)) - .layer(Extension(context.repository_stats_updater()?)) .layer(option_layer(template_data.map(Extension))) .layer(middleware::from_fn(csp::csp_middleware)) .layer(option_layer(has_templates.then_some(middleware::from_fn( diff --git a/src/web/rustdoc.rs b/src/web/rustdoc.rs index 17e903690..6d7e7d8da 100644 --- a/src/web/rustdoc.rs +++ b/src/web/rustdoc.rs @@ -2,7 +2,6 @@ use crate::{ db::Pool, - repositories::RepositoryStatsUpdater, storage::rustdoc_archive_path, utils, web::{ @@ -175,7 +174,7 @@ pub(crate) async fn rustdoc_redirector_handler( if target.ends_with(".js") { // this URL is actually from a crate-internal path, serve it there instead rendering_time.step("serve JS for crate"); - let krate = CrateDetails::new(&mut conn, &crate_name, &version, &version, None) + let krate = CrateDetails::new(&mut conn, &crate_name, &version, &version) .await? .ok_or(AxumNope::ResourceNotFound)?; @@ -362,7 +361,6 @@ pub(crate) async fn rustdoc_html_server_handler( Extension(storage): Extension>, Extension(config): Extension>, Extension(csp): Extension>, - Extension(updater): Extension>, uri: Uri, ) -> AxumResult { let mut rendering_time = RenderingTimesRecorder::new(&metrics.rustdoc_rendering_times); @@ -444,15 +442,9 @@ pub(crate) async fn rustdoc_html_server_handler( // Get the crate's details from the database // NOTE: we know this crate must exist because we just checked it above (or else `match_version` is buggy) - let krate = CrateDetails::new( - &mut conn, - ¶ms.name, - &version, - &version_or_latest, - Some(&updater), - ) - .await? - .ok_or(AxumNope::ResourceNotFound)?; + let krate = CrateDetails::new(&mut conn, ¶ms.name, &version, &version_or_latest) + .await? + .ok_or(AxumNope::ResourceNotFound)?; if !krate.rustdoc_status { rendering_time.step("redirect to crate"); @@ -748,7 +740,6 @@ pub(crate) async fn target_redirect_handler( Path((name, version, req_path)): Path<(String, String, String)>, mut conn: DbConnection, Extension(storage): Extension>, - Extension(updater): Extension>, ) -> AxumResult { let release_found = match_version(&mut conn, &name, Some(&version)).await?; let (version, version_or_latest, is_latest_url) = match release_found.version { @@ -758,15 +749,9 @@ pub(crate) async fn target_redirect_handler( MatchSemver::Semver(_) => return Err(AxumNope::VersionNotFound), }; - let crate_details = CrateDetails::new( - &mut conn, - &name, - &version, - &version_or_latest, - Some(&updater), - ) - .await? - .ok_or(AxumNope::VersionNotFound)?; + let crate_details = CrateDetails::new(&mut conn, &name, &version, &version_or_latest) + .await? + .ok_or(AxumNope::VersionNotFound)?; // We're trying to find the storage location // for the requested path in the target-redirect. diff --git a/templates/crate/details.html b/templates/crate/details.html index e23a0d08a..2046f11d8 100644 --- a/templates/crate/details.html +++ b/templates/crate/details.html @@ -69,7 +69,7 @@ {# If the repo link is for github or gitlab, show some stats #} {# TODO: add support for hosts besides github and gitlab (#35) #} {%- if details.repository_metadata -%} - {{ details.repository_metadata.icon | fab }} + {{ "code-branch" | fab }} {% if details.repository_metadata.name %} {{details.repository_metadata.name}} {% else %}