From 55d4091256c39e3b6e224353cec63588858dcef9 Mon Sep 17 00:00:00 2001 From: PizieDust Date: Thu, 19 Dec 2024 12:22:07 +0100 Subject: [PATCH] return uuid of latest build when header contains an accept json --- lib/builder_web.ml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/builder_web.ml b/lib/builder_web.ml index af6c328..eb7a5b6 100644 --- a/lib/builder_web.ml +++ b/lib/builder_web.ml @@ -330,9 +330,18 @@ let routes ~datadir ~cachedir ~configdir ~expired_jobs = Dream.sql req (Model.latest_successful_build_uuid job_id platform)) >>= Model.not_found |> if_error "Error getting job" >>= fun build -> - Dream.redirect req - (Link.Job_build_artifact.make_from_string ~job_name ~build ~artifact ()) - |> Lwt_result.ok + match Dream.header req "Accept" with + | Some accept when String.starts_with ~prefix:"application/json" accept -> + let json_response = + `Assoc [ + "uuid", `String (Uuidm.to_string build); + ] |> Yojson.Basic.to_string + in + Dream.json ~status:`OK json_response |> Lwt_result.ok + | _ -> + Dream.redirect req + (Link.Job_build_artifact.make_from_string ~job_name ~build ~artifact ()) + |> Lwt_result.ok in let redirect_latest req =