@@ -10,55 +10,78 @@ import { App } from '@slack/bolt';
10
10
import { reviewCloser } from '@/services/ReviewCloser' ;
11
11
import log from '@utils/log' ;
12
12
13
- export const expireRequest = moveOntoNextPerson (
14
- 'The request has expired. You will keep your spot in the queue.' ,
15
- ) ;
13
+ const expireMessage = 'The request has expired. You will keep your spot in the queue.' ;
14
+
15
+ export const expireRequest = moveOntoNextPerson ( expireMessage ) ;
16
16
17
17
export const declineRequest = moveOntoNextPerson ( 'Thanks! You will keep your spot in the queue.' ) ;
18
18
19
- /**
20
- * Notify the user if necessary, and request the next person in line
21
- */
22
- function moveOntoNextPerson ( closeMessage : string ) {
23
- return async ( app : App , activeReview : Readonly < ActiveReview > , previousUserId : string ) => {
24
- const updatedReview : ActiveReview = {
25
- ...activeReview ,
26
- } ;
19
+ export const closeRequest = async (
20
+ app : App ,
21
+ activeReview : Readonly < ActiveReview > ,
22
+ previousUserId : string ,
23
+ ) : Promise < ActiveReview > => {
24
+ return closeRequestInternal ( app , activeReview , previousUserId , expireMessage ) ;
25
+ } ;
26
+
27
+ const closeRequestInternal = async (
28
+ app : App ,
29
+ activeReview : Readonly < ActiveReview > ,
30
+ previousUserId : string ,
31
+ closeMessage : string ,
32
+ ) : Promise < ActiveReview > => {
33
+ const updatedReview : ActiveReview = {
34
+ ...activeReview ,
35
+ } ;
36
+
37
+ log . d (
38
+ 'requestService.moveOnToNextPerson' ,
39
+ `Moving on to next person for ${ activeReview . threadId } ` ,
40
+ ) ;
27
41
42
+ const priorPendingReviewer = updatedReview . pendingReviewers . find (
43
+ ( { userId } ) => userId === previousUserId ,
44
+ ) ;
45
+ if ( priorPendingReviewer ) {
46
+ updatedReview . pendingReviewers = updatedReview . pendingReviewers . filter (
47
+ ( { userId } ) => userId !== previousUserId ,
48
+ ) ;
49
+ updatedReview . declinedReviewers . push ( {
50
+ userId : previousUserId ,
51
+ declinedAt : new Date ( ) . getTime ( ) ,
52
+ } ) ;
28
53
log . d (
29
54
'requestService.moveOnToNextPerson' ,
30
- `Moving on to next person for ${ activeReview . threadId } ` ,
55
+ `Adding ${ previousUserId } to declined reviewers for ${ activeReview . threadId } ` ,
56
+ ) ;
57
+ await activeReviewRepo . update ( updatedReview ) ;
58
+ const contextBlock = requestBuilder . buildReviewSectionBlock (
59
+ { id : updatedReview . requestorId } ,
60
+ updatedReview . languages ,
61
+ DeadlineLabel . get ( updatedReview . dueBy ) || 'Unknown' ,
62
+ ) ;
63
+ const closeMessageBlock = textBlock ( closeMessage ) ;
64
+ await chatService . updateDirectMessage (
65
+ app . client ,
66
+ priorPendingReviewer . userId ,
67
+ priorPendingReviewer . messageTimestamp ,
68
+ [ contextBlock , closeMessageBlock ] ,
31
69
) ;
70
+ }
71
+ return updatedReview ;
72
+ } ;
32
73
33
- const priorPendingReviewer = updatedReview . pendingReviewers . find (
34
- ( { userId } ) => userId === previousUserId ,
74
+ /**
75
+ * Notify the user if necessary, and request the next person in line
76
+ */
77
+ function moveOntoNextPerson ( closeMessage : string ) {
78
+ return async ( app : App , activeReview : Readonly < ActiveReview > , previousUserId : string ) => {
79
+ const updatedReview = await closeRequestInternal (
80
+ app ,
81
+ activeReview ,
82
+ previousUserId ,
83
+ closeMessage ,
35
84
) ;
36
- if ( priorPendingReviewer ) {
37
- updatedReview . pendingReviewers = updatedReview . pendingReviewers . filter (
38
- ( { userId } ) => userId !== previousUserId ,
39
- ) ;
40
- updatedReview . declinedReviewers . push ( {
41
- userId : previousUserId ,
42
- declinedAt : new Date ( ) . getTime ( ) ,
43
- } ) ;
44
- log . d (
45
- 'requestService.moveOnToNextPerson' ,
46
- `Adding ${ previousUserId } to declined reviewers for ${ activeReview . threadId } ` ,
47
- ) ;
48
- await activeReviewRepo . update ( updatedReview ) ;
49
- const contextBlock = requestBuilder . buildReviewSectionBlock (
50
- { id : updatedReview . requestorId } ,
51
- updatedReview . languages ,
52
- DeadlineLabel . get ( updatedReview . dueBy ) || 'Unknown' ,
53
- ) ;
54
- const closeMessageBlock = textBlock ( closeMessage ) ;
55
- await chatService . updateDirectMessage (
56
- app . client ,
57
- priorPendingReviewer . userId ,
58
- priorPendingReviewer . messageTimestamp ,
59
- [ contextBlock , closeMessageBlock ] ,
60
- ) ;
61
- }
62
85
63
86
await requestNextUserReview ( updatedReview , app . client ) ;
64
87
0 commit comments