Skip to content

Commit b4a3742

Browse files
committed
do not attempt to close the main review for each pending reviewer
1 parent e41029c commit b4a3742

File tree

3 files changed

+69
-46
lines changed

3 files changed

+69
-46
lines changed

src/services/RequestService.ts

Lines changed: 63 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,55 +10,78 @@ import { App } from '@slack/bolt';
1010
import { reviewCloser } from '@/services/ReviewCloser';
1111
import log from '@utils/log';
1212

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);
1616

1717
export const declineRequest = moveOntoNextPerson('Thanks! You will keep your spot in the queue.');
1818

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+
);
2741

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+
});
2853
log.d(
2954
'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],
3169
);
70+
}
71+
return updatedReview;
72+
};
3273

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,
3584
);
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-
}
6285

6386
await requestNextUserReview(updatedReview, app.client);
6487

src/services/ReviewCloser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import { mention } from '@/utils/text';
44
import { App } from '@slack/bolt';
55
import { chatService } from '@/services/ChatService';
66
import { ActiveReview } from '@models/ActiveReview';
7-
import { expireRequest } from '@/services/RequestService';
7+
import { closeRequest } from '@/services/RequestService';
88

99
export const reviewCloser = {
1010
async closeReviewIfComplete(app: App, threadId: string): Promise<void> {
1111
const review = await activeReviewRepo.getReviewByThreadIdOrFail(threadId);
1212

1313
if (isCompleted(review)) {
1414
for (const user of review.pendingReviewers) {
15-
await expireRequest(app, review, user.userId);
15+
await closeRequest(app, review, user.userId);
1616
}
1717
await closeReview(
1818
app,

src/services/__tests__/reviewCloser.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import { reviewCloser } from '@/services/ReviewCloser';
88

99
jest.mock('@/services/RequestService', () => ({
1010
...jest.requireActual('@/services/RequestService'),
11-
expireRequest: jest.fn(),
11+
closeRequest: jest.fn(),
1212
}));
1313

14-
import { expireRequest } from '@/services/RequestService';
14+
import { closeRequest } from '@/services/RequestService';
1515

1616
describe('reviewCloser', () => {
1717
let app: App;
@@ -131,9 +131,9 @@ describe('reviewCloser', () => {
131131

132132
await reviewCloser.closeReviewIfComplete(app, threadId);
133133

134-
expect(expireRequest).toHaveBeenCalledTimes(pendingReviewers.length);
134+
expect(closeRequest).toHaveBeenCalledTimes(pendingReviewers.length);
135135
pendingReviewers.forEach(pendingReviewer => {
136-
expect(expireRequest).toHaveBeenCalledWith(app, review, pendingReviewer.userId);
136+
expect(closeRequest).toHaveBeenCalledWith(app, review, pendingReviewer.userId);
137137
});
138138

139139
// Verify the review is closed after expiring requests

0 commit comments

Comments
 (0)