Skip to content

Commit

Permalink
Support only builkite CI in get_build_number fn
Browse files Browse the repository at this point in the history
  • Loading branch information
thatportugueseguy committed Dec 18, 2024
1 parent d3d7db7 commit a8ba00f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/action.ml
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
let has_same_status (branch : branch) =
match StringMap.find_opt branch.name branch_statuses with
| Some build_statuses ->
let current = Util.Build.get_build_number_exn ~context ~build_url in
let current = Util.Build.get_build_number_exn ~build_url in
let previous_builds = IntMap.filter (fun build_num _ -> build_num < current) build_statuses in
(match IntMap.is_empty previous_builds with
| true ->
Expand Down
2 changes: 1 addition & 1 deletion lib/state.ml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ let set_repo_pipeline_status { state } (n : Github_t.status_notification) =
| Some build_url ->
let context = n.context in
let { Util.Build.is_pipeline_step; pipeline_name } = Util.Build.parse_context_exn ~context in
let build_number = Util.Build.get_build_number_exn ~context ~build_url in
let build_number = Util.Build.get_build_number_exn ~build_url in
let is_finished =
match is_pipeline_step, n.state with
| true, (Success | Failure | Error) -> true
Expand Down
15 changes: 8 additions & 7 deletions lib/util.ml
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ module Build = struct
| Some c -> c
| None -> failwith (Printf.sprintf "failed to get pipeline name from notification. Context: %s" context)

let get_build_number_exn ~context ~build_url =
let { pipeline_name; _ } = parse_context_exn ~context in
(* build urls are in the form of .../<base_pipeline_name>/builds/<build_number>.
Pipeline steps have an html anchor after the build number *)
let re = Re2.create_exn (Printf.sprintf ".*/%s/builds/(\\d+)#?" pipeline_name) in
match Re2.find_first_exn ~sub:(`Index 1) re build_url with
let buildkite_build_number_re =
(* buildkite.com/<org_name>/<pipeline_name>/builds/<build_id> *)
Re2.create_exn {|buildkite.com/[\w_-]+/[\w_-]+/builds/(\d+)|}

(** For now we only care about buildkite pipelines and steps. Other CI systems are not supported yet. *)
let get_build_number_exn ~build_url =
match Re2.find_first_exn ~sub:(`Index 1) buildkite_build_number_re build_url with
| build_number -> int_of_string build_number
| exception _ -> failwith "failed to get build number from url"

Expand All @@ -88,7 +89,7 @@ module Build = struct
| Some branches_statuses ->
(match StringMap.find_opt branch.name branches_statuses with
| Some builds_maps ->
let current_build_number = get_build_number_exn ~context:n.context ~build_url in
let current_build_number = get_build_number_exn ~build_url in
let to_previous_failed_steps n build_number (build_status : State_t.build_status) acc =
match build_number >= n with
| true -> acc
Expand Down

0 comments on commit a8ba00f

Please sign in to comment.