Skip to content

Commit 69c8411

Browse files
committed
action, state: clean up when receive PR closed event
1 parent c0cddb0 commit 69c8411

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/action.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
271271
end
272272
| _ -> Lwt.return_unit
273273

274+
let cleanup_state (ctx : Context.t) (payload : Github.t) =
275+
match payload with
276+
| Github.Pull_request { action = Closed; pull_request = { number; _ }; repository = { url; _ }; _ } ->
277+
State.close_issue ctx.state url number
278+
| _ -> Lwt.return_unit
279+
274280
let process_github_notification (ctx : Context.t) headers body =
275281
let validate_signature secrets payload =
276282
let repo = Github.repo_of_notification payload in
@@ -300,6 +306,7 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
300306
( match ctx.state_filepath with
301307
| None -> Lwt.return_unit
302308
| Some path ->
309+
let%lwt () = cleanup_state ctx payload in
303310
( match%lwt State.save ctx.state path with
304311
| Ok () -> Lwt.return_unit
305312
| Error e -> action_error e

lib/state.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ let get_review_msg { state; _ } repo_url ~issue_num review_id =
6565
let close_issue { state; lock } repo_url issue_num =
6666
Lwt_mutex.with_lock lock @@ fun () ->
6767
let repo_state = find_or_add_repo' state repo_url in
68-
Stringtbl.remove repo_state.issue_tbl issue_num;
68+
Stringtbl.remove repo_state.issue_tbl (Int.to_string issue_num);
6969
Lwt.return_unit
7070

7171
let set_bot_user_id { state; _ } user_id = state.State_t.bot_user_id <- Some user_id

0 commit comments

Comments
 (0)