File tree Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -238,6 +238,23 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
238
238
Lwt. return_unit
239
239
240
240
let process_link_shared_event (ctx : Context.t ) (event : Slack_t.link_shared_event ) =
241
+ let fetch_bot_user_id () =
242
+ match % lwt Slack_api. send_auth_test ~ctx () with
243
+ | Ok { user_id; _ } ->
244
+ ctx.state.bot_user_id < - Some user_id;
245
+ let % lwt () =
246
+ Option. value_map ctx.state_filepath ~default: Lwt. return_unit ~f: (fun path ->
247
+ match % lwt State. save ctx.state path with
248
+ | Ok () -> Lwt. return_unit
249
+ | Error msg ->
250
+ log#error " %s" msg;
251
+ Lwt. return_unit)
252
+ in
253
+ Lwt. return_some user_id
254
+ | Error msg ->
255
+ log#error " %s" msg;
256
+ Lwt. return_none
257
+ in
241
258
let process link =
242
259
match Github. gh_link_of_string link with
243
260
| None -> Lwt. return_none
@@ -259,7 +276,14 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
259
276
| Ok commit -> Lwt. return_some @@ (link, Slack_message. populate_commit repo commit)
260
277
)
261
278
in
279
+ let % lwt bot_user_id =
280
+ match ctx.state.bot_user_id with
281
+ | Some id -> Lwt. return_some id
282
+ | None -> fetch_bot_user_id ()
283
+ in
262
284
if List. length event.links > 2 then Lwt. return " ignored: more than two links present"
285
+ else if Option. value_map bot_user_id ~default: false ~f: (String. equal event.user) then
286
+ Lwt. return " ignored: is bot user"
263
287
else begin
264
288
let links = List. map event.links ~f: (fun l -> l.url) in
265
289
let % lwt unfurls = List. map links ~f: process |> Lwt. all |> Lwt. map List. filter_opt |> Lwt. map StringMap. of_list in
Original file line number Diff line number Diff line change @@ -11,5 +11,6 @@ type pipeline_statuses = branch_statuses map_as_object
11
11
12
12
(* The serializable runtime state of the bot *)
13
13
type state = {
14
- pipeline_statuses <ocaml mutable>: pipeline_statuses
14
+ pipeline_statuses <ocaml mutable>: pipeline_statuses;
15
+ ?bot_user_id <ocaml mutable>: string nullable;
15
16
}
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ open Base
2
2
open Common
3
3
open Devkit
4
4
5
- let empty : State_t.state = { pipeline_statuses = StringMap. empty }
5
+ let empty : State_t.state = { pipeline_statuses = StringMap. empty; bot_user_id = None }
6
6
7
7
let refresh_pipeline_status (state : State_t.state ) ~pipeline ~(branches : Github_t.branch list ) ~status =
8
8
let update_pipeline_status branch_statuses =
You can’t perform that action at this time.
0 commit comments