@@ -317,32 +317,30 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
317
317
Lwt. return_none
318
318
in
319
319
let process link =
320
+ let with_gh_result_populate_slack (type a ) ~(api_result : (a, string) Result.t )
321
+ ~(populate : repository -> a -> Slack_t.message_attachment ) ~repo
322
+ =
323
+ match api_result with
324
+ | Error _ -> Lwt. return_none
325
+ | Ok item -> Lwt. return_some @@ (link, populate repo item)
326
+ in
320
327
match Github. gh_link_of_string link with
321
328
| None -> Lwt. return_none
322
329
| Some gh_link ->
323
330
match gh_link with
324
331
| Pull_request (repo , number ) ->
325
- ( match % lwt Github_api. get_pull_request ~ctx ~repo ~number with
326
- | Error _ -> Lwt. return_none
327
- | Ok pr -> Lwt. return_some @@ (link, Slack_message. populate_pull_request repo pr)
328
- )
332
+ let % lwt result = Github_api. get_pull_request ~ctx ~repo ~number in
333
+ with_gh_result_populate_slack ~api_result: result ~populate: Slack_message. populate_pull_request ~repo
329
334
| Issue (repo , number ) ->
330
- ( match % lwt Github_api. get_issue ~ctx ~repo ~number with
331
- | Error _ -> Lwt. return_none
332
- | Ok issue -> Lwt. return_some @@ (link, Slack_message. populate_issue repo issue)
333
- )
335
+ let % lwt result = Github_api. get_issue ~ctx ~repo ~number in
336
+ with_gh_result_populate_slack ~api_result: result ~populate: Slack_message. populate_issue ~repo
334
337
| Commit (repo , sha ) ->
335
- ( match % lwt Github_api. get_api_commit ~ctx ~repo ~sha with
336
- | Error _ -> Lwt. return_none
337
- | Ok commit -> Lwt. return_some @@ (link, Slack_message. populate_commit repo commit)
338
- )
339
- | Compare (repo , (base , merge )) ->
340
- ( match % lwt Github_api. get_compare ~ctx ~repo ~basehead: (base, merge) with
341
- | Error _ -> Lwt. return_none
342
- | Ok compare -> Lwt. return_some @@ (link, Slack_message. populate_compare repo compare)
343
- )
338
+ let % lwt result = Github_api. get_api_commit ~ctx ~repo ~sha in
339
+ with_gh_result_populate_slack ~api_result: result ~populate: Slack_message. populate_commit ~repo
340
+ | Compare (repo , basehead ) ->
341
+ let % lwt result = Github_api. get_compare ~ctx ~repo ~basehead in
342
+ with_gh_result_populate_slack ~api_result: result ~populate: Slack_message. populate_compare ~repo
344
343
in
345
-
346
344
let % lwt bot_user_id =
347
345
match State. get_bot_user_id ctx.state with
348
346
| Some id -> Lwt. return_some id
0 commit comments