Skip to content

Commit 95e0cb7

Browse files
authored
Merge pull request #6 from hu-qi/master
refactor: remove short commit ID from commit link display.
2 parents 39f4810 + ccd63f1 commit 95e0cb7

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

.github/scripts/transform-message-for-card.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ const createUserLink = (user: GitHubUser) =>
6161
const sanitizeMarkdown = (text: string): string => {
6262
return text
6363
// 移除代码块
64-
// .replace(/```[\s\S]*?```/g, '[代码块]')
64+
.replace(/```[\s\S]*?```/g, '[代码块]')
6565
// 移除行内代码
66-
// .replace(/`[^`]+`/g, (match) => match.slice(1, -1))
66+
.replace(/`[^`]+`/g, (match) => match.slice(1, -1))
6767
// 将图片转换为链接文本
6868
.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, '🖼️ [$1]($2)')
6969
// 将 ### 标题转换为加粗
@@ -104,7 +104,6 @@ const eventHandlers: Record<string, EventHandler> = {
104104
actor,
105105
}) => {
106106
const commitUrl = head_commit?.url || `${server_url}/${repository}/tree/${ref_name}`;
107-
const commitId = head_commit?.id?.slice(0, 7) || 'n/a';
108107
const commitMessage = head_commit?.message || 'Create/Delete/Update Branch (No head commit)';
109108

110109
return {
@@ -113,7 +112,7 @@ const eventHandlers: Record<string, EventHandler> = {
113112
{
114113
tag: 'markdown',
115114
content: [
116-
createContentItem('提交链接:', createLink(commitUrl, commitId)),
115+
createContentItem('提交链接:', createLink(commitUrl)),
117116
createContentItem('代码分支:', createLink(`${server_url}/${repository}/tree/${ref_name}`, ref_name)),
118117
createContentItem('提交作者:', createLink(`${server_url}/${actor}`, actor)),
119118
createContentItem('提交信息:', commitMessage),
@@ -129,7 +128,7 @@ const eventHandlers: Record<string, EventHandler> = {
129128
{
130129
tag: 'markdown',
131130
content: [
132-
createContentItem('链接:', createLink(issue!.html_url, `#${issue!.number}`)),
131+
createContentItem('链接:', createLink(issue!.html_url)),
133132
createContentItem('作者:', createUserLink(issue!.user!)),
134133
createContentItem('指派:', issue?.assignee ? createUserLink(issue.assignee) : '无'),
135134
createContentItem('标签:', issue?.labels?.map(({ name }) => name).join(', ') || '无'),
@@ -146,7 +145,7 @@ const eventHandlers: Record<string, EventHandler> = {
146145
{
147146
tag: 'markdown',
148147
content: [
149-
createContentItem('链接:', createLink(pull_request!.html_url, `#${pull_request!.number}`)),
148+
createContentItem('链接:', createLink(pull_request!.html_url)),
150149
createContentItem('作者:', createUserLink(pull_request!.user)),
151150
createContentItem('指派:', pull_request?.assignee ? createUserLink(pull_request.assignee) : '无'),
152151
createContentItem('标签:', pull_request?.labels?.map(({ name }) => name).join(', ') || '无'),
@@ -163,7 +162,7 @@ const eventHandlers: Record<string, EventHandler> = {
163162
{
164163
tag: 'markdown',
165164
content: [
166-
createContentItem('链接:', createLink(discussion!.html_url, `#${discussion!.number}`)),
165+
createContentItem('链接:', createLink(discussion!.html_url)),
167166
createContentItem('作者:', createUserLink(discussion!.user as GitHubUser)),
168167
createContentItem('描述:', discussion?.body || '无'),
169168
].join('\n'),
@@ -177,7 +176,7 @@ const eventHandlers: Record<string, EventHandler> = {
177176
{
178177
tag: 'markdown',
179178
content: [
180-
createContentItem('链接:', createLink(comment!.html_url, '查看评论')),
179+
createContentItem('链接:', createLink(comment!.html_url)),
181180
createContentItem('作者:', createUserLink(comment!.user!)),
182181
createContentItem('描述:', comment?.body || '无'),
183182
].join('\n'),
@@ -191,7 +190,7 @@ const eventHandlers: Record<string, EventHandler> = {
191190
{
192191
tag: 'markdown',
193192
content: [
194-
createContentItem('链接:', createLink(comment!.html_url, '查看评论')),
193+
createContentItem('链接:', createLink(comment!.html_url)),
195194
createContentItem('作者:', createUserLink(comment!.user!)),
196195
createContentItem('描述:', comment?.body || '无'),
197196
].join('\n'),
@@ -205,7 +204,7 @@ const eventHandlers: Record<string, EventHandler> = {
205204
{
206205
tag: 'markdown',
207206
content: [
208-
createContentItem('链接:', createLink(release!.html_url, release!.tag_name)),
207+
createContentItem('链接:', createLink(release!.html_url)),
209208
createContentItem('作者:', createUserLink(release!.author)),
210209
createContentItem('描述:', release?.body || '无'),
211210
].join('\n'),
@@ -219,7 +218,7 @@ const eventHandlers: Record<string, EventHandler> = {
219218
{
220219
tag: 'markdown',
221220
content: [
222-
createContentItem('链接:', createLink(comment!.html_url, '查看评论')),
221+
createContentItem('链接:', createLink(comment!.html_url)),
223222
createContentItem('作者:', createUserLink(comment!.user!)),
224223
createContentItem('PR:', createLink(pull_request!.html_url, `#${pull_request!.number}`)),
225224
createContentItem('评论:', comment?.body || '无'),

.github/workflows/Lark-notification.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ on:
1616
jobs:
1717
send-Lark-message:
1818
runs-on: ubuntu-latest
19+
env:
20+
FEISHU_BOT_WEBHOOK_URL: ${{ secrets.FEISHU_BOT_WEBHOOK_URL }}
1921
steps:
20-
- uses: actions/checkout@v5
22+
- uses: actions/checkout@v6
2123

2224
- uses: denoland/setup-deno@v2
2325
with:
@@ -26,18 +28,22 @@ jobs:
2628
- name: Event Message serialization
2729
id: message
2830
run: |
29-
YAML=$(echo '${{ toJSON(github) }}' | deno --allow-all .github/scripts/transform-message-for-card.ts)
31+
YAML=$(
32+
cat <<'JSON' | deno run --allow-all .github/scripts/transform-message-for-card.ts
33+
${{ toJSON(github) }}
34+
JSON
35+
)
3036
{
3137
echo 'content<<EOF'
32-
echo $YAML
38+
echo "$YAML"
3339
echo 'EOF'
34-
} >> $GITHUB_OUTPUT
40+
} >> "$GITHUB_OUTPUT"
3541
3642
- name: Send message to Lark
3743
if: ${{ contains(steps.message.outputs.content, ':') }}
3844
uses: ./
3945
with:
40-
url: ${{ secrets.FEISHU_BOT_WEBHOOK_URL }}
46+
url: ${{ env.FEISHU_BOT_WEBHOOK_URL }}
4147
msg_type: interactive
4248
content: |
4349
${{ steps.message.outputs.content }}

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ jobs:
1212
build: # make sure build/ci work properly
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v2
15+
- uses: actions/checkout@v6
1616
- run: |
1717
npm install
1818
npm run all
1919
test: # make sure the action works on a clean machine without building
2020
if: ${{ github.event_name == 'workflow_dispatch' }}
2121
runs-on: ubuntu-latest
2222
steps:
23-
- uses: actions/checkout@v2
23+
- uses: actions/checkout@v6
2424
- uses: ./
2525
with:
2626
url: ${{ secrets.FEISHU_BOT_WEBHOOK_URL }}

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
"noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
99
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
1010
},
11+
"include": ["src/**/*"],
1112
"exclude": ["node_modules", "**/*.test.ts"]
1213
}

0 commit comments

Comments
 (0)