-
Notifications
You must be signed in to change notification settings - Fork 0
feat [mumu]: issue_comment 핸들러 추가 및 코멘트 핸들러 통합 #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import { redisStorage } from "../redis"; | ||
| import type { SlackNotifier } from "../slack"; | ||
| import type { SlackThread } from "../types"; | ||
| import type { PullRequestReviewComment } from "./schema"; | ||
| import type { Comment } from "./schema"; | ||
|
|
||
| const MAX_CHARS = 200; | ||
|
|
||
|
|
@@ -14,18 +14,31 @@ const truncateBody = (body: string): string => { | |
| const escapeSlackLinkText = (text: string): string => | ||
| text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """); | ||
|
|
||
| export const handlePullRequestReviewComment = async ( | ||
| payload: PullRequestReviewComment, | ||
| slackNotifier: SlackNotifier, | ||
| ) => { | ||
| function buildCommentMessage(payload: Comment): string { | ||
| const preview = truncateBody(payload.comment.body); | ||
| const safePreview = escapeSlackLinkText(preview); | ||
|
|
||
| return [`> *${payload.comment.user.login}*`, `> <${payload.comment.html_url}|${safePreview}>`].join("\n"); | ||
| } | ||
|
|
||
| export const handleComment = async (payload: Comment, slackNotifier: SlackNotifier): Promise<string> => { | ||
| if (payload.action !== "created") { | ||
| return JSON.stringify({ success: false, message: "Review comment action skipped." }); | ||
| return JSON.stringify({ success: false, message: "Comment action skipped." }); | ||
| } | ||
|
|
||
| const repoFullName = payload.repository.full_name; | ||
| const prNumber = payload.pull_request.number; | ||
| const cacheKey = `${repoFullName}#${prNumber}`; | ||
| let prNumber: number; | ||
|
|
||
| if ("issue" in payload) { | ||
| if (!payload.issue.pull_request) { | ||
| return JSON.stringify({ success: false, message: "Issue comment (not PR); skipped." }); | ||
| } | ||
| prNumber = payload.issue.number; | ||
| } else { | ||
| prNumber = payload.pull_request.number; | ||
| } | ||
|
|
||
| const cacheKey = `${repoFullName}#${prNumber}`; | ||
| const thread = await redisStorage.get<SlackThread>(cacheKey); | ||
|
|
||
| if (!thread?.threadTs) { | ||
|
|
@@ -35,15 +48,13 @@ export const handlePullRequestReviewComment = async ( | |
| }); | ||
| } | ||
|
|
||
| const preview = truncateBody(payload.comment.body); | ||
| const safePreview = escapeSlackLinkText(preview); | ||
| const text = [`> *${payload.comment.user.login}*`, `> <${payload.comment.html_url}|${safePreview}>`].join("\n"); | ||
| const text = buildCommentMessage(payload); | ||
|
|
||
| try { | ||
| await slackNotifier.createThreadReply(thread.threadTs, text); | ||
| } catch { | ||
| console.error(`${cacheKey}/${thread.channel}: review comment 슬랙 스레드 답변 전송 실패`); | ||
| console.error(`${cacheKey}/${thread.channel}: 슬랙 스레드 답변 전송 실패`); | ||
| } | ||
|
|
||
| return JSON.stringify({ success: true, message: "Review comment processed successfully" }); | ||
| return JSON.stringify({ success: true, message: "Comment processed successfully" }); | ||
|
Comment on lines
53
to
+60
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 아니에요! 요건 사실 저번에도 비슷한 리뷰를 받았었는데요. 어느 계층에서 로그를 남길것이냐를 고민하다가 저런 식으로 작성되었는데,
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,9 @@ import { z } from "zod"; | |
|
|
||
| export type PullRequest = z.infer<typeof pullRequestSchema>; | ||
| export type PullRequestReviewComment = z.infer<typeof pullRequestReviewCommentSchema>; | ||
| export type IssueComment = z.infer<typeof issueCommentSchema>; | ||
|
|
||
| export type Comment = z.infer<typeof commentSchema>; | ||
|
|
||
| export const pullRequestSchema = z.object({ | ||
| action: z.string(), | ||
|
|
@@ -44,3 +47,19 @@ export const pullRequestReviewCommentSchema = z.object({ | |
| }), | ||
| repository: z.object({ full_name: z.string() }), | ||
| }); | ||
|
|
||
| export const issueCommentSchema = z.object({ | ||
| action: z.enum(["created", "edited", "deleted"]), | ||
| issue: z.object({ | ||
| number: z.number(), | ||
| pull_request: z.object({}).passthrough().optional(), | ||
|
||
| }), | ||
| comment: z.object({ | ||
| body: z.string(), | ||
| html_url: z.string(), | ||
| user: z.object({ login: z.string() }), | ||
| }), | ||
| repository: z.object({ full_name: z.string() }), | ||
| }); | ||
|
|
||
| export const commentSchema = z.union([pullRequestReviewCommentSchema, issueCommentSchema]); | ||


Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issueComment랑 reviewComment가 구분이 따로 안되고 있는 것 같은데 일부러 이렇게 구현하신걸까요 ? 아니시라면 앞에 [issueComment], [reviewComment] 이런식으로 붙여서 구분하는 건 어떻게 생각하시나요...? Just 개인적인 의견입니당....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네네 사실 issue 코멘트랑 review 코멘트를 구분할 필요성을 못느꼈어서 따로 처리해두지는 않았습니다.
혜린님이 생각하신 구분되어야 할 이유가 혹시 무엇일까요 ?!