From 60e9541a7062fa8538148c643cc38fe6096683e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reynir=20Bj=C3=B6rnsson?= Date: Wed, 15 Nov 2023 17:01:28 +0100 Subject: [PATCH] Use a custom git commit message Requires yocaml#76b27c6282ff343e618f53c03153008a7ee2366e or later. --- src/blogger.ml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/blogger.ml b/src/blogger.ml index 71d6524..ca1edf7 100644 --- a/src/blogger.ml +++ b/src/blogger.ml @@ -125,6 +125,20 @@ let run_git_config key = function | Ok (value, _) -> Some value | Error _ -> None) +let run_git_rev_parse default = + let open Bos in + let value = OS.Cmd.run_out Cmd.(v "git" % "rev-parse" % "HEAD") in + match OS.Cmd.out_string value with + | Ok (value, (_, `Exited 0)) -> value + | Ok (value, (run_info, _)) -> + Logs.warn (fun m -> m "Failed to get commit id: %a: %s" + Cmd.pp (OS.Cmd.run_info_cmd run_info) + value); + default + | Error `Msg e -> + Logs.warn (fun m -> m "Failed to get commit id: %s" e); + default + let get_name_and_email name email = let name = run_git_config "user.name" name in let email = run_git_config "user.email" email in @@ -144,12 +158,14 @@ let name_and_email = let build_and_push _quiet remote (author, email) hook = let fiber () = let open Lwt.Syntax in + let commit_id = run_git_rev_parse "an unknown state" in + let comment = Printf.sprintf "Built from %s" commit_id in let* ctx = unix_ctx_with_ssh () in let* res = Yocaml_git.execute (module Yocaml_unix) (module Pclock) - ~ctx ?author ?email remote (program ~target:"") + ~ctx ?author ?email ~comment remote (program ~target:"") in match res with | Error (`Msg err) -> Fmt.failwith "build-and-push: %s." err