Skip to content

Commit e07420e

Browse files
committed
github & slack_msg: cleaned up line breaks and add default values to compare files returns
1 parent 5d070a4 commit e07420e

File tree

5 files changed

+8
-13
lines changed

5 files changed

+8
-13
lines changed

lib/api_local.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ module Slack_simple : Api.Slack = struct
8989
log#info "will notify %s%s" msg.channel
9090
( match msg.Slack_t.text with
9191
| None -> ""
92-
| Some s -> Printf.sprintf " with %S" s
92+
| Some s -> sprintf " with %S" s
9393
);
9494
Lwt.return @@ Ok ()
9595

lib/github.atd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ type compare = {
130130
behind_by: int;
131131
total_commits: int;
132132
commits: api_commit list;
133-
files: file list;
133+
~files <ocaml default="[]">: file list;
134134
}
135135

136136
type pr_action = [

lib/github.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ let gh_link_of_string url_str =
118118
match Re2.find_submatches_exn gh_link_re path with
119119
| [| _; prefix; Some owner; Some name; Some link_type; Some item |] ->
120120
let item = Base.String.chop_suffix_if_exists item ~suffix:"/" in
121-
let make_repo owner name =
121+
let repo =
122122
let base = Option.value_map prefix ~default:host ~f:(fun p -> String.concat [ host; p ]) in
123123
let scheme = Uri.scheme url in
124124
let html_base, api_base =
@@ -136,7 +136,6 @@ let gh_link_of_string url_str =
136136
compare_url = sprintf "%s/compare{/basehead}" api_base;
137137
}
138138
in
139-
let repo = make_repo owner name in
140139
let verify_commit_sha repo item =
141140
try
142141
match Re2.find_submatches_exn commit_sha_re item with

lib/slack_message.ml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,7 @@ let populate_compare repository (compare : compare) =
221221
let commits_unfurl_fallback =
222222
List.map commits_unfurl ~f:(fun commit_unfurl -> Option.value commit_unfurl.fallback ~default:"")
223223
in
224-
let file_stats =
225-
match condense_file_changes compare.files with
226-
| "" -> ""
227-
| text -> sprintf "\n\n%s" text
228-
in
224+
let file_stats = sprintf "\n%s" (condense_file_changes compare.files) in
229225
let text = sprintf "%s%s" (String.concat commits_unfurl_text) file_stats in
230226
let fallback = String.concat commits_unfurl_fallback in
231227
{ base with text = Some text; fallback = Some fallback }

test/slack_payloads.expected

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ will unfurl in #C047QTRD1CH
601601
"fallback": "[9d20f77f] test: added tests for link unfurling - Sewen Thy",
602602
"mrkdwn_in": [ "text" ],
603603
"color": "#f6f8fa",
604-
"text": "`<https://github.com/ahrefs/monorobot/commit/9d20f77fd7c79f5a00978ae91340603159921cb1|9d20f77f>` test: added tests for link unfurling - Sewen Thy\n\n\nmodified 14 files",
604+
"text": "`<https://github.com/ahrefs/monorobot/commit/9d20f77fd7c79f5a00978ae91340603159921cb1|9d20f77f>` test: added tests for link unfurling - Sewen Thy\n\nmodified 14 files",
605605
"footer": "<https://github.com/ahrefs/monorobot|ahrefs/monorobot>"
606606
}
607607
}
@@ -616,7 +616,7 @@ will unfurl in #C047QTRD1CH
616616
"fallback": "[858b5e1d] test: test for ignoring user comment on PR - Sewen Thy[88372442] cfg and action: add support to ignore comments from certain users - Sewen Thy[6ec6b47d] Merge pull request #126 from sewenthy/sewen/121-ignore-code-comments-from-defined-list-of-users\n\nIgnore code comments from defined list of users - Louis",
617617
"mrkdwn_in": [ "text" ],
618618
"color": "#f6f8fa",
619-
"text": "`<https://github.com/sewenthy/monorobot/commit/858b5e1d2de2716883a7f83f69676cb1d05a6c9f|858b5e1d>` test: test for ignoring user comment on PR - Sewen Thy\n`<https://github.com/sewenthy/monorobot/commit/883724426505ec03e29a1e4fd11079797a30bd57|88372442>` cfg and action: add support to ignore comments from certain users - Sewen Thy\n`<https://github.com/sewenthy/monorobot/commit/6ec6b47d1f333d30d5c3889e05dcaad078f0e77d|6ec6b47d>` Merge pull request #126 from sewenthy/sewen/121-ignore-code-comments-from-defined-list-of-users - <https://github.com/Khady|Louis>\n\n\nmodified 6 files",
619+
"text": "`<https://github.com/sewenthy/monorobot/commit/858b5e1d2de2716883a7f83f69676cb1d05a6c9f|858b5e1d>` test: test for ignoring user comment on PR - Sewen Thy\n`<https://github.com/sewenthy/monorobot/commit/883724426505ec03e29a1e4fd11079797a30bd57|88372442>` cfg and action: add support to ignore comments from certain users - Sewen Thy\n`<https://github.com/sewenthy/monorobot/commit/6ec6b47d1f333d30d5c3889e05dcaad078f0e77d|6ec6b47d>` Merge pull request #126 from sewenthy/sewen/121-ignore-code-comments-from-defined-list-of-users - <https://github.com/Khady|Louis>\n\nmodified 6 files",
620620
"footer": "<https://github.com/sewenthy/monorobot|sewenthy/monorobot>"
621621
}
622622
}
@@ -631,7 +631,7 @@ will unfurl in #C047QTRD1CH
631631
"fallback": "[9d20f77f] test: added tests for link unfurling - Sewen Thy",
632632
"mrkdwn_in": [ "text" ],
633633
"color": "#f6f8fa",
634-
"text": "`<https://github.com/ahrefs/monorobot/commit/9d20f77fd7c79f5a00978ae91340603159921cb1|9d20f77f>` test: added tests for link unfurling - Sewen Thy\n\n\nmodified 14 files",
634+
"text": "`<https://github.com/ahrefs/monorobot/commit/9d20f77fd7c79f5a00978ae91340603159921cb1|9d20f77f>` test: added tests for link unfurling - Sewen Thy\n\nmodified 14 files",
635635
"footer": "<https://github.com/ahrefs/monorobot|ahrefs/monorobot>"
636636
}
637637
}
@@ -646,7 +646,7 @@ will unfurl in #C047QTRD1CH
646646
"fallback": "[0e222cde] use plaintext for all fallback messages - Yasunari Watanabe[46b04204] escape all user text and provide pretty-printing utility functions\n\nPR titles, comments, etc. should all be escaped. - Yasunari Watanabe[ee52fb2d] tests: promote with simple char escape check - Yasunari Watanabe",
647647
"mrkdwn_in": [ "text" ],
648648
"color": "#f6f8fa",
649-
"text": "`<https://github.com/ahrefs/monorobot/commit/0e222cdeeee469bf2109310d27d61a8afb86a118|0e222cde>` use plaintext for all fallback messages - <https://github.com/yasunariw|Yasunari Watanabe>\n`<https://github.com/ahrefs/monorobot/commit/46b04204b085fd1d2b8c15033deaa3be0a0f9936|46b04204>` escape all user text and provide pretty-printing utility functions - <https://github.com/yasunariw|Yasunari Watanabe>\n`<https://github.com/ahrefs/monorobot/commit/ee52fb2df818b3b46d81a3f5fa5de2c926987462|ee52fb2d>` tests: promote with simple char escape check - <https://github.com/yasunariw|Yasunari Watanabe>\n\n\nmodified 3 files",
649+
"text": "`<https://github.com/ahrefs/monorobot/commit/0e222cdeeee469bf2109310d27d61a8afb86a118|0e222cde>` use plaintext for all fallback messages - <https://github.com/yasunariw|Yasunari Watanabe>\n`<https://github.com/ahrefs/monorobot/commit/46b04204b085fd1d2b8c15033deaa3be0a0f9936|46b04204>` escape all user text and provide pretty-printing utility functions - <https://github.com/yasunariw|Yasunari Watanabe>\n`<https://github.com/ahrefs/monorobot/commit/ee52fb2df818b3b46d81a3f5fa5de2c926987462|ee52fb2d>` tests: promote with simple char escape check - <https://github.com/yasunariw|Yasunari Watanabe>\n\nmodified 3 files",
650650
"footer": "<https://github.com/ahrefs/monorobot|ahrefs/monorobot>"
651651
}
652652
}

0 commit comments

Comments
 (0)