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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove builds.json API endpoint #2198

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
129 changes: 1 addition & 128 deletions src/web/builds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ use crate::{
use anyhow::Result;
use axum::{
extract::{Extension, Path},
http::header::ACCESS_CONTROL_ALLOW_ORIGIN,
response::IntoResponse,
Json,
};
use chrono::{DateTime, Utc};
use serde::Serialize;
Expand Down Expand Up @@ -79,40 +77,6 @@ pub(crate) async fn build_list_handler(
.into_response())
}

pub(crate) async fn build_list_json_handler(
Path((name, req_version)): Path<(String, String)>,
Extension(pool): Extension<Pool>,
) -> AxumResult<impl IntoResponse> {
let version = match match_version_axum(&pool, &name, Some(&req_version))
.await?
.exact_name_only()?
{
MatchSemver::Exact((version, _)) | MatchSemver::Latest((version, _)) => version,
MatchSemver::Semver((version, _)) => {
return Ok(super::axum_cached_redirect(
&format!("/crate/{name}/{version}/builds.json"),
CachePolicy::ForeverInCdn,
)?
.into_response());
}
};

let builds = spawn_blocking({
move || {
let mut conn = pool.get()?;
get_builds(&mut conn, &name, &version)
}
})
.await?;

Ok((
Extension(CachePolicy::NoStoreMustRevalidate),
[(ACCESS_CONTROL_ALLOW_ORIGIN, "*")],
Json(builds),
)
.into_response())
}

fn get_builds(conn: &mut postgres::Client, name: &str, version: &str) -> Result<Vec<Build>> {
Ok(conn
.query(
Expand Down Expand Up @@ -150,7 +114,7 @@ mod tests {
test::{assert_cache_control, wrapper, FakeBuild},
web::cache::CachePolicy,
};
use chrono::{DateTime, Duration, Utc};
use chrono::Duration;
use kuchikiki::traits::TendrilSink;
use reqwest::StatusCode;

Expand Down Expand Up @@ -195,88 +159,6 @@ mod tests {
});
}

#[test]
fn build_list_json() {
wrapper(|env| {
env.fake_release()
.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"),
])
.create()?;

let response = env.frontend().get("/crate/foo/0.1.0/builds.json").send()?;
assert_cache_control(&response, CachePolicy::NoStoreMustRevalidate, &env.config());
let value: serde_json::Value = serde_json::from_str(&response.text()?)?;

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::<DateTime<Utc>>(
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::<DateTime<Utc>>(
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::<DateTime<Utc>>(
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 limits() {
wrapper(|env| {
Expand Down Expand Up @@ -355,15 +237,6 @@ mod tests {
assert!(body.contains("<a href=\"/crate/aquarelle/latest/source/\""));
assert!(body.contains("<a href=\"/crate/aquarelle/latest\""));

let resp_json = env
.frontend()
.get("/crate/aquarelle/latest/builds.json")
.send()?;
assert!(resp_json
.url()
.as_str()
.ends_with("/crate/aquarelle/latest/builds.json"));

Ok(())
});
}
Expand Down
4 changes: 0 additions & 4 deletions src/web/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,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",
Expand Down
4 changes: 0 additions & 4 deletions src/web/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,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/status.json",
get_internal(super::status::status_handler),
Expand Down