feat: 初始化 Gitea Action 发送钉钉机器人消息项目

This commit is contained in:
ren
2025-10-15 17:52:44 +08:00
commit 428795c6a5
27 changed files with 9262 additions and 0 deletions

View File

@@ -0,0 +1,407 @@
/**
* 无效配置数据夹具
* 包含各种无效的配置组合用于测试错误处理
*/
export const invalidConfigs = {
// 环境变量格式的无效配置
envVars: {
missingWebhook: {
INPUT_WEBHOOK_URL: '',
INPUT_MESSAGE_TYPE: 'text',
INPUT_CONTENT: 'Hello World',
INPUT_TITLE: '',
INPUT_AT_MOBILES: '',
INPUT_AT_ALL: 'false',
INPUT_LINK_URL: '',
INPUT_PIC_URL: '',
INPUT_BTN_ORIENTATION: '0',
INPUT_SINGLE_TITLE: '',
INPUT_SINGLE_URL: '',
INPUT_BUTTONS: '',
INPUT_FEED_LINKS: ''
},
invalidWebhook: {
INPUT_WEBHOOK_URL: 'not-a-valid-url',
INPUT_MESSAGE_TYPE: 'text',
INPUT_CONTENT: 'Hello World',
INPUT_TITLE: '',
INPUT_AT_MOBILES: '',
INPUT_AT_ALL: 'false',
INPUT_LINK_URL: '',
INPUT_PIC_URL: '',
INPUT_BTN_ORIENTATION: '0',
INPUT_SINGLE_TITLE: '',
INPUT_SINGLE_URL: '',
INPUT_BUTTONS: '',
INPUT_FEED_LINKS: ''
},
emptyContent: {
INPUT_WEBHOOK_URL: 'https://oapi.dingtalk.com/robot/send?access_token=test123',
INPUT_MESSAGE_TYPE: 'text',
INPUT_CONTENT: '',
INPUT_TITLE: '',
INPUT_AT_MOBILES: '',
INPUT_AT_ALL: 'false',
INPUT_LINK_URL: '',
INPUT_PIC_URL: '',
INPUT_BTN_ORIENTATION: '0',
INPUT_SINGLE_TITLE: '',
INPUT_SINGLE_URL: '',
INPUT_BUTTONS: '',
INPUT_FEED_LINKS: ''
}
},
// 缺少 webhook_url
missingWebhookUrl: {
webhook_url: '',
message_type: 'text',
content: 'Hello, World!',
title: '',
at_mobiles: '',
at_all: false,
link_url: '',
pic_url: '',
btn_orientation: '0',
single_title: '',
single_url: '',
buttons: '',
feed_links: ''
},
// 无效的 webhook_url
invalidWebhookUrl: {
webhook_url: 'not-a-valid-url',
message_type: 'text',
content: 'Hello, World!',
title: '',
at_mobiles: '',
at_all: false,
link_url: '',
pic_url: '',
btn_orientation: '0',
single_title: '',
single_url: '',
buttons: '',
feed_links: ''
},
// 不支持的消息类型
unsupportedMessageType: {
webhook_url: 'https://oapi.dingtalk.com/robot/send?access_token=test123',
message_type: 'unsupported',
content: 'Hello, World!',
title: '',
at_mobiles: '',
at_all: false,
link_url: '',
pic_url: '',
btn_orientation: '0',
single_title: '',
single_url: '',
buttons: '',
feed_links: ''
},
// 空的消息内容
emptyContent: {
webhook_url: 'https://oapi.dingtalk.com/robot/send?access_token=test123',
message_type: 'text',
content: '',
title: '',
at_mobiles: '',
at_all: false,
link_url: '',
pic_url: '',
btn_orientation: '0',
single_title: '',
single_url: '',
buttons: '',
feed_links: ''
},
// Markdown 消息缺少标题
markdownMissingTitle: {
webhook_url: 'https://oapi.dingtalk.com/robot/send?access_token=test123',
message_type: 'markdown',
content: '## 内容',
title: '',
at_mobiles: '',
at_all: false,
link_url: '',
pic_url: '',
btn_orientation: '0',
single_title: '',
single_url: '',
buttons: '',
feed_links: ''
},
// Link 消息缺少 URL
linkMissingUrl: {
webhook_url: 'https://oapi.dingtalk.com/robot/send?access_token=test123',
message_type: 'link',
content: '链接描述',
title: '链接标题',
at_mobiles: '',
at_all: false,
link_url: '',
pic_url: '',
btn_orientation: '0',
single_title: '',
single_url: '',
buttons: '',
feed_links: ''
},
// Link 消息无效的 URL
linkInvalidUrl: {
webhook_url: 'https://oapi.dingtalk.com/robot/send?access_token=test123',
message_type: 'link',
content: '链接描述',
title: '链接标题',
at_mobiles: '',
at_all: false,
link_url: 'not-a-valid-url',
pic_url: '',
btn_orientation: '0',
single_title: '',
single_url: '',
buttons: '',
feed_links: ''
},
// ActionCard 缺少标题
actionCardMissingTitle: {
webhook_url: 'https://oapi.dingtalk.com/robot/send?access_token=test123',
message_type: 'actionCard',
content: 'ActionCard 内容',
title: '',
at_mobiles: '',
at_all: false,
link_url: '',
pic_url: '',
btn_orientation: '0',
single_title: '按钮',
single_url: 'https://example.com',
buttons: '',
feed_links: ''
},
// ActionCard 既没有单按钮也没有多按钮
actionCardNoButtons: {
webhook_url: 'https://oapi.dingtalk.com/robot/send?access_token=test123',
message_type: 'actionCard',
content: 'ActionCard 内容',
title: 'ActionCard 标题',
at_mobiles: '',
at_all: false,
link_url: '',
pic_url: '',
btn_orientation: '0',
single_title: '',
single_url: '',
buttons: '',
feed_links: ''
},
// ActionCard 单按钮缺少 URL
actionCardSingleMissingUrl: {
webhook_url: 'https://oapi.dingtalk.com/robot/send?access_token=test123',
message_type: 'actionCard',
content: 'ActionCard 内容',
title: 'ActionCard 标题',
at_mobiles: '',
at_all: false,
link_url: '',
pic_url: '',
btn_orientation: '0',
single_title: '按钮',
single_url: '',
buttons: '',
feed_links: ''
},
// ActionCard 多按钮格式错误
actionCardInvalidButtons: {
webhook_url: 'https://oapi.dingtalk.com/robot/send?access_token=test123',
message_type: 'actionCard',
content: 'ActionCard 内容',
title: 'ActionCard 标题',
at_mobiles: '',
at_all: false,
link_url: '',
pic_url: '',
btn_orientation: '0',
single_title: '',
single_url: '',
buttons: 'invalid-json',
feed_links: ''
},
// ActionCard 多按钮为空数组
actionCardEmptyButtons: {
webhook_url: 'https://oapi.dingtalk.com/robot/send?access_token=test123',
message_type: 'actionCard',
content: 'ActionCard 内容',
title: 'ActionCard 标题',
at_mobiles: '',
at_all: false,
link_url: '',
pic_url: '',
btn_orientation: '0',
single_title: '',
single_url: '',
buttons: '[]',
feed_links: ''
},
// ActionCard 按钮缺少必需字段
actionCardButtonMissingFields: {
webhook_url: 'https://oapi.dingtalk.com/robot/send?access_token=test123',
message_type: 'actionCard',
content: 'ActionCard 内容',
title: 'ActionCard 标题',
at_mobiles: '',
at_all: false,
link_url: '',
pic_url: '',
btn_orientation: '0',
single_title: '',
single_url: '',
buttons: JSON.stringify([
{ title: '按钮1' }, // 缺少 actionURL
{ actionURL: 'https://example.com' } // 缺少 title
]),
feed_links: ''
},
// FeedCard 缺少链接
feedCardMissingLinks: {
webhook_url: 'https://oapi.dingtalk.com/robot/send?access_token=test123',
message_type: 'feedCard',
content: '',
title: '',
at_mobiles: '',
at_all: false,
link_url: '',
pic_url: '',
btn_orientation: '0',
single_title: '',
single_url: '',
buttons: '',
feed_links: ''
},
// FeedCard 链接格式错误
feedCardInvalidLinks: {
webhook_url: 'https://oapi.dingtalk.com/robot/send?access_token=test123',
message_type: 'feedCard',
content: '',
title: '',
at_mobiles: '',
at_all: false,
link_url: '',
pic_url: '',
btn_orientation: '0',
single_title: '',
single_url: '',
buttons: '',
feed_links: 'invalid-json'
},
// FeedCard 空链接数组
feedCardEmptyLinks: {
webhook_url: 'https://oapi.dingtalk.com/robot/send?access_token=test123',
message_type: 'feedCard',
content: '',
title: '',
at_mobiles: '',
at_all: false,
link_url: '',
pic_url: '',
btn_orientation: '0',
single_title: '',
single_url: '',
buttons: '',
feed_links: '[]'
},
// FeedCard 链接缺少必需字段
feedCardLinkMissingFields: {
webhook_url: 'https://oapi.dingtalk.com/robot/send?access_token=test123',
message_type: 'feedCard',
content: '',
title: '',
at_mobiles: '',
at_all: false,
link_url: '',
pic_url: '',
btn_orientation: '0',
single_title: '',
single_url: '',
buttons: '',
feed_links: JSON.stringify([
{ title: '链接1' }, // 缺少 messageURL
{ messageURL: 'https://example.com' } // 缺少 title
])
},
// 无效的手机号格式
invalidMobileFormat: {
webhook_url: 'https://oapi.dingtalk.com/robot/send?access_token=test123',
message_type: 'text',
content: 'Hello, World!',
title: '',
at_mobiles: 'invalid-mobile',
at_all: false,
link_url: '',
pic_url: '',
btn_orientation: '0',
single_title: '',
single_url: '',
buttons: '',
feed_links: ''
},
// 无效的按钮方向
invalidBtnOrientation: {
webhook_url: 'https://oapi.dingtalk.com/robot/send?access_token=test123',
message_type: 'actionCard',
content: 'ActionCard 内容',
title: 'ActionCard 标题',
at_mobiles: '',
at_all: false,
link_url: '',
pic_url: '',
btn_orientation: '2', // 只支持 0 和 1
single_title: '按钮',
single_url: 'https://example.com',
buttons: '',
feed_links: ''
}
};
// 环境变量格式的无效配置
export const invalidEnvConfigs = {
missingWebhookUrl: {
INPUT_WEBHOOK_URL: '',
INPUT_MESSAGE_TYPE: 'text',
INPUT_CONTENT: 'Hello, World!'
},
unsupportedMessageType: {
INPUT_WEBHOOK_URL: 'https://oapi.dingtalk.com/robot/send?access_token=test123',
INPUT_MESSAGE_TYPE: 'unsupported',
INPUT_CONTENT: 'Hello, World!'
},
emptyContent: {
INPUT_WEBHOOK_URL: 'https://oapi.dingtalk.com/robot/send?access_token=test123',
INPUT_MESSAGE_TYPE: 'text',
INPUT_CONTENT: ''
}
};

378
tests/fixtures/configs/valid-configs.js vendored Normal file
View File

@@ -0,0 +1,378 @@
/**
* 有效配置数据夹具
* 包含各种有效的配置组合用于测试
*/
export const validConfigs = {
// 环境变量格式的配置
envVars: {
text: {
INPUT_WEBHOOK_URL: 'https://oapi.dingtalk.com/robot/send?access_token=test123',
INPUT_MESSAGE_TYPE: 'text',
INPUT_CONTENT: 'Hello World',
INPUT_TITLE: '',
INPUT_AT_MOBILES: '',
INPUT_AT_ALL: 'false',
INPUT_LINK_URL: '',
INPUT_PIC_URL: '',
INPUT_BTN_ORIENTATION: '0',
INPUT_SINGLE_TITLE: '',
INPUT_SINGLE_URL: '',
INPUT_BUTTONS: '',
INPUT_FEED_LINKS: '',
},
markdown: {
INPUT_WEBHOOK_URL: 'https://oapi.dingtalk.com/robot/send?access_token=test456',
INPUT_MESSAGE_TYPE: 'markdown',
INPUT_CONTENT: '# Hello\n\nThis is **markdown** content.',
INPUT_TITLE: 'Test Title',
INPUT_AT_MOBILES: '',
INPUT_AT_ALL: 'false',
INPUT_LINK_URL: '',
INPUT_PIC_URL: '',
INPUT_BTN_ORIENTATION: '0',
INPUT_SINGLE_TITLE: '',
INPUT_SINGLE_URL: '',
INPUT_BUTTONS: '',
INPUT_FEED_LINKS: '',
},
link: {
INPUT_WEBHOOK_URL: 'https://oapi.dingtalk.com/robot/send?access_token=test789',
INPUT_MESSAGE_TYPE: 'link',
INPUT_CONTENT: 'This is a test link',
INPUT_TITLE: 'Test Link',
INPUT_AT_MOBILES: '',
INPUT_AT_ALL: 'false',
INPUT_LINK_URL: 'https://example.com',
INPUT_PIC_URL: '',
INPUT_BTN_ORIENTATION: '0',
INPUT_SINGLE_TITLE: '',
INPUT_SINGLE_URL: '',
INPUT_BUTTONS: '',
INPUT_FEED_LINKS: '',
},
actionCard: {
INPUT_WEBHOOK_URL: 'https://oapi.dingtalk.com/robot/send?access_token=test101',
INPUT_MESSAGE_TYPE: 'actionCard',
INPUT_CONTENT: 'Action card content',
INPUT_TITLE: 'Action Card Title',
INPUT_AT_MOBILES: '',
INPUT_AT_ALL: 'false',
INPUT_LINK_URL: '',
INPUT_PIC_URL: '',
INPUT_BTN_ORIENTATION: '0',
INPUT_SINGLE_TITLE: '',
INPUT_SINGLE_URL: '',
INPUT_BUTTONS: JSON.stringify([{ title: 'Button 1', actionURL: 'https://example.com/1' }]),
INPUT_FEED_LINKS: '',
},
feedCard: {
INPUT_WEBHOOK_URL: 'https://oapi.dingtalk.com/robot/send?access_token=test103',
INPUT_MESSAGE_TYPE: 'feedCard',
INPUT_CONTENT: '',
INPUT_TITLE: '',
INPUT_AT_MOBILES: '',
INPUT_AT_ALL: 'false',
INPUT_LINK_URL: '',
INPUT_PIC_URL: '',
INPUT_BTN_ORIENTATION: '0',
INPUT_SINGLE_TITLE: '',
INPUT_SINGLE_URL: '',
INPUT_BUTTONS: '',
INPUT_FEED_LINKS: JSON.stringify([
{
title: '新闻1',
messageURL: 'https://example.com/news1',
picURL: 'https://example.com/pic1.jpg',
},
]),
},
},
// 基础文本消息配置
basicText: {
webhook_url: 'https://oapi.dingtalk.com/robot/send?access_token=test123',
message_type: 'text',
content: 'Hello, World!',
title: '',
at_mobiles: '',
at_all: false,
link_url: '',
pic_url: '',
btn_orientation: '0',
single_title: '',
single_url: '',
buttons: '',
feed_links: '',
},
// Markdown 消息配置
markdown: {
webhook_url: 'https://oapi.dingtalk.com/robot/send?access_token=test456',
message_type: 'markdown',
content: '## 标题\n这是一个 **Markdown** 消息',
title: 'Markdown 标题',
at_mobiles: '',
at_all: false,
link_url: '',
pic_url: '',
btn_orientation: '0',
single_title: '',
single_url: '',
buttons: '',
feed_links: '',
},
// 链接消息配置
link: {
webhook_url: 'https://oapi.dingtalk.com/robot/send?access_token=test789',
message_type: 'link',
content: '这是一个链接消息的描述',
title: '链接标题',
at_mobiles: '',
at_all: false,
link_url: 'https://example.com',
pic_url: 'https://example.com/image.jpg',
btn_orientation: '0',
single_title: '',
single_url: '',
buttons: '',
feed_links: '',
},
// 单按钮 ActionCard 配置
singleActionCard: {
webhook_url: 'https://oapi.dingtalk.com/robot/send?access_token=test101',
message_type: 'actionCard',
content: '这是一个单按钮 ActionCard',
title: 'ActionCard 标题',
at_mobiles: '',
at_all: false,
link_url: '',
pic_url: '',
btn_orientation: '0',
single_title: '查看详情',
single_url: 'https://example.com/detail',
buttons: '',
feed_links: '',
},
// 多按钮 ActionCard 配置
multiActionCard: {
webhook_url: 'https://oapi.dingtalk.com/robot/send?access_token=test102',
message_type: 'actionCard',
content: '这是一个多按钮 ActionCard',
title: 'ActionCard 标题',
at_mobiles: '',
at_all: false,
link_url: '',
pic_url: '',
btn_orientation: '1',
single_title: '',
single_url: '',
buttons: JSON.stringify([
{ title: '按钮1', actionURL: 'https://example.com/action1' },
{ title: '按钮2', actionURL: 'https://example.com/action2' },
]),
feed_links: '',
},
// FeedCard 配置
feedCard: {
webhook_url: 'https://oapi.dingtalk.com/robot/send?access_token=test103',
message_type: 'feedCard',
content: '',
title: '',
at_mobiles: '',
at_all: false,
link_url: '',
pic_url: '',
btn_orientation: '0',
single_title: '',
single_url: '',
buttons: '',
feed_links: JSON.stringify([
{
title: '新闻1',
messageURL: 'https://example.com/news1',
picURL: 'https://example.com/pic1.jpg',
},
{
title: '新闻2',
messageURL: 'https://example.com/news2',
picURL: 'https://example.com/pic2.jpg',
},
]),
},
// 带 @ 功能的文本消息
textWithAt: {
webhook_url: 'https://oapi.dingtalk.com/robot/send?access_token=test104',
message_type: 'text',
content: '这是一个带 @ 功能的消息',
title: '',
at_mobiles: '13800138000,13900139000',
at_all: false,
link_url: '',
pic_url: '',
btn_orientation: '0',
single_title: '',
single_url: '',
buttons: '',
feed_links: '',
},
// @ 所有人的消息
textWithAtAll: {
webhook_url: 'https://oapi.dingtalk.com/robot/send?access_token=test105',
message_type: 'text',
content: '这是一个 @ 所有人的消息',
title: '',
at_mobiles: '',
at_all: true,
link_url: '',
pic_url: '',
btn_orientation: '0',
single_title: '',
single_url: '',
buttons: '',
feed_links: '',
},
// 复杂的 Markdown 消息
complexMarkdown: {
webhook_url: 'https://oapi.dingtalk.com/robot/send?access_token=test106',
message_type: 'markdown',
content: `# 构建报告
## 构建状态: ✅ 成功
- **项目**: dingtalk-bot
- **分支**: main
- **提交**: abc123
- **时间**: 2024-01-01 12:00:00
### 测试结果
- 单元测试: 100% 通过
- 覆盖率: 95%
[查看详细报告](https://example.com/report)`,
title: '构建报告',
at_mobiles: '13800138000',
at_all: false,
link_url: '',
pic_url: '',
btn_orientation: '0',
single_title: '',
single_url: '',
buttons: '',
feed_links: '',
},
// 垂直排列的多按钮 ActionCard
verticalActionCard: {
webhook_url: 'https://oapi.dingtalk.com/robot/send?access_token=test107',
message_type: 'actionCard',
content: '请选择操作',
title: '操作选择',
at_mobiles: '',
at_all: false,
link_url: '',
pic_url: '',
btn_orientation: '1',
single_title: '',
single_url: '',
buttons: JSON.stringify([
{ title: '同意', actionURL: 'https://example.com/approve' },
{ title: '拒绝', actionURL: 'https://example.com/reject' },
{ title: '查看详情', actionURL: 'https://example.com/detail' },
]),
feed_links: '',
},
// 多链接 FeedCard
multiFeedCard: {
webhook_url: 'https://oapi.dingtalk.com/robot/send?access_token=test108',
message_type: 'feedCard',
content: '',
title: '',
at_mobiles: '',
at_all: false,
link_url: '',
pic_url: '',
btn_orientation: '0',
single_title: '',
single_url: '',
buttons: '',
feed_links: JSON.stringify([
{
title: '技术文档',
messageURL: 'https://docs.example.com',
picURL: 'https://example.com/doc.jpg',
},
{
title: 'API 参考',
messageURL: 'https://api.example.com',
picURL: 'https://example.com/api.jpg',
},
{
title: '示例代码',
messageURL: 'https://github.com/example',
picURL: 'https://example.com/code.jpg',
},
]),
},
};
// 环境变量格式的配置(用于测试 config.js
export const envConfigs = {
basicText: {
INPUT_WEBHOOK_URL: 'https://oapi.dingtalk.com/robot/send?access_token=test123',
INPUT_MESSAGE_TYPE: 'text',
INPUT_CONTENT: 'Hello, World!',
INPUT_TITLE: '',
INPUT_AT_MOBILES: '',
INPUT_AT_ALL: 'false',
INPUT_LINK_URL: '',
INPUT_PIC_URL: '',
INPUT_BTN_ORIENTATION: '0',
INPUT_SINGLE_TITLE: '',
INPUT_SINGLE_URL: '',
INPUT_BUTTONS: '',
INPUT_FEED_LINKS: '',
},
markdown: {
INPUT_WEBHOOK_URL: 'https://oapi.dingtalk.com/robot/send?access_token=test456',
INPUT_MESSAGE_TYPE: 'markdown',
INPUT_CONTENT: '## 标题\n这是一个 **Markdown** 消息',
INPUT_TITLE: 'Markdown 标题',
INPUT_AT_MOBILES: '',
INPUT_AT_ALL: 'false',
INPUT_LINK_URL: '',
INPUT_PIC_URL: '',
INPUT_BTN_ORIENTATION: '0',
INPUT_SINGLE_TITLE: '',
INPUT_SINGLE_URL: '',
INPUT_BUTTONS: '',
INPUT_FEED_LINKS: '',
},
textWithAtAll: {
INPUT_WEBHOOK_URL: 'https://oapi.dingtalk.com/robot/send?access_token=test105',
INPUT_MESSAGE_TYPE: 'text',
INPUT_CONTENT: '这是一个 @ 所有人的消息',
INPUT_TITLE: '',
INPUT_AT_MOBILES: '',
INPUT_AT_ALL: 'true',
INPUT_LINK_URL: '',
INPUT_PIC_URL: '',
INPUT_BTN_ORIENTATION: '0',
INPUT_SINGLE_TITLE: '',
INPUT_SINGLE_URL: '',
INPUT_BUTTONS: '',
INPUT_FEED_LINKS: '',
},
};