Skip to content

Commit 80f98fc

Browse files
authored
Dev to master, v2.2.0 finish feishu notification (#14)
* separate local config and default config * finish feishu (#12) * finish feishu, readme optimize feishu template * change feishu msg header * docker log => stdout stderr * add show original env * upgrade to 2.2.0
1 parent c3e1a3a commit 80f98fc

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ ENV TIME_ZONE=Asia/Shanghai
55

66
RUN \
77
echo "${TIME_ZONE}" > /etc/timezone \
8-
&& ln -sf /usr/share/zoneinfo/${TIME_ZONE} /etc/localtime
8+
&& ln -sf /usr/share/zoneinfo/${TIME_ZONE} /etc/localtime \
9+
&& mkdir -p /root/logs/gitlab-bot \
10+
&& ln -sf /dev/stdout /root/logs/gitlab-bot/gitlab-bot-web.log \
11+
&& ln -sf /dev/stderr /root/logs/gitlab-bot/common-error.log
912

1013
WORKDIR /app
1114

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
`1.0.0`: 采用内置代码,且仅支持企业微信;
1818

19-
`2.0.0`: 通过消息模板,可自行配置通知消息格式和字段,具体配置方式,参见[mustache官方文档](https://github.com/janl/mustache.js)
19+
`2.x.x`: 通过消息模板,可自行配置通知消息格式和字段,具体配置方式,参见[mustache官方文档](https://github.com/janl/mustache.js)
2020

2121
todo:
2222

@@ -62,8 +62,10 @@ Gitlab pipeline 流水线
6262

6363
### 环境变量
6464

65-
- `PLATFORM``qywx`, `feishu`,即:企业微信、飞书;
65+
66+
- `PLATFORM``qywx | feishu`,默认为`qywx`,即:企业微信、飞书;
6667
- `WEBHOOK_URL_XXX`:机器人webhook地址,具体配置参考[应用部署运行](#应用部署运行)
68+
- `SHOW_ORIGINAL``true | false`,默认为`false`,如果无模板,是否发送原消息体;
6769

6870
### 与企业微信对接
6971

@@ -75,7 +77,8 @@ Gitlab pipeline 流水线
7577

7678
![alt gitlab-feishu](./docs/gitlab-feishu.png)
7779

78-
webhook地址示例:https://open.feishu.cn/open-apis/bot/v2/hook/UUID
80+
81+
飞书webhook地址示例:https://open.feishu.cn/open-apis/bot/v2/hook/UUID
7982

8083

8184
## 应用部署运行

app/service/webhook.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ Mustache.escape = text =>
1616
// all customized variables start with GB_
1717
class WebhookService extends Service {
1818
async translateMsg(data = {}, platform, gitlabEvent) {
19-
const { template, response, color } = this.config;
19+
const { template, response, color, showOriginal } = this.config;
20+
21+
const isShowOriginal = process.env['SHOW_ORIGINAL'] || showOriginal;
2022

2123
// set templage, response, color code
2224
if (!template[platform]) {
@@ -58,6 +60,9 @@ class WebhookService extends Service {
5860
break;
5961
}
6062

63+
if (!content.length && isShowOriginal) content.push(JSON.stringify(data));
64+
if (!content.length) return false;
65+
6166
const { path, body } = this.response;
6267
this.setJsonValue(body, path, content.join());
6368
return body;

config/config.default.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module.exports = appInfo => {
2424

2525
// add your user config here
2626
const userConfig = {
27+
showOriginal: false,
2728
supportPlatforms: ['qywx', 'feishu'],
2829
platform: 'qywx',
2930
response: {
@@ -50,7 +51,7 @@ module.exports = appInfo => {
5051
header: {
5152
template: 'blue',
5253
title: {
53-
content: 'Gitlab通知',
54+
content: 'Gitlab机器人通知',
5455
tag: 'plain_text',
5556
},
5657
},

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gitlab-bot",
3-
"version": "2.1.0",
3+
"version": "2.2.0",
44
"description": "",
55
"private": true,
66
"egg": {
@@ -28,8 +28,8 @@
2828
"node": ">=14.20.0"
2929
},
3030
"scripts": {
31-
"start": "egg-scripts start --title=egg-server-gitlab-bot",
32-
"stop": "egg-scripts stop --title=egg-server-gitlab-bot",
31+
"start": "egg-scripts start --title=gitlab-bot",
32+
"stop": "egg-scripts stop --title=gitlab-bot",
3333
"dev": "egg-bin dev",
3434
"debug": "egg-bin debug",
3535
"test": "npm run lint -- --fix && npm run test-local",

0 commit comments

Comments
 (0)