Skip to content

Commit 2aac8e2

Browse files
committed
feat: replace hardcode with repo_config for bench
1 parent 66547b6 commit 2aac8e2

File tree

5 files changed

+76
-17
lines changed

5 files changed

+76
-17
lines changed

src/actions/job.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ let job_action ~bot_info ~repo_config_table
2525
in
2626
match (github_repo_full_name, job_info.build_name) with
2727
| "rocq-prover/rocq", "bench" ->
28-
Bench.update_bench_status ~bot_info ~job_info (gh_owner, gh_repo)
29-
~external_id ~number:pr_num
28+
Bench.update_bench_status ~bot_info ~repo_config_table ~job_info
29+
(gh_owner, gh_repo) ~external_id ~number:pr_num
3030
| _, _ -> (
3131
match job_info.build_status with
3232
| "failed" ->

src/utils/bench.ml

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ open Utils
66
open HTTP_utils
77
open String_utils
88
open Lwt.Infix
9+
open Repo_config
910

1011
let parse_quantity table table_name =
1112
let regexp = {|.*TOP \([0-9]*\)|} in
@@ -151,8 +152,8 @@ let bench_comment ~bot_info ~owner ~repo ~number ~gitlab_url ?check_url
151152
Lwt_io.printlf "Unable to get_pull_request_id for bench for pr #%d: %s"
152153
number e
153154

154-
let update_bench_status ~bot_info ~job_info (gh_owner, gh_repo) ~external_id
155-
~number =
155+
let update_bench_status ~bot_info ~repo_config_table ~job_info
156+
(gh_owner, gh_repo) ~external_id ~number =
156157
let open Lwt.Syntax in
157158
match number with
158159
| None ->
@@ -163,11 +164,28 @@ let update_bench_status ~bot_info ~job_info (gh_owner, gh_repo) ~external_id
163164
| Error e ->
164165
Lwt_io.printlf "No repo id for bench job: %s" e
165166
| Ok repo_id -> (
166-
Lwt_io.printl "Pushing status check for bench job."
167-
<&>
167+
let repo_config =
168+
get_repo_config_opt ~owner:gh_owner ~repo:gh_repo repo_config_table
169+
in
170+
(* Original: hardcoded GitLab URL "https://gitlab.inria.fr/coq/coq/-/jobs/%d"
171+
Now: use repo_config if available, fallback to hardcoded value *)
168172
let gitlab_url =
169-
f "https://gitlab.inria.fr/coq/coq/-/jobs/%d" job_info.build_id
173+
match repo_config with
174+
| Some config -> (
175+
match
176+
(config.gitlab_domain, config.gitlab_owner, config.gitlab_repo)
177+
with
178+
| Some domain, Some gl_owner, Some gl_repo ->
179+
f "https://%s/%s/%s/-/jobs/%d" domain gl_owner gl_repo
180+
job_info.build_id
181+
| _ ->
182+
f "https://gitlab.inria.fr/coq/coq/-/jobs/%d"
183+
job_info.build_id )
184+
| None ->
185+
f "https://gitlab.inria.fr/coq/coq/-/jobs/%d" job_info.build_id
170186
in
187+
Lwt_io.printl "Pushing status check for bench job."
188+
<&>
171189
let summary =
172190
f "## GitLab Job URL:\n[GitLab Bench Job](%s)\n" gitlab_url
173191
in
@@ -231,14 +249,41 @@ let update_bench_status ~bot_info ~job_info (gh_owner, gh_repo) ~external_id
231249
| _ ->
232250
Lwt_io.printlf "Unknown state for bench job: %s" state ) )
233251

234-
let run_bench ~bot_info ?(org = "rocq-prover") ?(team = "contributors")
235-
?(gitlab_domain = "gitlab.inria.fr") ?key_value_pairs comment_info =
252+
let run_bench ~bot_info ~repo_config_table ?key_value_pairs comment_info =
236253
(* Do we want to use this more often? *)
237254
let open Lwt.Syntax in
238255
let pr = comment_info.issue in
239256
let owner = pr.issue.owner in
240257
let repo = pr.issue.repo in
241258
let pr_number = pr.number in
259+
let repo_config = get_repo_config_opt ~owner ~repo repo_config_table in
260+
(* Original: hardcoded org="rocq-prover", team="contributors", gitlab_domain="gitlab.inria.fr"
261+
Now: use repo_config if available, fallback to hardcoded values *)
262+
let org =
263+
match repo_config with
264+
| Some config -> (
265+
match config.org_name with Some org -> org | None -> "rocq-prover" )
266+
| None ->
267+
"rocq-prover"
268+
in
269+
let team =
270+
match repo_config with
271+
| Some config -> (
272+
match config.team_name with Some team -> team | None -> "contributors" )
273+
| None ->
274+
"contributors"
275+
in
276+
let gitlab_domain =
277+
match repo_config with
278+
| Some config -> (
279+
match config.gitlab_domain with
280+
| Some domain ->
281+
domain
282+
| None ->
283+
"gitlab.inria.fr" )
284+
| None ->
285+
"gitlab.inria.fr"
286+
in
242287
(* We need the GitLab build_id and project_id. Currently there is no good way
243288
to query this data so we have to jump through some somewhat useless hoops in
244289
order to get our hands on this information. TODO: do this more directly.*)
@@ -263,10 +308,24 @@ let run_bench ~bot_info ?(org = "rocq-prover") ?(team = "contributors")
263308
Lwt.return_error err
264309
| Ok summary -> (
265310
try
311+
(* Original: hardcoded GitLab URL "https://gitlab.inria.fr/coq/coq/-/jobs/"
312+
Now: use repo_config if available, fallback to hardcoded value *)
313+
let gitlab_url_prefix =
314+
match repo_config with
315+
| Some config -> (
316+
match
317+
(config.gitlab_domain, config.gitlab_owner, config.gitlab_repo)
318+
with
319+
| Some domain, Some gl_owner, Some gl_repo ->
320+
f "https://%s/%s/%s/-/jobs/" domain gl_owner gl_repo
321+
| _ ->
322+
"https://gitlab.inria.fr/coq/coq/-/jobs/" )
323+
| None ->
324+
"https://gitlab.inria.fr/coq/coq/-/jobs/"
325+
in
266326
let build_id =
267327
let regexp =
268-
f {|.*%s\([0-9]*\)|}
269-
(Str.quote "[bench](https://gitlab.inria.fr/coq/coq/-/jobs/")
328+
f {|.*%s\([0-9]*\)|} (Str.quote (f "[bench](%s" gitlab_url_prefix))
270329
in
271330
( if String_utils.string_match ~regexp summary then
272331
Str.matched_group 1 summary

src/utils/bench.mli

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ val bench_comment :
3131

3232
val update_bench_status :
3333
bot_info:Bot_components.Bot_info.t
34+
-> repo_config_table:(string, Repo_config.t) Base.Hashtbl.t
3435
-> job_info:
3536
Bot_components.GitLab_types.ci_common_info
3637
Bot_components.GitLab_types.job_info
@@ -41,9 +42,7 @@ val update_bench_status :
4142

4243
val run_bench :
4344
bot_info:Bot_components.Bot_info.t
44-
-> ?org:string
45-
-> ?team:string
46-
-> ?gitlab_domain:string
45+
-> repo_config_table:(string, Repo_config.t) Base.Hashtbl.t
4746
-> ?key_value_pairs:(string * string) list
4847
-> Bot_components.GitHub_types.comment_info
4948
-> unit Lwt.t

src/utils/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(library
22
(name utils)
33
(public_name coq-bot.utils)
4-
(libraries base bot-components)
4+
(libraries base bot-components coq-bot.config)
55
(wrapped false)
66
(modules bench coq))

src/webhooks/github.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ let handle_comment_created ~bot_info ~key ~app_id ~github_bot_name
240240
Bot_components.Github_installations.action_as_github_app ~bot_info
241241
~key ~app_id ~owner:comment_info.issue.issue.owner
242242
(fun ~bot_info ->
243-
run_bench ~bot_info
243+
run_bench ~bot_info ~repo_config_table
244244
~key_value_pairs:[("coq_native", "yes")]
245245
comment_info ) )
246246
|> Lwt.async ;
@@ -260,7 +260,8 @@ let handle_comment_created ~bot_info ~key ~app_id ~github_bot_name
260260
(fun () ->
261261
Bot_components.Github_installations.action_as_github_app ~bot_info
262262
~key ~app_id ~owner:comment_info.issue.issue.owner
263-
(fun ~bot_info -> run_bench ~bot_info comment_info ) )
263+
(fun ~bot_info ->
264+
run_bench ~bot_info ~repo_config_table comment_info ) )
264265
|> Lwt.async ;
265266
Server.respond_string ~status:`OK
266267
~body:(f "Received a request to start the bench.")

0 commit comments

Comments
 (0)