-
Notifications
You must be signed in to change notification settings - Fork 0
142 lines (129 loc) · 4.85 KB
/
Copy pathfeishu-notify.yml
File metadata and controls
142 lines (129 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: Notify Feishu on New Issue
on:
issues:
types: [opened]
jobs:
notify:
runs-on: ubuntu-latest
steps:
- name: Send Feishu Card Notification
uses: actions/github-script@v7
env:
FEISHU_WEBHOOK_URL: ${{ secrets.FEISHU_WEBHOOK_URL }}
with:
script: |
const issue = context.payload.issue;
const author = issue.user.login;
const title = issue.title;
const url = issue.html_url;
const body = issue.body || '';
const labels = issue.labels.map(l => l.name);
// Determine if bug or feature based on issue type or title prefix
const isBug = title.startsWith('[Bug]') || labels.includes('bug');
const isFeature = title.startsWith('[FR]') || labels.includes('enhancement');
let cardHeader, cardColor, cardType, cardContent;
if (isBug) {
cardColor = 'red';
cardHeader = '😣问题反馈';
// Parse bug report fields from body
let description = '';
const descMatch = body.match(/### 问题描述\s*\n\s*\n([\s\S]*?)(?=\n###|$)/);
if (descMatch) description = descMatch[1].trim();
cardContent = [
{
"tag": "div",
"text": {
"tag": "lark_md",
"content": `问题反馈:\n反馈人:**${author}**\n**问题概述:${title.replace('[Bug] ', '')}**\n${description ? description.substring(0, 500) : ''}\n\n请及时查看并处理该问题。`
}
},
{
"tag": "action",
"actions": [
{
"tag": "button",
"text": {
"tag": "plain_text",
"content": "问题详情🔍"
},
"url": url,
"type": "default"
}
]
},
{ "tag": "hr" },
{
"tag": "note",
"elements": [
{
"tag": "lark_md",
"content": "来自 [TaaS迭代](https://github.com/orgs/china-qijizhifeng/projects/3)"
}
]
}
];
} else {
cardColor = 'green';
cardHeader = '⏰新增需求';
let description = '';
const descMatch = body.match(/### 功能描述\s*\n\s*\n([\s\S]*?)(?=\n###|$)/);
if (descMatch) description = descMatch[1].trim();
cardContent = [
{
"tag": "div",
"text": {
"tag": "lark_md",
"content": `新增需求:\n提需人:**${author}**\n**需求概述:${title.replace('[FR] ', '')}**\n${description ? description.substring(0, 500) : ''}\n\n请及时查看并处理该需求,如有疑问可与提需人沟通。`
}
},
{
"tag": "action",
"actions": [
{
"tag": "button",
"text": {
"tag": "plain_text",
"content": "需求详情🔍"
},
"url": url,
"type": "default"
}
]
},
{ "tag": "hr" },
{
"tag": "note",
"elements": [
{
"tag": "lark_md",
"content": "来自 [TaaS迭代](https://github.com/orgs/china-qijizhifeng/projects/3)"
}
]
}
];
}
const card = {
"msg_type": "interactive",
"card": {
"header": {
"title": {
"tag": "plain_text",
"content": cardHeader
},
"template": cardColor
},
"elements": cardContent
}
};
const webhookUrl = process.env.FEISHU_WEBHOOK_URL;
if (!webhookUrl) {
console.log('FEISHU_WEBHOOK_URL not set, skipping notification');
return;
}
const response = await fetch(webhookUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(card)
});
const result = await response.json();
console.log('Feishu response:', JSON.stringify(result));