Skip to content

Commit

Permalink
clean file content before pushing
Browse files Browse the repository at this point in the history
  • Loading branch information
thatportugueseguy committed Feb 7, 2025
1 parent aacd452 commit 05d9c1b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
4 changes: 4 additions & 0 deletions cleanup/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(library
(name text_cleanup))

(ocamllex lexer)
16 changes: 16 additions & 0 deletions cleanup/lexer.mll
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{}

let digit = ['0' - '9']

let esc = '\027'

let timestamp = esc "_bk;t=" digit* '\007'

let color_code = esc '[' (digit | ';') * 'm'

let to_delete = timestamp | color_code

rule cleanup buf = parse
| to_delete { cleanup buf lexbuf }
| _ { Buffer.add_string buf (Lexing.lexeme lexbuf); cleanup buf lexbuf }
| eof { () }
5 changes: 5 additions & 0 deletions cleanup/text_cleanup.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let cleanup string =
let lexbuf = Lexing.from_string string in
let buf = Buffer.create 16 in
Lexer.cleanup buf lexbuf;
Buffer.contents buf
3 changes: 2 additions & 1 deletion lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
re2
sexplib0
uri
yojson)
yojson
text_cleanup)
(preprocess
(pps lwt_ppx)))

Expand Down
4 changes: 2 additions & 2 deletions lib/slack.ml
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ let generate_status_notification ?slack_user_id ?failed_steps ~(ctx : Context.t)
match is_failed_build_notification with
| false -> Lwt.return_unit
| true ->
let logs = Text.[ log1 ] in
let logs = Text.[ log2 ] in
let secrets = Context.get_secrets_exn ctx in
(match secrets.slack_access_token with
| None -> failwith " failed to retrieve Slack access token to upload files"
Expand Down Expand Up @@ -501,7 +501,7 @@ let generate_status_notification ?slack_user_id ?failed_steps ~(ctx : Context.t)
let%lwt files =
Lwt_list.map_p
(fun (filename, content) ->
let%lwt uploaded = get_upload_url_external (filename, content) in
let%lwt uploaded = get_upload_url_external (filename, Text_cleanup.cleanup content) in
Lwt.return (uploaded.file_id, filename))
logs
in
Expand Down

0 comments on commit 05d9c1b

Please sign in to comment.