Skip to content

Commit

Permalink
fix: fix slack message edition and reaction
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehurpeau committed Dec 19, 2022
1 parent c94c102 commit 8d4054f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/events/pr-handlers/reviewRequestRemoved.ts
Expand Up @@ -198,7 +198,7 @@ export default function reviewRequestRemoved(
const message = sentMessageRequestedReview.message;
await Promise.all([
repoContext.slack.updateMessage(
sentMessageRequestedReview.account,
sentTo.user,
sentTo.ts,
sentTo.channel,
{
Expand All @@ -210,7 +210,7 @@ export default function reviewRequestRemoved(
},
),
repoContext.slack.addReaction(
sentMessageRequestedReview.account,
sentTo.user,
sentTo.ts,
sentTo.channel,
'skull_and_crossbones',
Expand Down
1 change: 1 addition & 0 deletions src/events/pr-handlers/reviewRequested.ts
Expand Up @@ -117,6 +117,7 @@ export default function reviewRequested(
message,
requestedTeam ? requestedTeam.id : undefined,
);

if (result) {
await appContext.mongoStores.slackSentMessages.insertOne({
type: 'review-requested',
Expand Down
54 changes: 29 additions & 25 deletions src/events/pr-handlers/reviewSubmitted.ts
Expand Up @@ -176,37 +176,41 @@ export default function reviewSubmitted(
repoContext.slack.updateHome(reviewer.login);

const sentMessageRequestedReview =
await appContext.mongoStores.slackSentMessages.findOne({
'account.id': repoContext.accountEmbed.id,
'account.type': repoContext.accountEmbed.type,
type: 'review-requested',
typeId: `${pullRequest.id}_${reviewer.id}`,
});
await appContext.mongoStores.slackSentMessages.findOne(
{
'account.id': repoContext.accountEmbed.id,
'account.type': repoContext.accountEmbed.type,
type: 'review-requested',
typeId: `${pullRequest.id}_${reviewer.id}`,
},
{ created: -1 },
);

const emoji = getEmojiFromState(state);

if (sentMessageRequestedReview) {
const sentTo = sentMessageRequestedReview.sentTo[0];
const message = sentMessageRequestedReview.message;
await Promise.all([
repoContext.slack.updateMessage(
sentMessageRequestedReview.account,
sentTo.ts,
sentTo.channel,
{
...message,
text: message.text
.split('\n')
.map((l) => `~${l}~`)
.join('\n'),
},
),
repoContext.slack.addReaction(
sentMessageRequestedReview.account,
sentTo.ts,
sentTo.channel,
emoji,
),
...sentMessageRequestedReview.sentTo.map((sentTo) => [
repoContext.slack.updateMessage(
sentTo.user,
sentTo.ts,
sentTo.channel,
{
...message,
text: message.text
.split('\n')
.map((l) => `~${l}~`)
.join('\n'),
},
),
repoContext.slack.addReaction(
sentTo.user,
sentTo.ts,
sentTo.channel,
emoji,
),
]),
appContext.mongoStores.slackSentMessages.deleteOne(
sentMessageRequestedReview,
),
Expand Down

0 comments on commit 8d4054f

Please sign in to comment.