Skip to content

Commit 71cb378

Browse files
buildkite: call get_build with build url
1 parent 620c747 commit 71cb378

File tree

4 files changed

+15
-21
lines changed

4 files changed

+15
-21
lines changed

lib/action.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,9 +642,8 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) (Buildkite_api :
642642
~failed_steps:Common.FailedStepSet.empty n channel;
643643
]
644644
| Failed ->
645-
let get_build ~build_url = Buildkite_api.get_build ~ctx build_url in
646645
(* repo state is updated upon fetching new failed steps *)
647-
(match%lwt new_failed_steps ~repo_state ~get_build n with
646+
(match%lwt new_failed_steps ~repo_state ~get_build:(Buildkite_api.get_build ~ctx) n with
648647
| Error e -> action_error e
649648
| Ok failed_steps ->
650649
match FailedStepSet.is_empty failed_steps with

lib/api_local.ml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,10 @@ module Buildkite : Api.Buildkite = struct
238238

239239
[@@@warning "-27"]
240240
let get_build ?(cache : [ `Use | `Refresh ] option) ~ctx build_url =
241-
match Re2.find_submatches_exn Util.Build.buildkite_org_pipeline_build_re build_url with
242-
| exception _ -> failwith "Failed to parse Buildkite build url"
243-
| [| Some _; Some org; Some pipeline; Some build_nr |] ->
244-
let file = clean_forward_slashes (sprintf "organizations/%s/pipelines/%s/builds/%s" org pipeline build_nr) in
245-
let url = Filename.concat buildkite_cache_dir file in
246-
with_cache_file url Buildkite_j.get_build_res_of_string
247-
| _ -> failwith "failed to get all build details from the notification. Is this a Buildkite notification?"
241+
let* org, pipeline, build_nr = Lwt.return @@ Util.Build.get_org_pipeline_build' build_url in
242+
let file = clean_forward_slashes (sprintf "organizations/%s/pipelines/%s/builds/%s" org pipeline build_nr) in
243+
let url = Filename.concat buildkite_cache_dir file in
244+
with_cache_file url Buildkite_j.get_build_res_of_string
248245

249246
let get_build_branch ~ctx (n : Github_t.status_notification) =
250247
let* build_url = Lwt.return @@ Util.Build.get_build_url n in

lib/api_remote.ml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -332,30 +332,29 @@ module Buildkite : Api.Buildkite = struct
332332

333333
let get_build ?(cache : [ `Use | `Refresh ] = `Use) ~(ctx : Context.t) build_url =
334334
let* org, pipeline, build_nr = Lwt.return @@ Util.Build.get_org_pipeline_build' build_url in
335-
let build_url = sprintf "organizations/%s/pipelines/%s/builds/%s" org pipeline build_nr in
335+
let path = sprintf "organizations/%s/pipelines/%s/builds/%s" org pipeline build_nr in
336336
let build_key = cache_key org pipeline build_nr in
337337
let* build =
338338
let get () =
339-
request_token_auth ~name:("get build details for #" ^ build_nr) ~ctx `GET build_url
339+
request_token_auth ~name:("get build details for #" ^ build_nr) ~ctx `GET path
340340
Buildkite_j.get_build_res_of_string
341341
in
342342
match cache with
343343
| `Refresh -> get ()
344344
| `Use ->
345345
match Builds_cache.get builds_cache build_key with
346-
| Some build -> Lwt.return_ok build
346+
| Some build ->
347+
log#info "Cache hit for build %s" build_key;
348+
Lwt.return_ok build
347349
| None -> get ()
348350
in
349351
Builds_cache.set builds_cache build_key build;
350352
Lwt.return_ok build
351353

352354
let get_build_branch ~(ctx : Context.t) (n : Github_t.status_notification) =
353355
let* org, pipeline, build_nr = Lwt.return @@ Util.Build.get_org_pipeline_build n in
354-
let build_url = sprintf "organizations/%s/pipelines/%s/builds/%s" org pipeline build_nr in
356+
let* build_url = Lwt.return @@ Util.Build.get_build_url n in
355357
let map_branch { Buildkite_t.branch; _ } : Github_t.branch = { name = branch } in
356-
match Builds_cache.get builds_cache (cache_key org pipeline build_nr) with
357-
| Some { Buildkite_t.branch; _ } -> Lwt.return_ok ({ name = branch } : Github_t.branch)
358-
| None ->
359-
log#info "Fetching branch details for build %s in pipeline %s" build_nr pipeline;
360-
get_build ~ctx build_url |> Lwt_result.map map_branch
358+
log#info "Fetching branch details for %s" (cache_key org pipeline build_nr);
359+
get_build ~cache:`Use ~ctx build_url |> Lwt_result.map map_branch
361360
end

lib/util.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,8 @@ module Webhook = struct
349349
let* org, pipeline, build_nr = Lwt.return @@ Build.get_org_pipeline_build' n.build.web_url in
350350
let repo_key = repo_key org pipeline in
351351
let get_failed_steps () =
352-
log#info "Fetching failed steps for org=%s, pipeline=%s, build=%s" org pipeline build_nr;
353-
let build_url = Printf.sprintf "organizations/%s/pipelines/%s/builds/%s" org pipeline build_nr in
354-
let* (build : Buildkite_t.get_build_res) = get_build ~build_url in
352+
log#info "Fetching failed steps for build %s/%s/%s" org pipeline build_nr;
353+
let* (build : Buildkite_t.get_build_res) = get_build n.build.web_url in
355354
let to_failed_step (job : Buildkite_t.job) = { Buildkite_t.name = job.name; build_url = job.web_url } in
356355
Lwt.return_ok @@ (Build.filter_failed_jobs build.jobs |> List.map to_failed_step |> Common.FailedStepSet.of_list)
357356
in

0 commit comments

Comments
 (0)