From c99d4bacebdfa7d551cb1a7cba13bfd1a10bded7 Mon Sep 17 00:00:00 2001 From: Emile Trotignon Date: Tue, 28 Jan 2025 10:54:13 +0000 Subject: [PATCH] remove use of let* --- lib/action.ml | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/lib/action.ml b/lib/action.ml index 68acf215..ef2f0d19 100644 --- a/lib/action.ml +++ b/lib/action.ml @@ -368,25 +368,32 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) (Buildkite_api : | Some sender_login -> List.exists (String.equal sender_login) cfg.ignored_users | None -> false + let get_failed_jobs jobs = + List.filter_map + (fun (job : Buildkite_t.job_type) -> + match job with + | Script ({ state = Failed; _ } as job) | Trigger ({ state = Failed; _ } as job) -> Some job + | _ -> None) + jobs + + let log_content_of_job ~ctx job = + match%lwt Buildkite_api.get_job_log ~ctx job with + | Error _ as e -> Lwt.return e + | Ok log -> Lwt.return_ok (Some log.content) + + let get_logs' ~ctx (n : status_notification) = + match%lwt Buildkite_api.get_build ~ctx n with + | Error _ as e -> Lwt.return e + | Ok build -> + let failed_jobs = get_failed_jobs build.jobs in + (match failed_jobs with + | [] -> Lwt.return_ok None + | _ :: _ -> log_content_of_job ~ctx (List.hd failed_jobs)) + let get_logs ~ctx (n : status_notification) = - let ( let* ) = Lwt_result.bind in match n.state with | Success | Pending -> Lwt.return_ok None - | Failure | Error -> - let* build = Buildkite_api.get_build ~ctx n in - let failed_jobs = - List.filter_map - (fun (job : Buildkite_t.job_type) -> - match job with - | Script ({ state = Failed; _ } as job) | Trigger ({ state = Failed; _ } as job) -> Some job - | _ -> None) - build.jobs - in - (match failed_jobs with - | [] -> Lwt.return_ok None - | _ :: _ -> - let* log = Buildkite_api.get_job_log ~ctx (List.hd failed_jobs) in - Lwt.return_ok (Some log.content)) + | Failure | Error -> get_logs' ~ctx n let generate_notifications (ctx : Context.t) (req : Github.t) = let repo = Github.repo_of_notification req in