-
Notifications
You must be signed in to change notification settings - Fork 0
feat [github, slack-blocks, mumu]: PR 리뷰 재요청 Slack 알림 추가 #33
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 all commits
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 |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { z } from "zod"; | ||
|
|
||
| export const pullRequestReviewRequestedSchema = z.object({ | ||
| action: z.enum(["review_requested"]), | ||
| sender: z.object({ login: z.string() }), | ||
| requested_reviewer: z.object({ login: z.string() }), | ||
| pull_request: z.object({ | ||
| number: z.number(), | ||
| title: z.string(), | ||
| html_url: z.string(), | ||
| }), | ||
| repository: z.object({ full_name: z.string() }), | ||
| }); | ||
|
|
||
| export type PullRequestReviewRequested = z.infer<typeof pullRequestReviewRequestedSchema>; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import type { PullRequestReviewRequested } from "@makers-devops/github"; | ||
| import type { KnownBlock } from "@slack/types"; | ||
| import type { SlackBlockPayload } from "../types"; | ||
|
|
||
| export type PR리뷰재요청Options = { | ||
| senderId: string; | ||
| reviewerId: string; | ||
| }; | ||
|
|
||
| export const blocks = (payload: PullRequestReviewRequested, options: PR리뷰재요청Options): KnownBlock[] => { | ||
| const { pull_request } = payload; | ||
| const { html_url: prUrl, number: prNumber, title } = pull_request; | ||
|
|
||
| const senderMention = `<@${options.senderId}>`; | ||
| const reviewerMention = `<@${options.reviewerId}>`; | ||
|
|
||
| return [ | ||
| { | ||
| type: "section", | ||
| text: { | ||
| type: "mrkdwn", | ||
| text: `*[${senderMention}]이 [${reviewerMention}]님에게 리뷰를 다시 요청했어요!* 🙏🏻`, | ||
| }, | ||
| }, | ||
| { | ||
| type: "section", | ||
| text: { | ||
| type: "mrkdwn", | ||
| text: `> *PR:* <${prUrl}|#${prNumber} ${title}>`, | ||
| }, | ||
| }, | ||
|
Comment on lines
+25
to
+31
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. 처음 스레드가 만들어질 때 PR과 PR번호, 제목이 보이는데 스레드에 코멘트가 쌓였을 때 상단으로 이동하지 않고 바로 확인하기 위해서 넣은건가욥?? Just Wonder! |
||
| ]; | ||
| }; | ||
|
|
||
| export const fallbackText = (payload: PullRequestReviewRequested): string => { | ||
| const { number, title } = payload.pull_request; | ||
| return `PR #${number}: ${title} - 리뷰 재요청`; | ||
| }; | ||
|
|
||
| export const slackPayload = (payload: PullRequestReviewRequested, options: PR리뷰재요청Options): SlackBlockPayload => ({ | ||
| text: fallbackText(payload), | ||
| blocks: blocks(payload, options), | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| export type { SlackBlockPayload } from "./types"; | ||
| export type { PR열림Options } from "./PR/PR_열림"; | ||
| export type { PR리뷰재요청Options } from "./PR/PR_재리뷰"; | ||
| export type { 리뷰요청Options } from "./피그마/리뷰_요청"; | ||
|
|
||
| export * as PR_열림 from "./PR/PR_열림"; | ||
| export * as PR_닫힘 from "./PR/PR_닫힘"; | ||
| export * as PR_리뷰 from "./PR/PR_리뷰"; | ||
| export * as PR_재리뷰 from "./PR/PR_재리뷰"; | ||
|
|
||
| export * as 피그마_리뷰_요청 from "./피그마/리뷰_요청"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| import { createSlackThread, findSlackThread, slackClient } from "@makers-devops/slack"; | ||
| import { getPullRequestThreadKey } from "./key"; | ||
| import type { PullRequest, PullRequestReviewComment } from "@makers-devops/github"; | ||
| import type { PullRequest, PullRequestReviewComment, PullRequestReviewRequested } from "@makers-devops/github"; | ||
| import { CHANNELS } from "../constant"; | ||
| import { PR_리뷰, PR_열림 } from "@makers-devops/slack-blocks"; | ||
| import type { PR열림Options } from "@makers-devops/slack-blocks"; | ||
| import { PR_리뷰, PR_열림, PR_재리뷰 } from "@makers-devops/slack-blocks"; | ||
| import type { PR열림Options, PR리뷰재요청Options } from "@makers-devops/slack-blocks"; | ||
|
|
||
| /** PR에 대한 스레드를 생성합니다. */ | ||
| export const createPullRequestThread = async (pull: PullRequest, options: PR열림Options) => { | ||
|
|
@@ -50,3 +50,39 @@ export const createPullRequestReviewCommentReply = async (comment: PullRequestRe | |
| } | ||
| return null; | ||
| }; | ||
|
|
||
| /** PR 스레드에 리뷰 재요청 reply를 생성합니다. */ | ||
| export const createPullRequestReRequestedReply = async ( | ||
|
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. 이 함수가 바로 위의 |
||
| payload: PullRequestReviewRequested, | ||
| options: PR리뷰재요청Options, | ||
| ) => { | ||
| const key = getPullRequestThreadKey(payload); | ||
| const thread = await findSlackThread(key); | ||
|
|
||
| if (!thread) { | ||
| console.error(`${key}: Slack thread not found`); | ||
| return null; | ||
| } | ||
|
|
||
| try { | ||
| const response = await slackClient.chat.postMessage({ | ||
| channel: thread.channel, | ||
| thread_ts: thread.thread_ts, | ||
| ...PR_재리뷰.slackPayload(payload, options), | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| console.error(`${key}: Slack thread reply failed`); | ||
| return null; | ||
| } | ||
|
|
||
| return { | ||
| id: key, | ||
| channel: thread.channel, | ||
| thread_ts: response.ts, | ||
| }; | ||
| } catch { | ||
| console.error(`${key}: Slack thread reply failed`); | ||
| } | ||
| return null; | ||
| }; | ||
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.
예전에 주용님 리뷰에도 달았던건데, blocks가 뭘 의미하는건가요?