Skip to content

Commit

Permalink
Dev to master, v2.2.0 finish feishu notification (#14)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
goodideal authored Sep 7, 2023
1 parent c3e1a3a commit 80f98fc
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -62,8 +62,10 @@ Gitlab pipeline 流水线

### 环境变量

- `PLATFORM``qywx`, `feishu`,即:企业微信、飞书;

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

### 与企业微信对接

Expand All @@ -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


## 应用部署运行
Expand Down
7 changes: 6 additions & 1 deletion app/service/webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion config/config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = appInfo => {

// add your user config here
const userConfig = {
showOriginal: false,
supportPlatforms: ['qywx', 'feishu'],
platform: 'qywx',
response: {
Expand All @@ -50,7 +51,7 @@ module.exports = appInfo => {
header: {
template: 'blue',
title: {
content: 'Gitlab通知',
content: 'Gitlab机器人通知',
tag: 'plain_text',
},
},
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gitlab-bot",
"version": "2.1.0",
"version": "2.2.0",
"description": "",
"private": true,
"egg": {
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 80f98fc

Please sign in to comment.