Add /build/latest/ redirect

This commit is contained in:
Robur 2021-06-02 12:23:40 +00:00
parent 4fec5ed38c
commit fb2515e713
5 changed files with 37 additions and 2 deletions

View file

@ -394,6 +394,17 @@ module Build = struct
LIMIT 1
|}
let get_latest_successful_uuid =
Caqti_request.find
id
Rep.uuid
{| SELECT b.uuid
FROM build b
WHERE b.job = ? AND b.result_kind = 0 AND b.result_code = 0
ORDER BY start_d DESC, start_ps DESC
LIMIT 1
|}
let get_previous =
Caqti_request.find_opt
id

View file

@ -149,6 +149,9 @@ sig
val get_latest_uuid :
(id, id * Uuidm.t, [< `Many | `One | `Zero > `One `Zero ])
Caqti_request.t
val get_latest_successful_uuid :
(id, Uuidm.t, [< `Many | `One | `Zero > `One ])
Caqti_request.t
val get_previous :
(id, id * Meta.t, [< `Many | `One | `Zero > `One `Zero ])
Caqti_request.t

View file

@ -139,6 +139,19 @@ let add_routes datadir =
Views.job job_name builds |> string_of_html |> Dream.html
in
let redirect_latest req =
let job_name = Dream.param "job" req in
let path = Dream.path req |> String.concat "/" in
let* build = Dream.sql req (Model.latest_successful_build_uuid job_name) in
match build with
| Error e ->
Log.warn (fun m -> m "Error getting job: %a" pp_error e);
Dream.respond ~status:`Not_Found "Error getting job"
| Ok build ->
Dream.redirect req
(Fmt.strf "/job/%s/build/%a/%s" job_name Uuidm.pp build path)
in
let job_build req =
let job_name = Dream.param "job" req
and build = Dream.param "build" req in
@ -277,9 +290,10 @@ let add_routes datadir =
Dream.router [
Dream.get "/" builder;
Dream.get "/job/:job/" job;
Dream.get "/job/:job/build/latest/**" redirect_latest;
Dream.get "/job/:job/build/:build/" job_build;
Dream.get "/hash" hash;
Dream.get "/job/:job/build/:build/f/**" job_build_file;
Dream.post "/upload" (authorized upload);
Dream.get "/hash" hash;
Dream.get "/compare/:build_left/:build_right/opam-switch" compare_opam;
Dream.post "/upload" (authorized upload);
]

View file

@ -64,6 +64,10 @@ let latest_build_uuid job_id (module Db : CONN) =
(* We know there's at least one job when this is called, probably. *)
not_found >|= snd
let latest_successful_build_uuid job_name (module Db : CONN) =
Db.find Builder_db.Job.get_id_by_name job_name >>= fun job_id ->
Db.find Builder_db.Build.get_latest_successful_uuid job_id
let build_previous id (module Db : CONN) =
Db.find_opt Builder_db.Build.get_previous id >|=
Option.map (fun (_id, meta) -> meta)

View file

@ -28,6 +28,9 @@ val build_exists : Uuidm.t -> Caqti_lwt.connection ->
val latest_build_uuid : Builder_db.id -> Caqti_lwt.connection ->
(Uuidm.t, [> error ]) result Lwt.t
val latest_successful_build_uuid : string -> Caqti_lwt.connection ->
(Uuidm.t, [> Caqti_error.call_or_retrieve ]) result Lwt.t
val build_previous : Builder_db.id -> Caqti_lwt.connection ->
(Builder_db.Build.Meta.t option, [> Caqti_error.call_or_retrieve ]) result Lwt.t