Skip to content

Commit 9d11a69

Browse files
committed
refactor: 쓸모없는 Slack 라우터 제거
1 parent d786e46 commit 9d11a69

File tree

8 files changed

+140
-273
lines changed

8 files changed

+140
-273
lines changed

src/configs/db.config.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ const poolConfig: pg.PoolConfig = {
1616
max: 10, // 최대 연결 수
1717
idleTimeoutMillis: 30000, // 연결 유휴 시간 (30초)
1818
connectionTimeoutMillis: 5000, // 연결 시간 초과 (5초)
19+
ssl: false,
20+
// ssl: {
21+
// rejectUnauthorized: false,
22+
// },
1923
};
2024

21-
if (process.env.NODE_ENV === 'production') {
22-
poolConfig.ssl = {
23-
rejectUnauthorized: false,
24-
};
25-
}
25+
// if (process.env.NODE_ENV === 'production') {
26+
// poolConfig.ssl = {
27+
// rejectUnauthorized: false,
28+
// };
29+
// }
2630

2731
const pool = new Pool(poolConfig);
2832

src/controllers/slack.controller.ts

Lines changed: 0 additions & 165 deletions
This file was deleted.

src/controllers/webhook.controller.ts

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { NextFunction, Request, RequestHandler, Response } from 'express';
22
import { SlackService } from '@/services/slack.service';
33
import { SentryService } from '@/services/sentry.service';
44
import { SentryWebhookData, SlackMessage } from '@/types';
5+
import { SentryActionData, SentryApiAction } from '@/types/models/Sentry.type';
56
import logger from '@/configs/logger.config';
67
import { formatSentryIssueForSlack, createStatusUpdateMessage } from '@/utils/slack.util';
8+
import { getNewStatusFromAction } from '@/utils/sentry.util';
79

810
export class WebhookController {
911
constructor(
@@ -37,6 +39,51 @@ export class WebhookController {
3739
}
3840
};
3941

42+
handleSlackInteractive: RequestHandler = async (
43+
req: Request,
44+
res: Response,
45+
next: NextFunction,
46+
): Promise<void> => {
47+
try {
48+
const payload = JSON.parse(req.body.payload);
49+
50+
if (payload.type === 'interactive_message' && payload.actions && payload.actions[0]) {
51+
const action = payload.actions[0];
52+
53+
if (action.name === 'sentry_action') {
54+
const [actionType, issueId, organizationSlug, projectSlug] = action.value.split(':');
55+
56+
const actionData: SentryActionData = {
57+
action: actionType as SentryApiAction,
58+
issueId,
59+
organizationSlug,
60+
projectSlug,
61+
};
62+
63+
if (actionData.issueId && actionData.organizationSlug && actionData.projectSlug) {
64+
logger.info('Processing Sentry action:', actionData);
65+
66+
const result = await this.sentryService.handleIssueAction(actionData);
67+
68+
if (result.success) {
69+
const updatedMessage = this.createSuccessMessage(actionData, payload.original_message || {});
70+
res.json(updatedMessage);
71+
} else {
72+
const errorMessage = this.createErrorMessage(result.error || 'Unknown error', payload.original_message || {});
73+
res.json(errorMessage);
74+
}
75+
return;
76+
}
77+
}
78+
}
79+
80+
res.json({ text: '❌ 잘못된 요청입니다.' });
81+
} catch (error) {
82+
logger.error('Slack Interactive 처리 실패:', error instanceof Error ? error.message : '알 수 없는 오류');
83+
next(error);
84+
}
85+
};
86+
4087
private async formatSentryDataForSlack(sentryData: SentryWebhookData): Promise<SlackMessage | null> {
4188
const { action, data } = sentryData;
4289

@@ -106,4 +153,52 @@ export class WebhookController {
106153

107154
return formatSentryIssueForSlack(sentryData, this.sentryService.hasSentryToken());
108155
}
156+
157+
private createSuccessMessage(actionData: SentryActionData, originalMessage: unknown): unknown {
158+
const { action } = actionData;
159+
160+
const updatedMessage = JSON.parse(JSON.stringify(originalMessage));
161+
162+
if (updatedMessage.attachments && updatedMessage.attachments[0]) {
163+
const newStatus = getNewStatusFromAction(action);
164+
const statusColors = {
165+
'resolved': 'good',
166+
'ignored': 'warning',
167+
'archived': '#808080',
168+
'unresolved': 'danger',
169+
};
170+
171+
updatedMessage.attachments[0].color = statusColors[newStatus as keyof typeof statusColors] || 'good';
172+
173+
const statusMapping = {
174+
'resolved': 'RESOLVED',
175+
'ignored': 'IGNORED',
176+
'archived': 'ARCHIVED',
177+
'unresolved': 'UNRESOLVED',
178+
};
179+
180+
const statusText = statusMapping[newStatus as keyof typeof statusMapping] || newStatus.toUpperCase();
181+
updatedMessage.attachments[0].footer = `✅ ${statusText} | 처리 완료: ${new Date().toLocaleString('ko-KR', { timeZone: 'Asia/Seoul' })}`;
182+
183+
delete updatedMessage.attachments[0].actions;
184+
}
185+
186+
return updatedMessage;
187+
}
188+
189+
private createErrorMessage(error: string, originalMessage: unknown): unknown {
190+
const updatedMessage = JSON.parse(JSON.stringify(originalMessage));
191+
192+
if (updatedMessage.attachments && updatedMessage.attachments[0]) {
193+
updatedMessage.attachments[0].fields.push({
194+
title: '❌ 오류 발생',
195+
value: error,
196+
short: false,
197+
});
198+
199+
updatedMessage.attachments[0].color = 'danger';
200+
}
201+
202+
return updatedMessage;
203+
}
109204
}

src/routes/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import NotiRouter from './noti.router';
55
import LeaderboardRouter from './leaderboard.router';
66
import TotalStatsRouter from './totalStats.router';
77
import WebhookRouter from './webhook.router';
8-
import SlackRouter from './slack.router';
98

109

1110
const router: Router = express.Router();
@@ -20,7 +19,5 @@ router.use('/', NotiRouter);
2019
router.use('/', LeaderboardRouter);
2120
router.use('/', TotalStatsRouter);
2221
router.use('/', WebhookRouter);
23-
router.use('/', SlackRouter);
24-
2522

2623
export default router;

0 commit comments

Comments
 (0)