Skip to content
This repository was archived by the owner on Jul 14, 2020. It is now read-only.

Commit 1250b7c

Browse files
committed
fix: show review state in DM
1 parent a3d58ec commit 1250b7c

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/listener.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
StatusState,
1414
StatusWebhook
1515
} from './models/github';
16+
import { ReviewState } from './models/github/review-state';
1617
import { SlackAttachmentColor } from './models/slack';
1718

1819
if (!process.env.GITHUB_TOKEN) {
@@ -242,6 +243,18 @@ export const messenger = controller => {
242243
if (err) {
243244
console.error('failed to start private conversation', err);
244245
} else {
246+
let textSummary;
247+
switch (payload.review.state) {
248+
case ReviewState.APPROVED:
249+
textSummary = `:white_check_mark: *Approved*`;
250+
break;
251+
case ReviewState.COMMENTED:
252+
textSummary = `:eyes: *Commented*`;
253+
break;
254+
case ReviewState.REJECTED:
255+
textSummary = `:x: *Rejected*`;
256+
break;
257+
}
245258
convo.say({
246259
text: `Review ${payload.action} for *${payload.pull_request.base.repo.name}* by *${
247260
payload.sender.login
@@ -250,7 +263,7 @@ export const messenger = controller => {
250263
{
251264
title: `#${payload.pull_request.number}: ${payload.pull_request.title}`,
252265
title_link: payload.pull_request.html_url,
253-
text: payload.review.body,
266+
text: `${textSummary}\n${payload.review.body}`,
254267
mrkdwn_in: ['text']
255268
}
256269
]

src/models/github/pull-request-review-webhook.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { IssueState } from './issue-state';
22
import { Link } from './link';
33
import { Repository } from './repository';
4+
import { ReviewState } from './review-state';
45
import { Userish } from './userish';
56

67
export interface PullRequestReviewWebhook {
@@ -12,7 +13,7 @@ export interface PullRequestReviewWebhook {
1213
body: string;
1314
commit_id: string;
1415
submitted_at: string;
15-
state: 'commented' | string;
16+
state: ReviewState;
1617
html_url: string;
1718
pull_request_url: string;
1819
author_association: string;

src/models/github/review-state.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export enum ReviewState {
2+
APPROVED = 'approved',
3+
COMMENTED = 'commented',
4+
REJECTED = 'rejected'
5+
}

0 commit comments

Comments
 (0)