diff --git a/src/web/builds.rs b/src/web/builds.rs index d01756ef6..cad7aabb0 100644 --- a/src/web/builds.rs +++ b/src/web/builds.rs @@ -18,9 +18,7 @@ use crate::{ }; use anyhow::{Result, anyhow}; use askama::Template; -use axum::{ - Json, extract::Extension, http::header::ACCESS_CONTROL_ALLOW_ORIGIN, response::IntoResponse, -}; +use axum::{Json, extract::Extension, response::IntoResponse}; use axum_extra::{ TypedHeader, headers::{Authorization, authorization::Bearer}, @@ -84,53 +82,6 @@ pub(crate) async fn build_list_handler( .into_response()) } -pub(crate) async fn build_list_json_handler( - Path((name, req_version)): Path<(String, ReqVersion)>, - mut conn: DbConnection, -) -> AxumResult { - let version = match_version(&mut conn, &name, &req_version) - .await? - .assume_exact_name()? - .into_canonical_req_version_or_else(|version| { - AxumNope::Redirect( - EscapedURI::new(&format!("/crate/{name}/{version}/builds.json"), None), - CachePolicy::ForeverInCdn, - ) - })? - .into_version(); - - Ok(( - Extension(CachePolicy::NoStoreMustRevalidate), - [(ACCESS_CONTROL_ALLOW_ORIGIN, "*")], - Json( - get_builds(&mut conn, &name, &version) - .await? - .iter() - .filter_map(|build| { - if build.build_status == BuildStatus::InProgress { - return None; - } - // for backwards compatibility in this API, we - // * convert the build status to a boolean - // * already filter out in-progress builds - // - // even when we start showing in-progress builds in the UI, - // we might still not show them here for backwards - // compatibility. - Some(serde_json::json!({ - "id": build.id, - "rustc_version": build.rustc_version, - "docsrs_version": build.docsrs_version, - "build_status": build.build_status.is_success(), - "build_time": build.build_time, - })) - }) - .collect::>(), - ), - ) - .into_response()) -} - async fn crate_version_exists( conn: &mut sqlx::PgConnection, name: &String, @@ -260,7 +211,6 @@ mod tests { web::cache::CachePolicy, }; use axum::{body::Body, http::Request}; - use chrono::{DateTime, Utc}; use kuchikiki::traits::TendrilSink; use reqwest::StatusCode; use tower::ServiceExt; @@ -341,106 +291,6 @@ mod tests { }); } - #[test] - fn build_list_json() { - async_wrapper(|env| async move { - env.fake_release() - .await - .name("foo") - .version("0.1.0") - .builds(vec![ - FakeBuild::default() - .rustc_version("rustc (blabla 2019-01-01)") - .docsrs_version("docs.rs 1.0.0"), - FakeBuild::default() - .successful(false) - .rustc_version("rustc (blabla 2020-01-01)") - .docsrs_version("docs.rs 2.0.0"), - FakeBuild::default() - .rustc_version("rustc (blabla 2021-01-01)") - .docsrs_version("docs.rs 3.0.0"), - FakeBuild::default() - .build_status(BuildStatus::InProgress) - .rustc_version("rustc (blabla 2022-01-01)") - .docsrs_version("docs.rs 4.0.0"), - ]) - .create() - .await?; - - let response = env - .web_app() - .await - .get("/crate/foo/0.1.0/builds.json") - .await?; - response.assert_cache_control(CachePolicy::NoStoreMustRevalidate, &env.config()); - let value: serde_json::Value = serde_json::from_str(&response.text().await?)?; - - assert_eq!(value.as_array().unwrap().len(), 3); - - assert_eq!(value.pointer("/0/build_status"), Some(&true.into())); - assert_eq!( - value.pointer("/0/docsrs_version"), - Some(&"docs.rs 3.0.0".into()) - ); - assert_eq!( - value.pointer("/0/rustc_version"), - Some(&"rustc (blabla 2021-01-01)".into()) - ); - assert!(value.pointer("/0/id").unwrap().is_i64()); - assert!( - serde_json::from_value::>( - value.pointer("/0/build_time").unwrap().clone() - ) - .is_ok() - ); - - assert_eq!(value.pointer("/1/build_status"), Some(&false.into())); - assert_eq!( - value.pointer("/1/docsrs_version"), - Some(&"docs.rs 2.0.0".into()) - ); - assert_eq!( - value.pointer("/1/rustc_version"), - Some(&"rustc (blabla 2020-01-01)".into()) - ); - assert!(value.pointer("/1/id").unwrap().is_i64()); - assert!( - serde_json::from_value::>( - value.pointer("/1/build_time").unwrap().clone() - ) - .is_ok() - ); - - assert_eq!(value.pointer("/2/build_status"), Some(&true.into())); - assert_eq!( - value.pointer("/2/docsrs_version"), - Some(&"docs.rs 1.0.0".into()) - ); - assert_eq!( - value.pointer("/2/rustc_version"), - Some(&"rustc (blabla 2019-01-01)".into()) - ); - assert!(value.pointer("/2/id").unwrap().is_i64()); - assert!( - serde_json::from_value::>( - value.pointer("/2/build_time").unwrap().clone() - ) - .is_ok() - ); - - assert!( - value.pointer("/1/build_time").unwrap().as_str().unwrap() - < value.pointer("/0/build_time").unwrap().as_str().unwrap() - ); - assert!( - value.pointer("/2/build_time").unwrap().as_str().unwrap() - < value.pointer("/1/build_time").unwrap().as_str().unwrap() - ); - - Ok(()) - }); - } - #[test] fn build_trigger_rebuild_missing_config() { async_wrapper(|env| async move { @@ -716,7 +566,7 @@ mod tests { env.web_app() .await - .assert_success("/crate/aquarelle/latest/builds.json") + .assert_success("/crate/aquarelle/latest/status.json") .await?; Ok(()) diff --git a/src/web/metrics.rs b/src/web/metrics.rs index 76f8889bd..33585adf4 100644 --- a/src/web/metrics.rs +++ b/src/web/metrics.rs @@ -120,10 +120,6 @@ mod tests { ("/", "/"), ("/crate/hexponent/0.2.0", "/crate/{name}/{version}"), ("/crate/rcc/0.0.0", "/crate/{name}/{version}"), - ( - "/crate/rcc/0.0.0/builds.json", - "/crate/{name}/{version}/builds.json", - ), ( "/crate/rcc/0.0.0/status.json", "/crate/{name}/{version}/status.json", diff --git a/src/web/routes.rs b/src/web/routes.rs index 9971c9133..39a59e9a2 100644 --- a/src/web/routes.rs +++ b/src/web/routes.rs @@ -223,10 +223,6 @@ pub(super) fn build_axum_routes() -> AxumRouter { "/crate/{name}/{version}/builds", get_internal(super::builds::build_list_handler), ) - .route( - "/crate/{name}/{version}/builds.json", - get_internal(super::builds::build_list_json_handler), - ) .route( "/crate/{name}/{version}/rebuild", post_internal(super::builds::build_trigger_rebuild_handler),