Skip to content

Commit 7ef5327

Browse files
committed
remove provider specific repository icons
1 parent 37c4548 commit 7ef5327

File tree

6 files changed

+23
-84
lines changed

6 files changed

+23
-84
lines changed

src/db/add_package.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ pub(crate) async fn add_package_into_database(
131131
&metadata_pkg.name,
132132
&metadata_pkg.version,
133133
&metadata_pkg.version,
134-
None,
135134
)
136135
.await
137136
.context("error when fetching crate-details")?

src/repositories/updater.rs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -250,16 +250,6 @@ impl RepositoryStatsUpdater {
250250
Ok(())
251251
}
252252

253-
pub fn get_icon_name(&self, host: &str) -> &'static str {
254-
for updater in &self.updaters {
255-
if updater.host() == host {
256-
return updater.icon();
257-
}
258-
}
259-
// The default icon in case it doesn't match any of the "known" ones.
260-
"code-branch"
261-
}
262-
263253
async fn store_repository(
264254
&self,
265255
conn: &mut sqlx::PgConnection,
@@ -346,7 +336,6 @@ pub struct RepositoryName<'a> {
346336
#[cfg(test)]
347337
mod test {
348338
use super::*;
349-
use crate::context::Context;
350339

351340
#[test]
352341
fn test_repository_name() {
@@ -423,26 +412,4 @@ mod test {
423412
// Unknown host
424413
assert_name("https://git.sr.ht/~ireas/merge-rs", None);
425414
}
426-
427-
#[test]
428-
fn test_icon_name() {
429-
crate::test::wrapper(|env| {
430-
let mut config = env.base_config();
431-
config.github_accesstoken = Some("qsjdnfqdq".to_owned());
432-
let updater = RepositoryStatsUpdater::new(&config, env.pool()?);
433-
434-
assert_eq!(updater.get_icon_name(""), "code-branch");
435-
assert_eq!(updater.get_icon_name("random"), "code-branch");
436-
assert_eq!(updater.get_icon_name("github"), "code-branch");
437-
assert_eq!(updater.get_icon_name("github.com"), "github");
438-
assert_eq!(updater.get_icon_name("gitlab"), "code-branch");
439-
assert_eq!(updater.get_icon_name("gitlab.com"), "gitlab");
440-
assert_eq!(updater.get_icon_name("gitlab.freedesktop.org"), "gitlab");
441-
assert_eq!(
442-
updater.get_icon_name("a.gitlab.freedesktop.org"),
443-
"code-branch"
444-
);
445-
Ok(())
446-
});
447-
}
448415
}

src/web/crate_details.rs

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::web::axum_cached_redirect;
44
use crate::web::rustdoc::RustdocHtmlParams;
55
use crate::{
66
impl_axum_webpage,
7-
repositories::RepositoryStatsUpdater,
87
storage::PathNotFoundError,
98
web::{
109
cache::CachePolicy,
@@ -74,7 +73,6 @@ struct RepositoryMetadata {
7473
forks: i32,
7574
issues: i32,
7675
name: Option<String>,
77-
icon: &'static str,
7876
}
7977

8078
fn optional_markdown<S>(markdown: &Option<String>, serializer: S) -> Result<S::Ok, S::Error>
@@ -104,7 +102,6 @@ impl CrateDetails {
104102
name: &str,
105103
version: &str,
106104
version_or_latest: &str,
107-
up: Option<&RepositoryStatsUpdater>,
108105
) -> Result<Option<CrateDetails>, anyhow::Error> {
109106
let krate = match sqlx::query!(
110107
r#"SELECT
@@ -168,12 +165,11 @@ impl CrateDetails {
168165
// get releases, sorted by semver
169166
let releases = releases_for_crate(conn, krate.crate_id).await?;
170167

171-
let repository_metadata = krate.repo_host.map(|host| RepositoryMetadata {
168+
let repository_metadata = krate.repo_host.map(|_| RepositoryMetadata {
172169
issues: krate.repo_issues.unwrap(),
173170
stars: krate.repo_stars.unwrap(),
174171
forks: krate.repo_forks.unwrap(),
175172
name: krate.repo_name,
176-
icon: up.map_or("code-branch", |u| u.get_icon_name(&host)),
177173
});
178174

179175
let metadata = MetaData {
@@ -386,7 +382,6 @@ pub(crate) async fn crate_details_handler(
386382
Path(params): Path<CrateDetailHandlerParams>,
387383
Extension(storage): Extension<Arc<AsyncStorage>>,
388384
mut conn: DbConnection,
389-
Extension(repository_stats_updater): Extension<Arc<RepositoryStatsUpdater>>,
390385
) -> AxumResult<AxumResponse> {
391386
// this handler must always called with a crate name
392387
if params.version.is_none() {
@@ -413,15 +408,9 @@ pub(crate) async fn crate_details_handler(
413408
}
414409
};
415410

416-
let mut details = CrateDetails::new(
417-
&mut conn,
418-
&params.name,
419-
&version,
420-
&version_or_latest,
421-
Some(&repository_stats_updater),
422-
)
423-
.await?
424-
.ok_or(AxumNope::VersionNotFound)?;
411+
let mut details = CrateDetails::new(&mut conn, &params.name, &version, &version_or_latest)
412+
.await?
413+
.ok_or(AxumNope::VersionNotFound)?;
425414

426415
match details.fetch_readme(&storage).await {
427416
Ok(readme) => details.readme = readme.or(details.readme),
@@ -712,7 +701,7 @@ mod tests {
712701
expected_last_successful_build: Option<&str>,
713702
) -> Result<(), Error> {
714703
let mut conn = db.async_conn().await;
715-
let details = CrateDetails::new(&mut conn, package, version, version, None)
704+
let details = CrateDetails::new(&mut conn, package, version, version)
716705
.await
717706
.with_context(|| anyhow::anyhow!("could not fetch crate details"))?
718707
.unwrap();
@@ -880,7 +869,7 @@ mod tests {
880869

881870
let details = env.runtime().block_on(async move {
882871
let mut conn = db.async_conn().await;
883-
CrateDetails::new(&mut conn, "foo", "0.2.0", "0.2.0", None)
872+
CrateDetails::new(&mut conn, "foo", "0.2.0", "0.2.0")
884873
.await
885874
.unwrap()
886875
.unwrap()
@@ -1001,7 +990,7 @@ mod tests {
1001990
for version in &["0.0.1", "0.0.2", "0.0.3"] {
1002991
let details = env.runtime().block_on(async move {
1003992
let mut conn = db.async_conn().await;
1004-
CrateDetails::new(&mut conn, "foo", version, version, None)
993+
CrateDetails::new(&mut conn, "foo", version, version)
1005994
.await
1006995
.unwrap()
1007996
.unwrap()
@@ -1031,7 +1020,7 @@ mod tests {
10311020
for version in &["0.0.1", "0.0.2", "0.0.3-pre.1"] {
10321021
let details = env.runtime().block_on(async move {
10331022
let mut conn = db.async_conn().await;
1034-
CrateDetails::new(&mut conn, "foo", version, version, None)
1023+
CrateDetails::new(&mut conn, "foo", version, version)
10351024
.await
10361025
.unwrap()
10371026
.unwrap()
@@ -1062,7 +1051,7 @@ mod tests {
10621051
for version in &["0.0.1", "0.0.2", "0.0.3"] {
10631052
let details = env.runtime().block_on(async move {
10641053
let mut conn = db.async_conn().await;
1065-
CrateDetails::new(&mut conn, "foo", version, version, None)
1054+
CrateDetails::new(&mut conn, "foo", version, version)
10661055
.await
10671056
.unwrap()
10681057
.unwrap()
@@ -1101,7 +1090,7 @@ mod tests {
11011090
for version in &["0.0.1", "0.0.2", "0.0.3"] {
11021091
let details = env.runtime().block_on(async move {
11031092
let mut conn = db.async_conn().await;
1104-
CrateDetails::new(&mut conn, "foo", version, version, None)
1093+
CrateDetails::new(&mut conn, "foo", version, version)
11051094
.await
11061095
.unwrap()
11071096
.unwrap()
@@ -1161,7 +1150,7 @@ mod tests {
11611150

11621151
let details = env.runtime().block_on(async move {
11631152
let mut conn = db.async_conn().await;
1164-
CrateDetails::new(&mut conn, "foo", "0.0.1", "0.0.1", None)
1153+
CrateDetails::new(&mut conn, "foo", "0.0.1", "0.0.1")
11651154
.await
11661155
.unwrap()
11671156
.unwrap()
@@ -1187,7 +1176,7 @@ mod tests {
11871176

11881177
let details = env.runtime().block_on(async move {
11891178
let mut conn = db.async_conn().await;
1190-
CrateDetails::new(&mut conn, "foo", "0.0.1", "0.0.1", None)
1179+
CrateDetails::new(&mut conn, "foo", "0.0.1", "0.0.1")
11911180
.await
11921181
.unwrap()
11931182
.unwrap()
@@ -1214,7 +1203,7 @@ mod tests {
12141203

12151204
let details = env.runtime().block_on(async move {
12161205
let mut conn = db.async_conn().await;
1217-
CrateDetails::new(&mut conn, "foo", "0.0.1", "0.0.1", None)
1206+
CrateDetails::new(&mut conn, "foo", "0.0.1", "0.0.1")
12181207
.await
12191208
.unwrap()
12201209
.unwrap()
@@ -1236,7 +1225,7 @@ mod tests {
12361225

12371226
let details = env.runtime().block_on(async move {
12381227
let mut conn = db.async_conn().await;
1239-
CrateDetails::new(&mut conn, "foo", "0.0.1", "0.0.1", None)
1228+
CrateDetails::new(&mut conn, "foo", "0.0.1", "0.0.1")
12401229
.await
12411230
.unwrap()
12421231
.unwrap()
@@ -1625,7 +1614,7 @@ mod tests {
16251614

16261615
let details = env.runtime().block_on(async move {
16271616
let mut conn = env.async_db().await.async_conn().await;
1628-
CrateDetails::new(&mut conn, "dummy", "0.5.0", "0.5.0", None)
1617+
CrateDetails::new(&mut conn, "dummy", "0.5.0", "0.5.0")
16291618
.await
16301619
.unwrap()
16311620
.unwrap()

src/web/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ fn apply_middleware(
273273
.layer(Extension(context.config()?))
274274
.layer(Extension(context.storage()?))
275275
.layer(Extension(async_storage))
276-
.layer(Extension(context.repository_stats_updater()?))
277276
.layer(option_layer(template_data.map(Extension)))
278277
.layer(middleware::from_fn(csp::csp_middleware))
279278
.layer(option_layer(has_templates.then_some(middleware::from_fn(

src/web/rustdoc.rs

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
use crate::{
44
db::Pool,
5-
repositories::RepositoryStatsUpdater,
65
storage::rustdoc_archive_path,
76
utils,
87
web::{
@@ -175,7 +174,7 @@ pub(crate) async fn rustdoc_redirector_handler(
175174
if target.ends_with(".js") {
176175
// this URL is actually from a crate-internal path, serve it there instead
177176
rendering_time.step("serve JS for crate");
178-
let krate = CrateDetails::new(&mut conn, &crate_name, &version, &version, None)
177+
let krate = CrateDetails::new(&mut conn, &crate_name, &version, &version)
179178
.await?
180179
.ok_or(AxumNope::ResourceNotFound)?;
181180

@@ -362,7 +361,6 @@ pub(crate) async fn rustdoc_html_server_handler(
362361
Extension(storage): Extension<Arc<AsyncStorage>>,
363362
Extension(config): Extension<Arc<Config>>,
364363
Extension(csp): Extension<Arc<Csp>>,
365-
Extension(updater): Extension<Arc<RepositoryStatsUpdater>>,
366364
uri: Uri,
367365
) -> AxumResult<AxumResponse> {
368366
let mut rendering_time = RenderingTimesRecorder::new(&metrics.rustdoc_rendering_times);
@@ -444,15 +442,9 @@ pub(crate) async fn rustdoc_html_server_handler(
444442

445443
// Get the crate's details from the database
446444
// NOTE: we know this crate must exist because we just checked it above (or else `match_version` is buggy)
447-
let krate = CrateDetails::new(
448-
&mut conn,
449-
&params.name,
450-
&version,
451-
&version_or_latest,
452-
Some(&updater),
453-
)
454-
.await?
455-
.ok_or(AxumNope::ResourceNotFound)?;
445+
let krate = CrateDetails::new(&mut conn, &params.name, &version, &version_or_latest)
446+
.await?
447+
.ok_or(AxumNope::ResourceNotFound)?;
456448

457449
if !krate.rustdoc_status {
458450
rendering_time.step("redirect to crate");
@@ -748,7 +740,6 @@ pub(crate) async fn target_redirect_handler(
748740
Path((name, version, req_path)): Path<(String, String, String)>,
749741
mut conn: DbConnection,
750742
Extension(storage): Extension<Arc<AsyncStorage>>,
751-
Extension(updater): Extension<Arc<RepositoryStatsUpdater>>,
752743
) -> AxumResult<impl IntoResponse> {
753744
let release_found = match_version(&mut conn, &name, Some(&version)).await?;
754745
let (version, version_or_latest, is_latest_url) = match release_found.version {
@@ -758,15 +749,9 @@ pub(crate) async fn target_redirect_handler(
758749
MatchSemver::Semver(_) => return Err(AxumNope::VersionNotFound),
759750
};
760751

761-
let crate_details = CrateDetails::new(
762-
&mut conn,
763-
&name,
764-
&version,
765-
&version_or_latest,
766-
Some(&updater),
767-
)
768-
.await?
769-
.ok_or(AxumNope::VersionNotFound)?;
752+
let crate_details = CrateDetails::new(&mut conn, &name, &version, &version_or_latest)
753+
.await?
754+
.ok_or(AxumNope::VersionNotFound)?;
770755

771756
// We're trying to find the storage location
772757
// for the requested path in the target-redirect.

templates/crate/details.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
{# If the repo link is for github or gitlab, show some stats #}
7070
{# TODO: add support for hosts besides github and gitlab (#35) #}
7171
{%- if details.repository_metadata -%}
72-
{{ details.repository_metadata.icon | fab }}
72+
{{ "code-branch" | fab }}
7373
{% if details.repository_metadata.name %}
7474
{{details.repository_metadata.name}}
7575
{% else %}

0 commit comments

Comments
 (0)