diff --git a/lib/action.ml b/lib/action.ml index 4c0bb4e5..605cde69 100644 --- a/lib/action.ml +++ b/lib/action.ml @@ -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 -> diff --git a/lib/state.ml b/lib/state.ml index 3eeba111..28c1f55f 100644 --- a/lib/state.ml +++ b/lib/state.ml @@ -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 diff --git a/lib/util.ml b/lib/util.ml index eee6d56b..a932d80a 100644 --- a/lib/util.ml +++ b/lib/util.ml @@ -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 ...//builds/. - 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///builds/ *) + 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" @@ -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