From 80f98fc8f2cb0527dea8d57307c97bc1b00a9cd5 Mon Sep 17 00:00:00 2001 From: JerryZ Date: Thu, 7 Sep 2023 23:21:06 +0800 Subject: [PATCH] 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 --- Dockerfile | 5 ++++- README.md | 9 ++++++--- app/service/webhook.js | 7 ++++++- config/config.default.js | 3 ++- package.json | 6 +++--- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8493b97..eb9f761 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,10 @@ ENV TIME_ZONE=Asia/Shanghai RUN \ echo "${TIME_ZONE}" > /etc/timezone \ - && ln -sf /usr/share/zoneinfo/${TIME_ZONE} /etc/localtime + && ln -sf /usr/share/zoneinfo/${TIME_ZONE} /etc/localtime \ + && mkdir -p /root/logs/gitlab-bot \ + && ln -sf /dev/stdout /root/logs/gitlab-bot/gitlab-bot-web.log \ + && ln -sf /dev/stderr /root/logs/gitlab-bot/common-error.log WORKDIR /app diff --git a/README.md b/README.md index 242786d..6c6a6fa 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ `1.0.0`: 采用内置代码,且仅支持企业微信; -`2.0.0`: 通过消息模板,可自行配置通知消息格式和字段,具体配置方式,参见[mustache官方文档](https://github.com/janl/mustache.js) +`2.x.x`: 通过消息模板,可自行配置通知消息格式和字段,具体配置方式,参见[mustache官方文档](https://github.com/janl/mustache.js) todo: @@ -62,8 +62,10 @@ Gitlab pipeline 流水线 ### 环境变量 -- `PLATFORM`:`qywx`, `feishu`,即:企业微信、飞书; + +- `PLATFORM`:`qywx | feishu`,默认为`qywx`,即:企业微信、飞书; - `WEBHOOK_URL_XXX`:机器人webhook地址,具体配置参考[应用部署运行](#应用部署运行); +- `SHOW_ORIGINAL`:`true | false`,默认为`false`,如果无模板,是否发送原消息体; ### 与企业微信对接 @@ -75,7 +77,8 @@ Gitlab pipeline 流水线 ![alt gitlab-feishu](./docs/gitlab-feishu.png) -webhook地址示例:https://open.feishu.cn/open-apis/bot/v2/hook/UUID + +飞书webhook地址示例:https://open.feishu.cn/open-apis/bot/v2/hook/UUID ## 应用部署运行 diff --git a/app/service/webhook.js b/app/service/webhook.js index 74e1002..ad590ed 100644 --- a/app/service/webhook.js +++ b/app/service/webhook.js @@ -16,7 +16,9 @@ Mustache.escape = text => // all customized variables start with GB_ class WebhookService extends Service { async translateMsg(data = {}, platform, gitlabEvent) { - const { template, response, color } = this.config; + const { template, response, color, showOriginal } = this.config; + + const isShowOriginal = process.env['SHOW_ORIGINAL'] || showOriginal; // set templage, response, color code if (!template[platform]) { @@ -58,6 +60,9 @@ class WebhookService extends Service { break; } + if (!content.length && isShowOriginal) content.push(JSON.stringify(data)); + if (!content.length) return false; + const { path, body } = this.response; this.setJsonValue(body, path, content.join()); return body; diff --git a/config/config.default.js b/config/config.default.js index 09af7b5..801dd21 100644 --- a/config/config.default.js +++ b/config/config.default.js @@ -24,6 +24,7 @@ module.exports = appInfo => { // add your user config here const userConfig = { + showOriginal: false, supportPlatforms: ['qywx', 'feishu'], platform: 'qywx', response: { @@ -50,7 +51,7 @@ module.exports = appInfo => { header: { template: 'blue', title: { - content: 'Gitlab通知', + content: 'Gitlab机器人通知', tag: 'plain_text', }, }, diff --git a/package.json b/package.json index 0fc0f71..8d56c78 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gitlab-bot", - "version": "2.1.0", + "version": "2.2.0", "description": "", "private": true, "egg": { @@ -28,8 +28,8 @@ "node": ">=14.20.0" }, "scripts": { - "start": "egg-scripts start --title=egg-server-gitlab-bot", - "stop": "egg-scripts stop --title=egg-server-gitlab-bot", + "start": "egg-scripts start --title=gitlab-bot", + "stop": "egg-scripts stop --title=gitlab-bot", "dev": "egg-bin dev", "debug": "egg-bin debug", "test": "npm run lint -- --fix && npm run test-local",