Skip to content

Commit 17b3d81

Browse files
authored
Refactor src folder (#362)
This PR is a pure refactor of the code in the src directory. The main goal is to reorganize the structure in preparation for adding support for configuring the bot using TOML files. ``` src/ |--- actions/ |--- ci/ |--- config/ |--- utils/ |--- webhooks/ |--- bot.ml |--- dune ```
2 parents 9a84ab3 + 99bdba5 commit 17b3d81

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+109
-101
lines changed

bot-components/Git_utils.ml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,16 @@ let%expect_test "http_repo_url_parsing_example_from_gitlab_docs" =
139139
{|
140140
GitLab domain: "gitlab.example.com"
141141
GitLab repository full name: "gitlab-org/gitlab-test" |}]
142+
143+
let init_git_bare_repository ~bot_info =
144+
let* () = Lwt_io.printl "Initializing repository..." in
145+
let github_token = Bot_info.github_token bot_info in
146+
"git init --bare"
147+
|&& f {|git config user.email "%s"|} bot_info.email
148+
|&& f {|git config user.name "%s"|} bot_info.github_name
149+
|> execute_cmd ~mask:[github_token]
150+
>>= function
151+
| Ok _ ->
152+
Lwt_io.printl "Bare repository initialized."
153+
| Error e ->
154+
Lwt_io.printlf "Error while initializing bare repository: %s." e

bot-components/Git_utils.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ val pr_from_branch : string -> int option * string
2828

2929
val parse_gitlab_repo_url :
3030
http_repo_url:string -> (string * string, string) result
31+
32+
val init_git_bare_repository : bot_info:Bot_info.t -> unit Lwt.t

src/actions/dune

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(library
2+
(name actions)
3+
(public_name coq-bot.actions)
4+
(libraries base bot-components coq-bot.config coq-bot.utils coq-bot.ci)
5+
(wrapped false)
6+
(modules backport job pr_sync))
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ let job_action ~bot_info
2525
in
2626
match (github_repo_full_name, job_info.build_name) with
2727
| "rocq-prover/rocq", "bench" ->
28-
Bench_utils.update_bench_status ~bot_info ~job_info
29-
(gh_owner, gh_repo) ~external_id ~number:pr_num
28+
Bench.update_bench_status ~bot_info ~job_info (gh_owner, gh_repo)
29+
~external_id ~number:pr_num
3030
| _, _ -> (
3131
match job_info.build_status with
3232
| "failed" ->
3333
let failure_reason = Option.value_exn job_info.failure_reason in
3434
let summary_builder, allow_failure_handler =
3535
if String.equal github_repo_full_name "rocq-prover/rocq" then
36-
( Ci_job_status_rocq.rocq_summary_builder
36+
( Job_status_rocq.rocq_summary_builder
3737
, fun ~bot_info ~job_name ~job_url ~pr_num ~head_commit
3838
(gh_owner, gh_repo) ~gitlab_repo_full_name ->
39-
Ci_job_status_rocq.handle_rocq_allow_failure ~bot_info
39+
Job_status_rocq.handle_rocq_allow_failure ~bot_info
4040
~job_name ~job_url ~pr_num ~head_commit
4141
(gh_owner, gh_repo) ~gitlab_repo_full_name )
4242
else
@@ -46,18 +46,18 @@ let job_action ~bot_info
4646
~head_commit:_ _ ~gitlab_repo_full_name:_ ->
4747
Lwt.return_unit )
4848
in
49-
Ci_job_status.job_failure ~bot_info job_info ~pr_num
49+
Job_status.job_failure ~bot_info job_info ~pr_num
5050
(gh_owner, gh_repo) ~gitlab_domain ~gitlab_repo_full_name ~context
5151
~failure_reason ~external_id ~summary_builder
5252
~allow_failure_handler ()
5353
| "success" as state ->
54-
Ci_job_status.job_success_or_pending ~bot_info (gh_owner, gh_repo)
54+
Job_status.job_success_or_pending ~bot_info (gh_owner, gh_repo)
5555
job_info ~gitlab_domain ~gitlab_repo_full_name ~context ~state
5656
~external_id
57-
<&> Ci_documentation.send_doc_url ~bot_info job_info
57+
<&> Documentation.send_doc_url ~bot_info job_info
5858
~github_repo_full_name
5959
| ("created" | "running") as state ->
60-
Ci_job_status.job_success_or_pending ~bot_info (gh_owner, gh_repo)
60+
Job_status.job_success_or_pending ~bot_info (gh_owner, gh_repo)
6161
job_info ~gitlab_domain ~gitlab_repo_full_name ~context ~state
6262
~external_id
6363
| "cancelled" | "canceled" | "pending" ->
File renamed without changes.

src/bot.ml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,18 @@ let callback _conn req body =
4646
(* print_endline "Request received."; *)
4747
match path with
4848
| "/job" | "/pipeline" (* legacy endpoints *) | "/gitlab" ->
49-
Webhook_gitlab.handle_gitlab_webhook ~bot_info ~key ~app_id
50-
~gitlab_mapping ~gitlab_webhook_secret ~headers:(Request.headers req)
51-
~body
49+
Gitlab.handle_gitlab_webhook ~bot_info ~key ~app_id ~gitlab_mapping
50+
~gitlab_webhook_secret ~headers:(Request.headers req) ~body
5251
| "/push" | "/pull_request" (* legacy endpoints *) | "/github" ->
53-
Webhook_github.handle_github_webhook ~bot_info ~key ~app_id
54-
~github_bot_name ~gitlab_mapping ~github_mapping ~github_webhook_secret
52+
Github.handle_github_webhook ~bot_info ~key ~app_id ~github_bot_name
53+
~gitlab_mapping ~github_mapping ~github_webhook_secret
5554
~headers:(Request.headers req) ~body ~minimize_text_of_body
5655
~ci_minimize_text_of_body ~resume_ci_minimize_text_of_body
5756
| "/coq-bug-minimizer" | "/ci-minimization" | "/resume-ci-minimization" ->
58-
Webhook_minimizer.handle_minimizer_webhook ~bot_info ~key ~app_id
59-
~endpoint:path ~body
57+
Minimizer.handle_minimizer_webhook ~bot_info ~key ~app_id ~endpoint:path
58+
~body
6059
| "/check-stale-pr" ->
61-
Webhook_scheduled.handle_stale_pr_check ~bot_info ~key ~app_id
60+
Scheduled.handle_stale_pr_check ~bot_info ~key ~app_id
6261
~daily_schedule_secret ~body
6362
| _ ->
6463
Server.respond_not_found ()

0 commit comments

Comments
 (0)