Something went wrong. Try again.
Git-native issue tracker
Something went wrong. Try again.
2.1 kB · 67 lines
OCaml
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768open Cmdlineropen Common
let export_row ~schema (view : Tracker.Store_tree.row_view) = let row = view.row in let id = Tracker.Core.Row.id row in let* encoded = Tracker.Row_json.to_string ~schema row in let comments = List.map (fun comment -> Json.object' [ field "author" (Json.string (Tracker.Comment.author comment)); field "body" (Json.string (Tracker.Comment.body comment)); ]) view.comments in Ok (Json.object' [ field "type" (Json.string "row"); field "id" (Json.string id); field "row" (Json.Value.of_string_exn encoded); field "body" (match view.body with | None -> Json.null () | Some body -> Json.string body); field "comments" (Json.list comments); ])
let export root jsonl = run @@ fun ~sw ~fs ~net:_ ~mono:_ -> if not jsonl then Error "export requires --jsonl" else with_store ~sw ~fs ~root @@ fun ~store ~repo ~commit:_ ~tree -> let* snapshot = Tracker.Store_tree.load_tree ~repo ~tree in let candidate = Tracker.Store_tree.candidate snapshot in let schema = Tracker.Schema_candidate.schema candidate in let* views = Tracker.Store_tree.row_views ~repo snapshot in let* encoded = List.fold_left (fun acc view -> let* acc = acc in let* value = export_row ~schema view in Ok (value :: acc)) (Ok []) views in Fmt.epr "tracker: %a@." Fpath.pp store; Fmt.pr "%s@." (Json.Value.to_string (Json.object' [ field "type" (Json.string "snapshot"); field "tree" (Json.string (Git.Hash.to_hex tree)); field "rows" (Json.int (List.length views)); ])); List.iter (fun row -> Fmt.pr "%s@." (Json.Value.to_string row)) (List.rev encoded); Ok ()
let jsonl = Arg.(value & flag & info [ "jsonl" ] ~doc:"Emit typed JSON lines.")
let cmd = Cmd.v (Cmd.info "export" ~doc:"Stream one validated canonical Git snapshot.") Term.(const export $ root $ jsonl)