Skip to content

Commit

Permalink
Merge pull request #2872 from Northeastern-Electric-Racing/#2501-add-…
Browse files Browse the repository at this point in the history
…reviewers-comment-to-slack-message

#2501 add reviewers comment to slack message
  • Loading branch information
walker-sean authored Nov 14, 2024
2 parents ba0c47a + 3d8ff30 commit 4c4ab80
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
10 changes: 4 additions & 6 deletions src/backend/src/services/change-requests.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ export default class ChangeRequestsService {
} else if (foundCR.type === CR_Type.ACTIVATION && foundCR.activationChangeRequest && accepted) {
await this.reviewActivationChangeRequest(foundCR, reviewer);
}

// finally we can update change request
const updated = await prisma.change_Request.update({
where: { crId },
Expand All @@ -143,14 +142,13 @@ export default class ChangeRequestsService {
dateReviewed: new Date()
},
include: {
activationChangeRequest: true,
notificationSlackThreads: true,
wbsElement: { include: { workPackage: true } }
...getChangeRequestQueryArgs(organization.organizationId).include,
notificationSlackThreads: true
}
});

// send the creator of the cr a slack notification that their cr was reviewed
await sendCRSubmitterReviewedNotification(foundCR);
// send a notification to the submitter that their change request has been reviewed
await sendCRSubmitterReviewedNotification(updated);

// send a reply to a CR's notifications of its updated status
await sendSlackCRStatusToThread(updated.notificationSlackThreads, foundCR.crId, foundCR.identifier, accepted);
Expand Down
7 changes: 6 additions & 1 deletion src/backend/src/utils/change-requests.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,12 @@ export const sendCRSubmitterReviewedNotification = async (
const creatorUserSettings = await prisma.user_Settings.findUnique({ where: { userId: foundCR.submitterId } });
if (creatorUserSettings && creatorUserSettings.slackId) {
try {
await sendSlackCRReviewedNotification(creatorUserSettings.slackId, foundCR.crId, foundCR.identifier);
await sendSlackCRReviewedNotification(
creatorUserSettings.slackId,
foundCR.crId,
foundCR.identifier,
foundCR.reviewNotes
);
} catch (err: unknown) {
if (err instanceof Error) {
throw new HttpException(500, `Failed to send slack notification: ${err.message}`);
Expand Down
11 changes: 9 additions & 2 deletions src/backend/src/utils/slack.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,17 @@ export const sendDRScheduledSlackNotif = async (
}
};

export const sendSlackCRReviewedNotification = async (slackId: string, crId: string, identifier: number) => {
export const sendSlackCRReviewedNotification = async (
slackId: string,
crId: string,
identifier: number,
comments: string | null
) => {
if (process.env.NODE_ENV !== 'production') return; // don't send msgs unless in prod
const msgs = [];
const fullMsg = `:tada: Your Change Request was just reviewed! Click the link to view! :tada:`;
const fullMsg = `:tada: Your Change Request was just reviewed!${
comments ? `\n Comments: ${comments}` : ''
}\nClick the link to view! :tada:`;
const fullLink = `https://finishlinebyner.com/cr/${crId}`;
const btnText = `View CR#${identifier}`;
msgs.push(sendMessage(slackId, fullMsg, fullLink, btnText));
Expand Down

0 comments on commit 4c4ab80

Please sign in to comment.