Skip to content

Commit 5565b17

Browse files
goodidealJerryZ
andauthored
merge to dev, use mustache as template engine (#9)
* add mustache * use template for push * remove lock file from ignore * update samples and apply templates * npm use --omit=dev * use package-lock.json for npm i * copy package.json * fix push op string missing issue * finish pipeline template and optimize push * add file change from commits * optimize push and pipeline * finish mr * finish tag_push * finish wiki * remove dept from lodash and string * v2.0.0, update readme --------- Co-authored-by: JerryZ <jerry@ezpro.com>
1 parent 25eb776 commit 5565b17

26 files changed

+24734
-877
lines changed

.eslintrc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
{
2-
"extends": "eslint-config-egg"
2+
"plugins": ["prettier"],
3+
"rules": {
4+
"prettier/prettier": [
5+
"error"
6+
]
7+
},
8+
"extends": ["plugin:prettier/recommended", "eslint-config-egg"]
39
}

.github/workflows/nodejs.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+
name: Node.js CI
5+
6+
on:
7+
push:
8+
branches:
9+
- main
10+
- master
11+
pull_request:
12+
branches:
13+
- main
14+
- master
15+
schedule:
16+
- cron: '0 2 * * *'
17+
18+
jobs:
19+
build:
20+
runs-on: ${{ matrix.os }}
21+
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
node-version: [10]
26+
os: [ubuntu-latest, windows-latest, macos-latest]
27+
28+
steps:
29+
- name: Checkout Git Source
30+
uses: actions/checkout@v2
31+
32+
- name: Use Node.js ${{ matrix.node-version }}
33+
uses: actions/setup-node@v3
34+
with:
35+
node-version: ${{ matrix.node-version }}
36+
37+
- name: Install Dependencies
38+
run: npm i
39+
40+
- name: Continuous Integration
41+
run: npm run ci
42+
43+
- name: Code Coverage
44+
uses: codecov/codecov-action@v3
45+
with:
46+
token: ${{ secrets.CODECOV_TOKEN }}

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ logs/
22
npm-debug.log
33
yarn-error.log
44
node_modules/
5-
package-lock.json
6-
yarn.lock
75
coverage/
86
.idea/
97
run/

.prettierrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"tabWidth": 2,
44
"semi": true,
55
"singleQuote": true,
6-
"arrowParens": "avoid"
6+
"arrowParens": "avoid",
7+
"bracketSpacing": true
78
}

Dockerfile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM library/node:lts-alpine
22

3-
# 设置时区
3+
# set timezone
44
ENV TIME_ZONE=Asia/Shanghai
55

66
RUN \
@@ -9,11 +9,10 @@ RUN \
99

1010
WORKDIR /app
1111

12-
COPY package.json package-lock.json
12+
COPY package.json package.json
13+
COPY package-lock.json package-lock.json
1314

14-
RUN \
15-
npm config set registry https://registry.npmmirror.com/ \
16-
&& npm i --no-audit --no-fund --production
15+
RUN npm i --no-audit --no-fund --omit=dev
1716

1817
EXPOSE 7001
1918

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
# Gitlab通知机器人
22

3-
`Gitlab``push``tag push``merge request``pipeline`推送到企业微信的机器人。
3+
`Gitlab``push``tag push``merge request``pipeline`推送到第三方IM平台的机器人,如企业微信、飞书等;
4+
5+
`1.0.0`: 采用内置代码,且仅支持企业微信;
6+
7+
`2.0.0`: 通过消息模板,可自行配置通知消息格式和字段,具体配置方式,参见[mustache官方文档](https://github.com/janl/mustache.js)
8+
9+
todo:
10+
11+
- [X] 使用mustache模板
12+
- [X] 增加note通知
13+
- [ ] 增加消息模板配置文件
14+
- [ ] 支持飞书机器人
15+
- [ ] 支持按天统计数据
16+
17+
18+
---
19+
20+
### 功能展示
421

522
具体见下图:
623

@@ -45,7 +62,7 @@ Gitlab pipeline 流水线
4562

4663
则环境变量设为:
4764
```
48-
WEBHOOK_URL_QYWX=https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=ABCDEFG
65+
WEBHOOK_URL_PROJ=https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=ABCDEFG
4966
```
5067

5168
一个应用可以添加多个推送组。

app/controller/home.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
'use strict';
22

33
const Controller = require('egg').Controller;
4-
const S = require('string');
5-
64
class HomeController extends Controller {
75
async index() {
86
const { ctx } = this;
97
const { path = '' } = ctx.params;
10-
118
const webhookUrl =
129
process.env['WEBHOOK_URL' + (path ? '_' + path.toUpperCase() : '')];
1310

11+
this.logger.debug('webhookUrl', webhookUrl);
12+
1413
this.logger.info('request body: ', ctx.request.body);
1514
const message = await ctx.service.webhook.translateMsg(ctx.request.body);
1615

app/router.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
'use strict';
22

3-
const S = require('string');
43
const contextPath = process.env.CONTEXT_PATH || '/';
5-
const contextPathEndWithSlash = S(contextPath).endsWith('/')
4+
const contextPathEndWithSlash = contextPath.endsWith('/')
65
? contextPath
76
: contextPath + '/';
87

0 commit comments

Comments
 (0)