Skip to content

Commit f7cb270

Browse files
committed
feat: replace hardcode with repo_config
1 parent 2aac8e2 commit f7cb270

File tree

6 files changed

+124
-22
lines changed

6 files changed

+124
-22
lines changed

src/actions/job.ml

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ open Bot_components.GitHub_GitLab_sync
55
open Git_utils
66
open Utils
77
open Lwt.Infix
8+
open Repo_config
89

910
let job_action ~bot_info ~repo_config_table
1011
({build_name; common_info= {http_repo_url}} as job_info) ~gitlab_mapping =
@@ -23,16 +24,49 @@ let job_action ~bot_info ~repo_config_table
2324
f "%s,projects/%d/jobs/%d" http_repo_url job_info.common_info.project_id
2425
job_info.build_id
2526
in
26-
match (github_repo_full_name, job_info.build_name) with
27-
| "rocq-prover/rocq", "bench" ->
28-
Bench.update_bench_status ~bot_info ~repo_config_table ~job_info
29-
(gh_owner, gh_repo) ~external_id ~number:pr_num
30-
| _, _ -> (
27+
let repo_config =
28+
get_repo_config_opt ~owner:gh_owner ~repo:gh_repo repo_config_table
29+
in
30+
(* Original: hardcoded check for "rocq-prover/rocq", "bench"
31+
Now: use repo_config.jobs.bench if available, fallback to hardcoded check *)
32+
let is_bench_job =
33+
match repo_config with
34+
| Some config -> (
35+
match config.jobs with
36+
| Some jobs -> (
37+
match jobs.bench with
38+
| Some bench_job_name ->
39+
String.equal job_info.build_name bench_job_name
40+
| None ->
41+
false )
42+
| None ->
43+
false )
44+
| None ->
45+
false
46+
in
47+
let is_rocq_bench =
48+
String.equal github_repo_full_name "rocq-prover/rocq"
49+
&& String.equal job_info.build_name "bench"
50+
in
51+
if is_bench_job || is_rocq_bench then
52+
Bench.update_bench_status ~bot_info ~repo_config_table ~job_info
53+
(gh_owner, gh_repo) ~external_id ~number:pr_num
54+
else
3155
match job_info.build_status with
3256
| "failed" ->
3357
let failure_reason = Option.value_exn job_info.failure_reason in
58+
(* Original: hardcoded check for "rocq-prover/rocq" for rocq-specific handling
59+
Now: use repo_config if available, fallback to hardcoded check *)
60+
let is_rocq_repo =
61+
match repo_config with
62+
| Some config ->
63+
String.equal config.github_owner "rocq-prover"
64+
&& String.equal config.github_repo "rocq"
65+
| None ->
66+
String.equal github_repo_full_name "rocq-prover/rocq"
67+
in
3468
let summary_builder, allow_failure_handler =
35-
if String.equal github_repo_full_name "rocq-prover/rocq" then
69+
if is_rocq_repo then
3670
( Job_status_rocq.rocq_summary_builder
3771
, fun ~bot_info ~job_name ~job_url ~pr_num ~head_commit
3872
(gh_owner, gh_repo) ~gitlab_repo_full_name ->
@@ -54,13 +88,8 @@ let job_action ~bot_info ~repo_config_table
5488
Job_status.job_success_or_pending ~bot_info (gh_owner, gh_repo)
5589
job_info ~github_repo_full_name ~gitlab_domain
5690
~gitlab_repo_full_name ~context ~state ~external_id
57-
<&>
58-
let repo_config =
59-
Repo_config.get_repo_config_opt ~owner:gh_owner ~repo:gh_repo
60-
repo_config_table
61-
in
62-
Documentation.send_doc_url ~bot_info ~github_repo_full_name
63-
?repo_config job_info
91+
<&> Documentation.send_doc_url ~bot_info ~github_repo_full_name
92+
?repo_config job_info
6493
| ("created" | "running") as state ->
6594
Job_status.job_success_or_pending ~bot_info (gh_owner, gh_repo)
6695
job_info ~github_repo_full_name ~gitlab_domain
@@ -73,4 +102,4 @@ let job_action ~bot_info ~repo_config_table
73102
request. *)
74103
Lwt.return_unit
75104
| unknown_state ->
76-
Lwt_io.printlf "Unknown job status: %s" unknown_state ) )
105+
Lwt_io.printlf "Unknown job status: %s" unknown_state )

src/ci/job_status.ml

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ open String_utils
88
open Git_utils
99
open Lwt.Infix
1010
open Lwt.Syntax
11+
open Repo_config
1112

1213
(******************************************************************************)
1314
(* Types *)
@@ -289,9 +290,9 @@ let job_success_or_pending ~bot_info (gh_owner, gh_repo) job_info
289290
| Error e ->
290291
Lwt_io.printf "%s\n" e
291292
292-
let pipeline_action ~bot_info ({common_info= {http_repo_url}} as pipeline_info)
293-
~gitlab_mapping ?(full_ci_check_repo = None)
294-
?(auto_minimize_on_failure = None) () =
293+
let pipeline_action ~bot_info ~repo_config_table
294+
({common_info= {http_repo_url}} as pipeline_info) ~gitlab_mapping
295+
?(full_ci_check_repo = None) ?(auto_minimize_on_failure = None) () =
295296
let pr_number, _ = pr_from_branch pipeline_info.common_info.branch in
296297
match pipeline_info.state with
297298
| "skipped" ->
@@ -310,8 +311,29 @@ let pipeline_action ~bot_info ({common_info= {http_repo_url}} as pipeline_info)
310311
| Error err ->
311312
Lwt_io.printlf "Error in pipeline action: %s" err
312313
| Ok (gh_owner, gh_repo) -> (
314+
let repo_config =
315+
Repo_config.get_repo_config_opt ~owner:gh_owner ~repo:gh_repo
316+
repo_config_table
317+
in
313318
let state, status, conclusion, title, summary_top =
314319
(* Check if this repo should have full CI detection *)
320+
(* Original: hardcoded CI variable name "FULL_CI"
321+
Now: use repo_config.ci_config.full_ci_variable if available, fallback to "FULL_CI" *)
322+
let full_ci_variable_name =
323+
match repo_config with
324+
| Some config -> (
325+
match config.ci_config with
326+
| Some ci_config -> (
327+
match ci_config.full_ci_variable with
328+
| Some var_name ->
329+
var_name
330+
| None ->
331+
"FULL_CI" )
332+
| None ->
333+
"FULL_CI" )
334+
| None ->
335+
"FULL_CI"
336+
in
315337
let full_ci =
316338
match full_ci_check_repo with
317339
| Some (check_owner, check_repo)
@@ -320,7 +342,7 @@ let pipeline_action ~bot_info ({common_info= {http_repo_url}} as pipeline_info)
320342
try
321343
List.find_map
322344
~f:(fun (key, value) ->
323-
if String.equal key "FULL_CI" then
345+
if String.equal key full_ci_variable_name then
324346
Some (Bool.of_string value)
325347
else None )
326348
pipeline_info.variables

src/ci/job_status.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ val job_success_or_pending :
6868

6969
val pipeline_action :
7070
bot_info:Bot_components.Bot_info.t
71+
-> repo_config_table:(string, Repo_config.t) Base.Hashtbl.t
7172
-> Bot_components.GitLab_types.pipeline_info
7273
-> gitlab_mapping:(string, string) Base.Hashtbl.t
7374
-> ?full_ci_check_repo:(string * string) option

src/config/repo_config.ml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,31 @@ let get_repo_config_opt ~owner ~repo repo_config_table =
259259
let has_repo_config ~owner ~repo repo_config_table =
260260
let key = f "%s/%s" owner repo in
261261
Hashtbl.mem repo_config_table key
262+
263+
(** Check if a repository config has CI configuration *)
264+
let has_ci_config config = Option.is_some config.ci_config
265+
266+
(** Check if a repository config has minimizer URL configured *)
267+
let has_minimizer config = Option.is_some config.minimizer_url
268+
269+
(** Find first repository with CI configuration *)
270+
let find_repo_with_ci_config repo_config_table =
271+
Hashtbl.fold repo_config_table ~init:None ~f:(fun ~key:_ ~data:config acc ->
272+
match acc with
273+
| Some _ ->
274+
acc (* Already found one *)
275+
| None when has_ci_config config ->
276+
Some (config.github_owner, config.github_repo)
277+
| None ->
278+
None )
279+
280+
(** Find first repository with minimizer URL configured *)
281+
let find_repo_with_minimizer repo_config_table =
282+
Hashtbl.fold repo_config_table ~init:None ~f:(fun ~key:_ ~data:config acc ->
283+
match acc with
284+
| Some _ ->
285+
acc (* Already found one *)
286+
| None when has_minimizer config ->
287+
Some (config.github_owner, config.github_repo)
288+
| None ->
289+
None )

src/config/repo_config.mli

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,13 @@ val get_repo_config_opt :
5050

5151
val has_repo_config :
5252
owner:string -> repo:string -> (string, t) Base.Hashtbl.t -> bool
53+
54+
val has_ci_config : t -> bool
55+
56+
val has_minimizer : t -> bool
57+
58+
val find_repo_with_ci_config :
59+
(string, t) Base.Hashtbl.t -> (string * string) option
60+
61+
val find_repo_with_minimizer :
62+
(string, t) Base.Hashtbl.t -> (string * string) option

src/webhooks/gitlab.ml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ open Bot_components.GitHub_GitLab_sync
66
open Job_status
77
open Lwt.Infix
88
open Utils
9+
open Repo_config
910

1011
let handle_gitlab_webhook ~bot_info ~key ~app_id ~gitlab_mapping
1112
~repo_config_table ~gitlab_webhook_secret ~headers ~body =
@@ -37,10 +38,21 @@ let handle_gitlab_webhook ~bot_info ~key ~app_id ~gitlab_mapping
3738
(fun () ->
3839
Bot_components.Github_installations.action_as_github_app ~bot_info
3940
~key ~app_id ~owner (fun ~bot_info ->
40-
pipeline_action ~bot_info pipeline_info ~gitlab_mapping
41-
~full_ci_check_repo:(Some ("rocq-prover", "rocq"))
42-
~auto_minimize_on_failure:(Some ("rocq-prover", "rocq"))
43-
() ) )
41+
(* Original: hardcoded "rocq-prover", "rocq" for full_ci_check_repo and auto_minimize_on_failure
42+
Now: use repo_config if available, fallback to hardcoded values *)
43+
let full_ci_repo =
44+
Option.first_some
45+
(find_repo_with_ci_config repo_config_table)
46+
(Some ("rocq-prover", "rocq"))
47+
in
48+
let minimizer_repo =
49+
Option.first_some
50+
(find_repo_with_minimizer repo_config_table)
51+
(Some ("rocq-prover", "rocq"))
52+
in
53+
pipeline_action ~bot_info ~repo_config_table pipeline_info
54+
~gitlab_mapping ~full_ci_check_repo:full_ci_repo
55+
~auto_minimize_on_failure:minimizer_repo () ) )
4456
|> Lwt.async ;
4557
Server.respond_string ~status:`OK ~body:"Pipeline event." () )
4658
| Ok (_, UnsupportedEvent e) ->

0 commit comments

Comments
 (0)