Skip to content

Commit

Permalink
Fix strip_quoted_bot_name for comments containing a colon and add exp…
Browse files Browse the repository at this point in the history
…ect test.
  • Loading branch information
Zimmi48 committed Jul 12, 2023
1 parent 53069f0 commit 7c4fbb6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
15 changes: 3 additions & 12 deletions src/bot.ml
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,7 @@ let callback _conn req body =
, coqbot_ci_minimize_text_of_body
, coqbot_resume_ci_minimize_text_of_body )
in
let strip_quoted_bot_name body =
(* If someone says "`@coqbot minimize foo`", (with backticks), we
don't want to treat that as them tagging coqbot, so we adjust
the tagging to "@`coqbot minimize foo`" so that the matching
below doesn't pick up the name *)
Str.global_replace
(Str.regexp (f "\\(`\\|<code>\\)@%s " @@ Str.quote github_bot_name))
(f "@\\1%s " @@ Str.quote github_bot_name)
body
in

let body = Cohttp_lwt.Body.to_string body in
(* print_endline "Request received."; *)
match Uri.path (Request.uri req) with
Expand Down Expand Up @@ -308,7 +299,7 @@ let callback _conn req body =
Server.respond_string ~status:`OK
~body:"Note card removed from project: nothing to do." ()
| Ok (_, IssueOpened ({body= Some body} as issue_info)) -> (
let body = body |> Helpers.trim_comments |> strip_quoted_bot_name in
let body = body |> trim_comments |> strip_quoted_bot_name ~github_bot_name in
match coqbot_minimize_text_of_body body with
| Some (options, script) ->
(fun () ->
Expand All @@ -329,7 +320,7 @@ let callback _conn req body =
() )
| Ok (signed, CommentCreated comment_info) -> (
let body =
comment_info.body |> Helpers.trim_comments |> strip_quoted_bot_name
comment_info.body |> trim_comments |> strip_quoted_bot_name ~github_bot_name
in
match coqbot_minimize_text_of_body body with
| Some (options, script) ->
Expand Down
17 changes: 17 additions & 0 deletions src/helpers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ let trim_comments comment =
in
aux comment 0 false

let strip_quoted_bot_name ~github_bot_name body =
(* If someone says "`@coqbot minimize foo`", (with backticks), we
don't want to treat that as them tagging coqbot, so we adjust
the tagging to "@`coqbot minimize foo`" so that the matching
below doesn't pick up the name *)
Str.global_replace
(Str.regexp (f "\\(`\\|<code>\\)@%s:? " @@ Str.quote github_bot_name))
(f "@\\1%s " @@ Str.quote github_bot_name)
body

let%expect_test "strip_quoted_bot_name" =
Stdio.printf "%s\n"
(strip_quoted_bot_name ~github_bot_name:"coqbot"
{|>this didn't produce a pipeline for some reason\r\n\r\nI think that this is normal. @herbelin was maybe expecting that adding the `request: full CI` label would trigger a new run immediately, but the semantics is that this label will produce such a full CI run at the next update (next push) of this PR. Cf. the [documentation](https://github.com/coq/coq/blob/master/CONTRIBUTING.md#understanding-automatic-feedback):\r\n\r\n>you can request a full run of the CI by putting the `request: full CI` label before pushing to your PR branch, or by commenting `@coqbot: run full CI` after having pushed. |}) ;
[%expect
{| >this didn't produce a pipeline for some reason\r\n\r\nI think that this is normal. @herbelin was maybe expecting that adding the `request: full CI` label would trigger a new run immediately, but the semantics is that this label will produce such a full CI run at the next update (next push) of this PR. Cf. the [documentation](https://github.com/coq/coq/blob/master/CONTRIBUTING.md#understanding-automatic-feedback):\r\n\r\n>you can request a full run of the CI by putting the `request: full CI` label before pushing to your PR branch, or by commenting @`coqbot run full CI` after having pushed. |}]

let github_repo_of_gitlab_project_path ~gitlab_mapping ~gitlab_domain
~gitlab_repo_full_name =
let full_name_with_domain = gitlab_domain ^ "/" ^ gitlab_repo_full_name in
Expand Down
2 changes: 2 additions & 0 deletions src/helpers.mli
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ val remove_between : string -> int -> int -> string

val trim_comments : string -> string

val strip_quoted_bot_name : github_bot_name:string -> string -> string

val github_repo_of_gitlab_project_path :
gitlab_mapping:(string, string) Base.Hashtbl.t
-> gitlab_domain:string
Expand Down

0 comments on commit 7c4fbb6

Please sign in to comment.