@@ -93,8 +93,12 @@ let execute_cmd ?(mask = []) command =
9393 Lwt_io. printf " Executing command: %s\n " command
9494 >> = fun () ->
9595 let process = Lwt_process. open_process_full (Lwt_process. shell command) in
96- let stdout_pipe = Utils. copy_stream ~src: process#stdout ~dst: Lwt_io. stdout in
97- let stderr_pipe = Utils. copy_stream ~src: process#stderr ~dst: Lwt_io. stderr in
96+ let stdout_pipe =
97+ HTTP_utils. copy_stream ~src: process#stdout ~dst: Lwt_io. stdout
98+ in
99+ let stderr_pipe =
100+ HTTP_utils. copy_stream ~src: process#stderr ~dst: Lwt_io. stderr
101+ in
98102 (* Capture stdout and stderr in parallel *)
99103 (* Wait for the process to finish *)
100104 let + _stdout_content = stdout_pipe
@@ -161,3 +165,123 @@ let git_test_modified ~base ~head pattern =
161165 Error (f " %s killed by signal %d." command signal)
162166 | Unix. WSTOPPED signal ->
163167 Error (f " %s stopped by signal %d." command signal)
168+
169+ let git_coq_bug_minimizer ~bot_info ~script ~comment_thread_id ~comment_author
170+ ~owner ~repo ~coq_version ~ocaml_version ~minimizer_extra_arguments =
171+ (* To push a new branch we need to identify as coqbot the GitHub
172+ user, who is a collaborator on the run-coq-bug-minimizer repo,
173+ not coqbot the GitHub App *)
174+ Stdlib.Filename. quote_command " ./coq_bug_minimizer.sh"
175+ [ script
176+ ; GitHub_ID. to_string comment_thread_id
177+ ; comment_author
178+ ; bot_info.github_pat
179+ ; bot_info.github_name
180+ ; bot_info.domain
181+ ; owner
182+ ; repo
183+ ; coq_version
184+ ; ocaml_version
185+ ; String. concat ~sep: " " minimizer_extra_arguments ]
186+ |> execute_cmd ~mask: [bot_info.github_pat]
187+
188+ let git_run_ci_minimization ~bot_info ~comment_thread_id ~owner ~repo ~pr_number
189+ ~docker_image ~target ~ci_targets ~opam_switch ~failing_urls ~passing_urls
190+ ~base ~head ~minimizer_extra_arguments ~bug_file_name =
191+ (* To push a new branch we need to identify as coqbot the GitHub
192+ user, who is a collaborator on the run-coq-bug-minimizer repo,
193+ not coqbot the GitHub App *)
194+ ( [ GitHub_ID. to_string comment_thread_id
195+ ; bot_info.github_pat
196+ ; bot_info.github_name
197+ ; bot_info.domain
198+ ; owner
199+ ; repo
200+ ; pr_number
201+ ; docker_image
202+ ; target
203+ ; String. concat ~sep: " " ci_targets
204+ ; opam_switch
205+ ; failing_urls
206+ ; passing_urls
207+ ; base
208+ ; head
209+ ; String. concat ~sep: " " minimizer_extra_arguments ]
210+ @
211+ match bug_file_name with Some bug_file_name -> [bug_file_name] | None -> [] )
212+ |> Stdlib.Filename. quote_command " ./run_ci_minimization.sh"
213+ |> execute_cmd ~mask: [bot_info.github_pat]
214+
215+ let pr_from_branch branch =
216+ if String_utils. string_match ~regexp: " ^pr-\\ ([0-9]*\\ )$" branch then
217+ (Some (Str. matched_group 1 branch |> Int. of_string), " pull request" )
218+ else (None , " branch" )
219+
220+ let github_repo_of_gitlab_project_path ~gitlab_mapping ~gitlab_domain
221+ ~gitlab_repo_full_name =
222+ let full_name_with_domain = gitlab_domain ^ " /" ^ gitlab_repo_full_name in
223+ let github_full_name =
224+ match Hashtbl. find gitlab_mapping full_name_with_domain with
225+ | Some value ->
226+ value
227+ | None ->
228+ Stdio. printf
229+ " Warning: No correspondence found for GitLab repository %s.\n "
230+ full_name_with_domain ;
231+ gitlab_repo_full_name
232+ in
233+ match Str. split (Str. regexp " /" ) github_full_name with
234+ | [owner; repo] ->
235+ (owner, repo)
236+ | _ ->
237+ failwith
238+ (f " Could not split repository full name %s into (owner, repo)."
239+ github_full_name )
240+
241+ let parse_gitlab_repo_url ~http_repo_url =
242+ if
243+ not
244+ (String_utils. string_match ~regexp: " https?://\\ ([^/]*\\ )/\\ (.*/.*\\ )"
245+ http_repo_url )
246+ then
247+ Result. Error (f " Could not parse GitLab repository URL %s." http_repo_url)
248+ else
249+ Result. Ok
250+ (Str. matched_group 1 http_repo_url, Str. matched_group 2 http_repo_url)
251+
252+ let parse_gitlab_repo_url_and_print ~http_repo_url =
253+ match parse_gitlab_repo_url ~http_repo_url with
254+ | Ok (gitlab_domain , gitlab_repo_full_name ) ->
255+ Stdio. printf " GitLab domain: \" %s\"\n " gitlab_domain ;
256+ Stdio. printf " GitLab repository full name: \" %s\"\n " gitlab_repo_full_name
257+ | Error msg ->
258+ Stdio. print_endline msg
259+
260+ let % expect_test " http_repo_url_parsing_coq" =
261+ parse_gitlab_repo_url_and_print ~http_repo_url: " https://gitlab.com/coq/coq" ;
262+ [% expect
263+ {|
264+ GitLab domain : "gitlab.com"
265+ GitLab repository full name : "coq/coq" |}]
266+
267+ let % expect_test " http_repo_url_parsing_mathcomp" =
268+ parse_gitlab_repo_url_and_print
269+ ~http_repo_url: " https://gitlab.inria.fr/math-comp/math-comp" ;
270+ [% expect
271+ {|
272+ GitLab domain : "gitlab.inria.fr"
273+ GitLab repository full name : "math-comp/math-comp" |}]
274+
275+ let % expect_test " http_repo_url_parsing_example_from_gitlab_docs" =
276+ parse_gitlab_repo_url_and_print
277+ ~http_repo_url: " https://gitlab.example.com/gitlab-org/gitlab-test" ;
278+ [% expect
279+ {|
280+ GitLab domain : "gitlab.example.com"
281+ GitLab repository full name : "gitlab-org/gitlab-test" |}]
282+
283+ let github_repo_of_gitlab_url ~gitlab_mapping ~http_repo_url =
284+ parse_gitlab_repo_url ~http_repo_url
285+ |> Result. map ~f: (fun (gitlab_domain , gitlab_repo_full_name ) ->
286+ github_repo_of_gitlab_project_path ~gitlab_mapping ~gitlab_domain
287+ ~gitlab_repo_full_name )
0 commit comments