add tag to jobs: description

This commit is contained in:
Robur 2021-06-29 15:15:16 +00:00
parent e45497e97c
commit 9a271add7b
3 changed files with 26 additions and 17 deletions

View file

@ -18,7 +18,7 @@ let job_tag =
{| CREATE TABLE job_tag ( {| CREATE TABLE job_tag (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
tag INTEGER NOT NULL, tag INTEGER NOT NULL,
value VARCHAR(255) NOT NULL, value TEXT NOT NULL,
job INTEGER NOT NULL, job INTEGER NOT NULL,
FOREIGN KEY(job) REFERENCES job(id), FOREIGN KEY(job) REFERENCES job(id),
@ -60,15 +60,15 @@ let infer_section_and_synopsis artifacts =
| None -> None | None -> None
| Some (_, data) -> Some (OpamFile.SwitchExport.read_from_string data) | Some (_, data) -> Some (OpamFile.SwitchExport.read_from_string data)
in in
let infer_synopsis switch = let infer_synopsis_and_descr switch =
let root = switch.OpamFile.SwitchExport.selections.OpamTypes.sel_roots in let root = switch.OpamFile.SwitchExport.selections.OpamTypes.sel_roots in
if OpamPackage.Set.cardinal root <> 1 then if OpamPackage.Set.cardinal root <> 1 then
None None, None
else else
let root = OpamPackage.Set.choose root in let root = OpamPackage.Set.choose root in
match OpamPackage.Name.Map.find_opt root.OpamPackage.name switch.OpamFile.SwitchExport.overlays with match OpamPackage.Name.Map.find_opt root.OpamPackage.name switch.OpamFile.SwitchExport.overlays with
| None -> None | None -> None, None
| Some opam -> OpamFile.OPAM.synopsis opam | Some opam -> OpamFile.OPAM.synopsis opam, OpamFile.OPAM.descr_body opam
in in
let infer_section_from_packages switch = let infer_section_from_packages switch =
let influx = OpamPackage.Name.of_string "metrics-influx" in let influx = OpamPackage.Name.of_string "metrics-influx" in
@ -89,14 +89,14 @@ let infer_section_and_synopsis artifacts =
| _ -> None | _ -> None
in in
match opam_switch with match opam_switch with
| None -> None, None | None -> None, (None, None)
| Some opam_switch -> | Some opam_switch ->
let section = let section =
match infer_section_from_extension with match infer_section_from_extension with
| Some x -> x | Some x -> x
| None -> infer_section_from_packages opam_switch | None -> infer_section_from_packages opam_switch
in in
Some section, infer_synopsis opam_switch Some section, infer_synopsis_and_descr opam_switch
let remove_tag = let remove_tag =
Caqti_request.exec Caqti_request.exec
@ -132,8 +132,10 @@ let migrate datadir (module Db : Caqti_blocking.CONNECTION) =
Db.exec job_tag () >>= fun () -> Db.exec job_tag () >>= fun () ->
Db.exec insert_tag "section" >>= fun () -> Db.exec insert_tag "section" >>= fun () ->
Db.exec insert_tag "synopsis" >>= fun () -> Db.exec insert_tag "synopsis" >>= fun () ->
Db.exec insert_tag "description" >>= fun () ->
Db.find find_tag "section" >>= fun section_id -> Db.find find_tag "section" >>= fun section_id ->
Db.find find_tag "synopsis" >>= fun synopsis_id -> Db.find find_tag "synopsis" >>= fun synopsis_id ->
Db.find find_tag "description" >>= fun descr_id ->
Db.collect_list jobs () >>= fun jobs -> Db.collect_list jobs () >>= fun jobs ->
Grej.list_iter_result (fun job -> Grej.list_iter_result (fun job ->
Db.find latest_successful_build job >>= fun build -> Db.find latest_successful_build job >>= fun build ->
@ -146,7 +148,8 @@ let migrate datadir (module Db : Caqti_blocking.CONNECTION) =
artifacts >>= fun files -> artifacts >>= fun files ->
let sec_syn = infer_section_and_synopsis files in let sec_syn = infer_section_and_synopsis files in
(match fst sec_syn with None -> Ok () | Some s -> Db.exec insert_job_tag (section_id, s, job)) >>= fun () -> (match fst sec_syn with None -> Ok () | Some s -> Db.exec insert_job_tag (section_id, s, job)) >>= fun () ->
(match snd sec_syn with None -> Ok () | Some s -> Db.exec insert_job_tag (synopsis_id, s, job))) (match snd sec_syn with None, _ -> Ok () | Some s, _ -> Db.exec insert_job_tag (synopsis_id, s, job)) >>= fun () ->
(match snd sec_syn with _, None -> Ok () | _, Some s -> Db.exec insert_job_tag (descr_id, s, job)))
jobs >>= fun () -> jobs >>= fun () ->
Db.exec (Grej.set_version new_version) () Db.exec (Grej.set_version new_version) ()

View file

@ -140,7 +140,7 @@ module Job_tag = struct
{| CREATE TABLE job_tag ( {| CREATE TABLE job_tag (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
tag INTEGER NOT NULL, tag INTEGER NOT NULL,
value VARCHAR(255) NOT NULL, value TEXT NOT NULL,
job INTEGER NOT NULL, job INTEGER NOT NULL,
FOREIGN KEY(job) REFERENCES job(id), FOREIGN KEY(job) REFERENCES job(id),

View file

@ -194,15 +194,15 @@ let infer_section_and_synopsis artifacts =
| None -> None | None -> None
| Some (_, data) -> Some (OpamFile.SwitchExport.read_from_string data) | Some (_, data) -> Some (OpamFile.SwitchExport.read_from_string data)
in in
let infer_synopsis switch = let infer_synopsis_and_descr switch =
let root = switch.OpamFile.SwitchExport.selections.OpamTypes.sel_roots in let root = switch.OpamFile.SwitchExport.selections.OpamTypes.sel_roots in
if OpamPackage.Set.cardinal root <> 1 then if OpamPackage.Set.cardinal root <> 1 then
None None, None
else else
let root = OpamPackage.Set.choose root in let root = OpamPackage.Set.choose root in
match OpamPackage.Name.Map.find_opt root.OpamPackage.name switch.OpamFile.SwitchExport.overlays with match OpamPackage.Name.Map.find_opt root.OpamPackage.name switch.OpamFile.SwitchExport.overlays with
| None -> None | None -> None, None
| Some opam -> OpamFile.OPAM.synopsis opam | Some opam -> OpamFile.OPAM.synopsis opam, OpamFile.OPAM.descr_body opam
in in
let infer_section_from_packages switch = let infer_section_from_packages switch =
let influx = OpamPackage.Name.of_string "metrics-influx" in let influx = OpamPackage.Name.of_string "metrics-influx" in
@ -223,14 +223,14 @@ let infer_section_and_synopsis artifacts =
| _ -> None | _ -> None
in in
match opam_switch with match opam_switch with
| None -> None, None | None -> None, (None, None)
| Some opam_switch -> | Some opam_switch ->
let section = let section =
match infer_section_from_extension with match infer_section_from_extension with
| Some x -> x | Some x -> x
| None -> infer_section_from_packages opam_switch | None -> infer_section_from_packages opam_switch
in in
Some section, infer_synopsis opam_switch Some section, infer_synopsis_and_descr opam_switch
let add_build let add_build
datadir datadir
@ -262,6 +262,9 @@ let add_build
let synopsis_tag = "synopsis" in let synopsis_tag = "synopsis" in
Db.exec Tag.try_add synopsis_tag >>= fun () -> Db.exec Tag.try_add synopsis_tag >>= fun () ->
Db.find Tag.get_id_by_name synopsis_tag >>= fun synopsis_id -> Db.find Tag.get_id_by_name synopsis_tag >>= fun synopsis_id ->
let descr_tag = "description" in
Db.exec Tag.try_add descr_tag >>= fun () ->
Db.find Tag.get_id_by_name descr_tag >>= fun descr_id ->
Db.exec Build.add { Build.uuid; start; finish; result; Db.exec Build.add { Build.uuid; start; finish; result;
console; script = job.Builder.script; console; script = job.Builder.script;
main_binary = None; user_id; job_id } >>= fun () -> main_binary = None; user_id; job_id } >>= fun () ->
@ -271,8 +274,11 @@ let add_build
| None -> Lwt_result.return () | None -> Lwt_result.return ()
| Some section_v -> Db.exec Job_tag.add (section_id, section_v, id)) >>= fun () -> | Some section_v -> Db.exec Job_tag.add (section_id, section_v, id)) >>= fun () ->
(match snd sec_syn with (match snd sec_syn with
| None -> Lwt_result.return () | None, _-> Lwt_result.return ()
| Some synopsis_v -> Db.exec Job_tag.add (synopsis_id, synopsis_v, id)) >>= fun () -> | Some synopsis_v, _ -> Db.exec Job_tag.add (synopsis_id, synopsis_v, id)) >>= fun () ->
(match snd sec_syn with
| _, None -> Lwt_result.return ()
| _, Some descr_v -> Db.exec Job_tag.add (descr_id, descr_v, id)) >>= fun () ->
List.fold_left List.fold_left
(fun r file -> (fun r file ->
r >>= fun () -> r >>= fun () ->