Skip to content

Commit 7ba7591

Browse files
Nemo157syphar
authored andcommitted
Remove builds.json API endpoint
1 parent a1a3d06 commit 7ba7591

File tree

3 files changed

+2
-160
lines changed

3 files changed

+2
-160
lines changed

src/web/builds.rs

Lines changed: 2 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ use crate::{
1818
};
1919
use anyhow::{Result, anyhow};
2020
use askama::Template;
21-
use axum::{
22-
Json, extract::Extension, http::header::ACCESS_CONTROL_ALLOW_ORIGIN, response::IntoResponse,
23-
};
21+
use axum::{Json, extract::Extension, response::IntoResponse};
2422
use axum_extra::{
2523
TypedHeader,
2624
headers::{Authorization, authorization::Bearer},
@@ -84,53 +82,6 @@ pub(crate) async fn build_list_handler(
8482
.into_response())
8583
}
8684

87-
pub(crate) async fn build_list_json_handler(
88-
Path((name, req_version)): Path<(String, ReqVersion)>,
89-
mut conn: DbConnection,
90-
) -> AxumResult<impl IntoResponse> {
91-
let version = match_version(&mut conn, &name, &req_version)
92-
.await?
93-
.assume_exact_name()?
94-
.into_canonical_req_version_or_else(|version| {
95-
AxumNope::Redirect(
96-
EscapedURI::new(&format!("/crate/{name}/{version}/builds.json"), None),
97-
CachePolicy::ForeverInCdn,
98-
)
99-
})?
100-
.into_version();
101-
102-
Ok((
103-
Extension(CachePolicy::NoStoreMustRevalidate),
104-
[(ACCESS_CONTROL_ALLOW_ORIGIN, "*")],
105-
Json(
106-
get_builds(&mut conn, &name, &version)
107-
.await?
108-
.iter()
109-
.filter_map(|build| {
110-
if build.build_status == BuildStatus::InProgress {
111-
return None;
112-
}
113-
// for backwards compatibility in this API, we
114-
// * convert the build status to a boolean
115-
// * already filter out in-progress builds
116-
//
117-
// even when we start showing in-progress builds in the UI,
118-
// we might still not show them here for backwards
119-
// compatibility.
120-
Some(serde_json::json!({
121-
"id": build.id,
122-
"rustc_version": build.rustc_version,
123-
"docsrs_version": build.docsrs_version,
124-
"build_status": build.build_status.is_success(),
125-
"build_time": build.build_time,
126-
}))
127-
})
128-
.collect::<Vec<_>>(),
129-
),
130-
)
131-
.into_response())
132-
}
133-
13485
async fn crate_version_exists(
13586
conn: &mut sqlx::PgConnection,
13687
name: &String,
@@ -260,7 +211,6 @@ mod tests {
260211
web::cache::CachePolicy,
261212
};
262213
use axum::{body::Body, http::Request};
263-
use chrono::{DateTime, Utc};
264214
use kuchikiki::traits::TendrilSink;
265215
use reqwest::StatusCode;
266216
use tower::ServiceExt;
@@ -341,106 +291,6 @@ mod tests {
341291
});
342292
}
343293

344-
#[test]
345-
fn build_list_json() {
346-
async_wrapper(|env| async move {
347-
env.fake_release()
348-
.await
349-
.name("foo")
350-
.version("0.1.0")
351-
.builds(vec![
352-
FakeBuild::default()
353-
.rustc_version("rustc (blabla 2019-01-01)")
354-
.docsrs_version("docs.rs 1.0.0"),
355-
FakeBuild::default()
356-
.successful(false)
357-
.rustc_version("rustc (blabla 2020-01-01)")
358-
.docsrs_version("docs.rs 2.0.0"),
359-
FakeBuild::default()
360-
.rustc_version("rustc (blabla 2021-01-01)")
361-
.docsrs_version("docs.rs 3.0.0"),
362-
FakeBuild::default()
363-
.build_status(BuildStatus::InProgress)
364-
.rustc_version("rustc (blabla 2022-01-01)")
365-
.docsrs_version("docs.rs 4.0.0"),
366-
])
367-
.create()
368-
.await?;
369-
370-
let response = env
371-
.web_app()
372-
.await
373-
.get("/crate/foo/0.1.0/builds.json")
374-
.await?;
375-
response.assert_cache_control(CachePolicy::NoStoreMustRevalidate, &env.config());
376-
let value: serde_json::Value = serde_json::from_str(&response.text().await?)?;
377-
378-
assert_eq!(value.as_array().unwrap().len(), 3);
379-
380-
assert_eq!(value.pointer("/0/build_status"), Some(&true.into()));
381-
assert_eq!(
382-
value.pointer("/0/docsrs_version"),
383-
Some(&"docs.rs 3.0.0".into())
384-
);
385-
assert_eq!(
386-
value.pointer("/0/rustc_version"),
387-
Some(&"rustc (blabla 2021-01-01)".into())
388-
);
389-
assert!(value.pointer("/0/id").unwrap().is_i64());
390-
assert!(
391-
serde_json::from_value::<DateTime<Utc>>(
392-
value.pointer("/0/build_time").unwrap().clone()
393-
)
394-
.is_ok()
395-
);
396-
397-
assert_eq!(value.pointer("/1/build_status"), Some(&false.into()));
398-
assert_eq!(
399-
value.pointer("/1/docsrs_version"),
400-
Some(&"docs.rs 2.0.0".into())
401-
);
402-
assert_eq!(
403-
value.pointer("/1/rustc_version"),
404-
Some(&"rustc (blabla 2020-01-01)".into())
405-
);
406-
assert!(value.pointer("/1/id").unwrap().is_i64());
407-
assert!(
408-
serde_json::from_value::<DateTime<Utc>>(
409-
value.pointer("/1/build_time").unwrap().clone()
410-
)
411-
.is_ok()
412-
);
413-
414-
assert_eq!(value.pointer("/2/build_status"), Some(&true.into()));
415-
assert_eq!(
416-
value.pointer("/2/docsrs_version"),
417-
Some(&"docs.rs 1.0.0".into())
418-
);
419-
assert_eq!(
420-
value.pointer("/2/rustc_version"),
421-
Some(&"rustc (blabla 2019-01-01)".into())
422-
);
423-
assert!(value.pointer("/2/id").unwrap().is_i64());
424-
assert!(
425-
serde_json::from_value::<DateTime<Utc>>(
426-
value.pointer("/2/build_time").unwrap().clone()
427-
)
428-
.is_ok()
429-
);
430-
431-
assert!(
432-
value.pointer("/1/build_time").unwrap().as_str().unwrap()
433-
< value.pointer("/0/build_time").unwrap().as_str().unwrap()
434-
);
435-
assert!(
436-
value.pointer("/2/build_time").unwrap().as_str().unwrap()
437-
< value.pointer("/1/build_time").unwrap().as_str().unwrap()
438-
);
439-
440-
Ok(())
441-
});
442-
}
443-
444294
#[test]
445295
fn build_trigger_rebuild_missing_config() {
446296
async_wrapper(|env| async move {
@@ -716,7 +566,7 @@ mod tests {
716566

717567
env.web_app()
718568
.await
719-
.assert_success("/crate/aquarelle/latest/builds.json")
569+
.assert_success("/crate/aquarelle/latest/status.json")
720570
.await?;
721571

722572
Ok(())

src/web/metrics.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,6 @@ mod tests {
120120
("/", "/"),
121121
("/crate/hexponent/0.2.0", "/crate/{name}/{version}"),
122122
("/crate/rcc/0.0.0", "/crate/{name}/{version}"),
123-
(
124-
"/crate/rcc/0.0.0/builds.json",
125-
"/crate/{name}/{version}/builds.json",
126-
),
127123
(
128124
"/crate/rcc/0.0.0/status.json",
129125
"/crate/{name}/{version}/status.json",

src/web/routes.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,6 @@ pub(super) fn build_axum_routes() -> AxumRouter {
223223
"/crate/{name}/{version}/builds",
224224
get_internal(super::builds::build_list_handler),
225225
)
226-
.route(
227-
"/crate/{name}/{version}/builds.json",
228-
get_internal(super::builds::build_list_json_handler),
229-
)
230226
.route(
231227
"/crate/{name}/{version}/rebuild",
232228
post_internal(super::builds::build_trigger_rebuild_handler),

0 commit comments

Comments
 (0)