diff --git a/src/github/handler.ts b/src/github/handler.ts index dbaa38f5..0c1805db 100644 --- a/src/github/handler.ts +++ b/src/github/handler.ts @@ -12,8 +12,12 @@ import { error, json } from '@/api/utils/response'; import Environment from '@/env'; import { Logger } from '@/utils/logger'; -import { getTemplates, StopHandleError } from './templates'; -import type { Context, IHasSender, TemplateRenderResult } from './types'; +import { + getTemplates, + StopHandleError, + TemplateRenderResult, +} from './templates'; +import type { Context, IHasSender } from './types'; export class ValidationError extends Error { constructor(public statusCode: number, message: string) { diff --git a/src/github/templates/comment.ts b/src/github/templates/comment.ts index 78400180..cdb39aa7 100644 --- a/src/github/templates/comment.ts +++ b/src/github/templates/comment.ts @@ -3,13 +3,13 @@ import { Repository, User } from '@octokit/webhooks-types'; import { StringBuilder } from '@/utils/string-builder'; -import { ExtractPayload, Context, TemplateRenderResult } from '../types'; +import { ExtractPayload, Context } from '../types'; import { Name, NameBlock } from './prOrIssue'; import { StopHandleError, + TemplateRenderResult, limitLine, - renderPrOrIssueLink, renderPrOrIssueTitleLink, textTpl, useRef, @@ -90,6 +90,7 @@ function renderComment( target: renderPrOrIssueTitleLink(data), title: `{{sender | link:sender}} ${action} [comment](${comment.html_url}) on [${location}](${data.html_url})`, body: renderCommentBody(payload.comment), + compactTitle: `{{sender | link:sender}} ${action} [comment](${data.html_url}): \n`, doNotRenderBody, }, ctx, @@ -196,6 +197,7 @@ export async function handleReviewComment( target: '{{pull_request|link}}', title: `{{sender | link:sender}} ${action} [review comment](${comment.html_url}) on [pull request](${pr.html_url})`, body: renderCommentBody(payload.comment), + compactTitle: `{{sender | link}} ${action} [review comment](${comment.html_url}): \n`, }, ctx, ); diff --git a/src/github/templates/index.ts b/src/github/templates/index.ts index af947499..394ee480 100644 --- a/src/github/templates/index.ts +++ b/src/github/templates/index.ts @@ -1,6 +1,6 @@ import pick from 'lodash/pick'; -import { Context, TemplateRenderResult } from '@/github/types'; +import { Context } from '@/github/types'; import { handleCommitComment, @@ -12,6 +12,7 @@ import { handleDiscussion, handleIssue, handlePr } from './prOrIssue'; import { handleRelease } from './release'; import { handleReview } from './review'; import { handleStar } from './star'; +import { TemplateRenderResult } from './utils'; import { handleWorkflowRun } from './workflow'; export * from './utils'; diff --git a/src/github/templates/prOrIssue.ts b/src/github/templates/prOrIssue.ts index 5d4d523f..83105c0d 100644 --- a/src/github/templates/prOrIssue.ts +++ b/src/github/templates/prOrIssue.ts @@ -2,12 +2,7 @@ import { Issue, PullRequest, Discussion } from '@octokit/webhooks-types'; import { StringBuilder } from '@/utils/string-builder'; -import { - ExtractPayload, - THasChanges, - Context, - TemplateRenderResult, -} from '../types'; +import { ExtractPayload, THasChanges, Context } from '../types'; import { renderPrOrIssueTitleLink, @@ -19,6 +14,7 @@ import { renderRequestedReviewersInfo, textTpl, prettyUnderlineWord, + TemplateRenderResult, } from './utils'; export type Name = 'issues' | 'pull_request' | 'discussion'; diff --git a/src/github/templates/release.ts b/src/github/templates/release.ts index 9a2e5b94..faf81030 100644 --- a/src/github/templates/release.ts +++ b/src/github/templates/release.ts @@ -1,9 +1,9 @@ import { StringBuilder } from '@/utils/string-builder'; -import { Context, ExtractPayload, TemplateRenderResult } from '../types'; +import { Context, ExtractPayload } from '../types'; import { replaceGitHubUrlToMarkdown } from '../utils'; -import { textTpl } from '.'; +import { TemplateRenderResult, textTpl } from './utils'; export async function handleRelease( payload: ExtractPayload<'release'>, diff --git a/src/github/templates/review.ts b/src/github/templates/review.ts index e6f7645a..e56212e2 100644 --- a/src/github/templates/review.ts +++ b/src/github/templates/review.ts @@ -1,6 +1,6 @@ -import { Context, ExtractPayload, TemplateRenderResult } from '../types'; +import { Context, ExtractPayload } from '../types'; -import { StopHandleError, textTpl } from './utils'; +import { StopHandleError, textTpl, TemplateRenderResult } from './utils'; export async function handleReview( payload: ExtractPayload<'pull_request_review'>, diff --git a/src/github/templates/star.ts b/src/github/templates/star.ts index ee41be0f..ac75321a 100644 --- a/src/github/templates/star.ts +++ b/src/github/templates/star.ts @@ -1,7 +1,7 @@ import { render } from '../renderer'; -import { ExtractPayload, TemplateRenderResult } from '../types'; +import { ExtractPayload } from '../types'; -import { StopHandleError } from './utils'; +import { StopHandleError, TemplateRenderResult } from './utils'; export async function handleStar( payload: ExtractPayload<'star'>, diff --git a/src/github/templates/utils.ts b/src/github/templates/utils.ts index 1584a5ea..5d6acaa4 100644 --- a/src/github/templates/utils.ts +++ b/src/github/templates/utils.ts @@ -3,8 +3,6 @@ import capitalize from 'lodash/capitalize'; import { StringBuilder, limitTextByPosition } from '@/utils/string-builder'; import { render } from '../renderer'; -import { Context } from '../types'; -import { replaceGitHubText } from '../utils'; export function renderRepoLink(repository: { name: string; html_url: string }) { return `[[${repository.name}]](${repository.html_url})`; @@ -227,6 +225,12 @@ export type TextTplInput = { autoRef?: boolean; }; +export type TemplateRenderResult = { + title: string; + text: string; + compactText?: string; +}; + type TextTpl = ( data: TextTplInput, ctx?: { @@ -239,11 +243,7 @@ type TextTpl = ( afterRender?: (result: string) => string; }; }, -) => { - title: string; - text: string; - compactText?: string; -}; +) => TemplateRenderResult; export type HandlerResult = { text: TextTplInput; diff --git a/src/github/templates/workflow.ts b/src/github/templates/workflow.ts index 77d3d9b6..1b1ecb20 100644 --- a/src/github/templates/workflow.ts +++ b/src/github/templates/workflow.ts @@ -2,9 +2,9 @@ import { Octokit } from '@octokit/rest'; import { StringBuilder } from '@/utils/string-builder'; -import { Context, ExtractPayload, TemplateRenderResult } from '../types'; +import { Context, ExtractPayload } from '../types'; -import { textTpl, StopHandleError } from '.'; +import { textTpl, StopHandleError, TemplateRenderResult } from './utils'; function renderWorkflow( payload: ExtractPayload<'workflow_run'>, diff --git a/src/github/types.ts b/src/github/types.ts index 7bf84053..738d9c77 100644 --- a/src/github/types.ts +++ b/src/github/types.ts @@ -23,15 +23,6 @@ export type MarkdownContent = { text: string; }; -export type TemplateRenderResult = { - title: string; - text: string; - detail?: { - bodyText: string; - bodyHeader: string; - }; -}; - export type THasAction = { action?: string; }; diff --git a/src/queue/worker/github.ts b/src/queue/worker/github.ts index 5102e19a..5867d7dd 100644 --- a/src/queue/worker/github.ts +++ b/src/queue/worker/github.ts @@ -5,7 +5,7 @@ import DefaultMap from 'mnemonist/default-map'; import { initApp } from '@/github/app'; import { setupWebhooksTemplate } from '@/github/handler'; -import { TemplateRenderResult } from '@/github/types'; +import { TemplateRenderResult } from '@/github/templates'; import { sendToDing } from '@/github/utils'; import { GitHubKVManager } from '@/kv/github'; import { ISetting } from '@/kv/types'; @@ -222,14 +222,16 @@ class EventComposite { const result = [] as IResult[]; - const separator = '\n\n---\n\n'; + const separator = '\n\n***\n\n'; if (subView.length > 0) { const chunked = chunk(subView, 5); chunked.forEach((v, i) => { let title = ''; let eventName = ''; - let text = v.map((d) => d.markdown.text).join(separator); + let text = v + .map((d) => d.markdown.compactText || d.markdown.text) + .join(separator); if (i === 0 && mainView) { title = mainView.markdown.title; diff --git a/test/github/templates/__snapshots__/review.test.ts.snap b/test/github/templates/__snapshots__/review.test.ts.snap index b180428d..ee501942 100644 --- a/test/github/templates/__snapshots__/review.test.ts.snap +++ b/test/github/templates/__snapshots__/review.test.ts.snap @@ -11,7 +11,9 @@ exports[`github templates pr review can handle pull_request_review_2_1_dismissed exports[`github templates pr review can handle pull_request_review_comment_0_created 1`] = ` { - "compactText": undefined, + "compactText": "[Codertocat](https://github.com/Codertocat) created [review comment](https://github.com/Codertocat/Hello-World/pull/2#discussion_r284312630): + +Maybe you should use more emoji on this line.", "text": "#### [Codertocat](https://github.com/Codertocat) created [review comment](https://github.com/Codertocat/Hello-World/pull/2#discussion_r284312630) on [pull request](https://github.com/Codertocat/Hello-World/pull/2) [#2 Update the README with new information.](https://github.com/Codertocat/Hello-World/pull/2) diff --git a/test/queue/__snapshots__/index.test.ts.snap b/test/queue/__snapshots__/index.test.ts.snap index 132a9391..25a24f24 100644 --- a/test/queue/__snapshots__/index.test.ts.snap +++ b/test/queue/__snapshots__/index.test.ts.snap @@ -12,13 +12,10 @@ exports[`queue can composite discussion 1`] = ` We're glad to have you here! ---- - -#### [[octo-repo]](https://github.com/octo-org/octo-repo) [Codertocat](https://github.com/Codertocat) created [comment](https://github.com/octo-org/octo-repo/discussions/90#discussioncomment-544078) on [discussion](https://github.com/octo-org/octo-repo/discussions/90) -#### [#90 Welcome to discussions!](https://github.com/octo-org/octo-repo/discussions/90) - *** +[Codertocat](https://github.com/Codertocat) created [comment](https://github.com/octo-org/octo-repo/discussions/90): + I have so many questions to ask you!", "title": "[octo-repo] Discussion#90 created", }, @@ -34,22 +31,16 @@ exports[`queue can composite pr review 1`] = ` "text": "#### [[Hello-World]](https://github.com/Codertocat/Hello-World) [Codertocat](https://github.com/Codertocat) [requested](https://github.com/Codertocat/Hello-World/pull/2#pullrequestreview-237895671) changes on [pull request](https://github.com/Codertocat/Hello-World/pull/2) #### [#2 Update the README with new information.](https://github.com/Codertocat/Hello-World/pull/2) ---- - -#### [[Hello-World]](https://github.com/Codertocat/Hello-World) [Codertocat](https://github.com/Codertocat) created [review comment](https://github.com/Codertocat/Hello-World/pull/2#discussion_r284312630) on [pull request](https://github.com/Codertocat/Hello-World/pull/2) -[#2 Update the README with new information.](https://github.com/Codertocat/Hello-World/pull/2) - *** -Maybe you should use more emoji on this line. - ---- +[Codertocat](https://github.com/Codertocat) created [review comment](https://github.com/Codertocat/Hello-World/pull/2#discussion_r284312630): -#### [[Hello-World]](https://github.com/Codertocat/Hello-World) [Codertocat](https://github.com/Codertocat) created [review comment](https://github.com/Codertocat/Hello-World/pull/2#discussion_r284312630) on [pull request](https://github.com/Codertocat/Hello-World/pull/2) -[#2 Update the README with new information.](https://github.com/Codertocat/Hello-World/pull/2) +Maybe you should use more emoji on this line. *** +[Codertocat](https://github.com/Codertocat) created [review comment](https://github.com/Codertocat/Hello-World/pull/2#discussion_r284312630): + Maybe you should use more emojji on this line.", "title": "[Hello-World] Review requested changes", },