Skip to content

Commit cb15ebd

Browse files
Merge pull request #183 from EmileTrotignon/error-log-in-notification-fixes
Error log in notification fixes
2 parents 51bcfcf + 679363d commit cb15ebd

File tree

5 files changed

+15
-25
lines changed

5 files changed

+15
-25
lines changed

lib/action.ml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) (Buildkite_api :
322322
| Error e -> Lwt.return_error e
323323
| Ok build ->
324324
let failed_jobs = Util.Build.filter_failed_jobs build.jobs in
325-
let%lwt logs_or_errors = Lwt_list.map_p (get_job_log_name_and_content ~ctx n) failed_jobs in
325+
let%lwt logs_or_errors = Lwt_list.map_s (get_job_log_name_and_content ~ctx n) failed_jobs in
326326
Lwt.return_ok
327327
@@ List.filter_map
328328
(function
@@ -387,7 +387,6 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) (Buildkite_api :
387387
let%lwt failed_steps = new_failed_steps ~get_build:(Buildkite_api.get_build ~ctx) n repo_state in
388388
Lwt.return_some failed_steps
389389
in
390-
391390
let%lwt job_log =
392391
match cfg.include_logs_in_notifs with
393392
| false -> Lwt.return []
@@ -447,11 +446,10 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) (Buildkite_api :
447446
(match handler with
448447
| None -> Lwt.return_unit
449448
| Some handler ->
450-
(try%lwt
451-
match%lwt handler res with
452-
| Result.Error e -> handler_error e
453-
| Ok () -> Lwt.return_unit
454-
with exn -> handler_error (Printexc.to_string exn)))
449+
(match%lwt handler res with
450+
| Result.Error e -> handler_error e
451+
| Ok () -> Lwt.return_unit
452+
| exception exn -> handler_error (Printexc.to_string exn)))
455453
| Ok None -> Lwt.return_unit
456454
| Error e -> action_error e
457455
in

lib/api_remote.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ module Slack : Api.Slack = struct
256256
| Ok { Slack_t.upload_url; file_id } ->
257257
(match%lwt post_file_content ~upload_url ~filename:name ~content with
258258
| Error e -> Lwt.return_error e
259-
| Ok () -> Lwt.return_ok ({ id = file_id; title } : Slack_t.file_v2))
259+
| Ok () -> Lwt.return_ok ({ id = file_id; title } : Slack_t.file))
260260

261261
let complete_upload_external ~(ctx : Context.t) ?channel_id ?thread_ts ?initial_comment files =
262262
let name = "complete_upload_external" in

lib/slack.atd

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -171,29 +171,22 @@ type upload_url_res = {
171171
file_id: string;
172172
}
173173

174-
type file_v2 = {
174+
type file = {
175175
id: string;
176176
?title: string nullable;
177177
}
178178

179-
type files_v2 = file_v2 list
179+
type files = file list
180180

181181
type complete_upload_external_req = {
182-
files: files_v2;
182+
files: files;
183183
?channel_id: channel_id nullable;
184184
?thread_ts: timestamp nullable;
185185
?initial_comment: string nullable;
186186
}
187187

188-
type complete_upload_external_file_res = {
189-
url_private: string;
190-
url_private_download: string;
191-
permalink: string;
192-
permalink_public: string;
193-
}
194-
195188
type complete_upload_external_res = {
196-
files: files_v2;
189+
files: files;
197190
}
198191

199192
type join_channel_req = {

lib/slack.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,17 +438,17 @@ let generate_status_notification ?slack_user_id ?failed_steps ~(job_log : (strin
438438
let handler =
439439
match job_log with
440440
| [] -> None
441-
| _ :: _ when is_failed_build_notification ->
441+
| _ :: _ when Status_notification.is_user channel ->
442442
let files =
443443
job_log
444444
|> List.map (fun (job_name, job_log) ->
445445
{ name = job_name; title = None; alt_txt = None; content = reply_of_log job_log })
446446
in
447447
Some
448-
(fun (upload_file : file:file_req -> (unit, string) result Lwt.t) (res : Slack_t.post_message_res) ->
448+
(fun (send_file : file:file_req -> (unit, string) result Lwt.t) (res : Slack_t.post_message_res) ->
449449
let ({ ts; channel; _ } : post_message_res) = res in
450450
let file = { files; channel_id = Some channel; initial_comment = None; thread_ts = Some ts } in
451-
upload_file ~file)
451+
send_file ~file)
452452
| _ -> None
453453
in
454454
make_message ~text:summary ~attachments:[ attachment ] ?handler

lib/util.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,8 @@ module Build = struct
342342

343343
let filter_failed_jobs jobs =
344344
List.filter_map
345-
(fun (job : Buildkite_t.job_type) ->
346-
match job with
347-
| Script ({ state = Failed; _ } as job) | Trigger ({ state = Failed; _ } as job) -> Some job
345+
(function
346+
| Buildkite_t.Script ({ state = Failed; _ } as job) | Trigger ({ state = Failed; _ } as job) -> Some job
348347
| _ -> None)
349348
jobs
350349
end

0 commit comments

Comments
 (0)