Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions .github/scripts/transform-message-for-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ const createUserLink = (user: GitHubUser) =>
const sanitizeMarkdown = (text: string): string => {
return text
// 移除代码块
// .replace(/```[\s\S]*?```/g, '[代码块]')
.replace(/```[\s\S]*?```/g, '[代码块]')
// 移除行内代码
// .replace(/`[^`]+`/g, (match) => match.slice(1, -1))
.replace(/`[^`]+`/g, (match) => match.slice(1, -1))
// 将图片转换为链接文本
.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, '🖼️ [$1]($2)')
// 将 ### 标题转换为加粗
Expand Down Expand Up @@ -104,7 +104,6 @@ const eventHandlers: Record<string, EventHandler> = {
actor,
}) => {
const commitUrl = head_commit?.url || `${server_url}/${repository}/tree/${ref_name}`;
const commitId = head_commit?.id?.slice(0, 7) || 'n/a';
const commitMessage = head_commit?.message || 'Create/Delete/Update Branch (No head commit)';

return {
Expand All @@ -113,7 +112,7 @@ const eventHandlers: Record<string, EventHandler> = {
{
tag: 'markdown',
content: [
createContentItem('提交链接:', createLink(commitUrl, commitId)),
createContentItem('提交链接:', createLink(commitUrl)),
createContentItem('代码分支:', createLink(`${server_url}/${repository}/tree/${ref_name}`, ref_name)),
createContentItem('提交作者:', createLink(`${server_url}/${actor}`, actor)),
createContentItem('提交信息:', commitMessage),
Expand All @@ -129,7 +128,7 @@ const eventHandlers: Record<string, EventHandler> = {
{
tag: 'markdown',
content: [
createContentItem('链接:', createLink(issue!.html_url, `#${issue!.number}`)),
createContentItem('链接:', createLink(issue!.html_url)),
createContentItem('作者:', createUserLink(issue!.user!)),
createContentItem('指派:', issue?.assignee ? createUserLink(issue.assignee) : '无'),
createContentItem('标签:', issue?.labels?.map(({ name }) => name).join(', ') || '无'),
Expand All @@ -146,7 +145,7 @@ const eventHandlers: Record<string, EventHandler> = {
{
tag: 'markdown',
content: [
createContentItem('链接:', createLink(pull_request!.html_url, `#${pull_request!.number}`)),
createContentItem('链接:', createLink(pull_request!.html_url)),
createContentItem('作者:', createUserLink(pull_request!.user)),
createContentItem('指派:', pull_request?.assignee ? createUserLink(pull_request.assignee) : '无'),
createContentItem('标签:', pull_request?.labels?.map(({ name }) => name).join(', ') || '无'),
Expand All @@ -163,7 +162,7 @@ const eventHandlers: Record<string, EventHandler> = {
{
tag: 'markdown',
content: [
createContentItem('链接:', createLink(discussion!.html_url, `#${discussion!.number}`)),
createContentItem('链接:', createLink(discussion!.html_url)),
createContentItem('作者:', createUserLink(discussion!.user as GitHubUser)),
createContentItem('描述:', discussion?.body || '无'),
].join('\n'),
Expand All @@ -177,7 +176,7 @@ const eventHandlers: Record<string, EventHandler> = {
{
tag: 'markdown',
content: [
createContentItem('链接:', createLink(comment!.html_url, '查看评论')),
createContentItem('链接:', createLink(comment!.html_url)),
createContentItem('作者:', createUserLink(comment!.user!)),
createContentItem('描述:', comment?.body || '无'),
].join('\n'),
Expand All @@ -191,7 +190,7 @@ const eventHandlers: Record<string, EventHandler> = {
{
tag: 'markdown',
content: [
createContentItem('链接:', createLink(comment!.html_url, '查看评论')),
createContentItem('链接:', createLink(comment!.html_url)),
createContentItem('作者:', createUserLink(comment!.user!)),
createContentItem('描述:', comment?.body || '无'),
].join('\n'),
Expand All @@ -205,7 +204,7 @@ const eventHandlers: Record<string, EventHandler> = {
{
tag: 'markdown',
content: [
createContentItem('链接:', createLink(release!.html_url, release!.tag_name)),
createContentItem('链接:', createLink(release!.html_url)),
createContentItem('作者:', createUserLink(release!.author)),
createContentItem('描述:', release?.body || '无'),
].join('\n'),
Expand All @@ -219,7 +218,7 @@ const eventHandlers: Record<string, EventHandler> = {
{
tag: 'markdown',
content: [
createContentItem('链接:', createLink(comment!.html_url, '查看评论')),
createContentItem('链接:', createLink(comment!.html_url)),
createContentItem('作者:', createUserLink(comment!.user!)),
createContentItem('PR:', createLink(pull_request!.html_url, `#${pull_request!.number}`)),
createContentItem('评论:', comment?.body || '无'),
Expand Down
16 changes: 11 additions & 5 deletions .github/workflows/Lark-notification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ on:
jobs:
send-Lark-message:
runs-on: ubuntu-latest
env:
FEISHU_BOT_WEBHOOK_URL: ${{ secrets.FEISHU_BOT_WEBHOOK_URL }}
steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v6

- uses: denoland/setup-deno@v2
with:
Expand All @@ -26,18 +28,22 @@ jobs:
- name: Event Message serialization
id: message
run: |
YAML=$(echo '${{ toJSON(github) }}' | deno --allow-all .github/scripts/transform-message-for-card.ts)
YAML=$(
cat <<'JSON' | deno run --allow-all .github/scripts/transform-message-for-card.ts
${{ toJSON(github) }}
JSON
)
{
echo 'content<<EOF'
echo $YAML
echo "$YAML"
echo 'EOF'
} >> $GITHUB_OUTPUT
} >> "$GITHUB_OUTPUT"

- name: Send message to Lark
if: ${{ contains(steps.message.outputs.content, ':') }}
uses: ./
with:
url: ${{ secrets.FEISHU_BOT_WEBHOOK_URL }}
url: ${{ env.FEISHU_BOT_WEBHOOK_URL }}
msg_type: interactive
content: |
${{ steps.message.outputs.content }}
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ jobs:
build: # make sure build/ci work properly
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6
- run: |
npm install
npm run all
test: # make sure the action works on a clean machine without building
if: ${{ github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6
- uses: ./
with:
url: ${{ secrets.FEISHU_BOT_WEBHOOK_URL }}
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
},
"include": ["src/**/*"],
"exclude": ["node_modules", "**/*.test.ts"]
}
Loading