Commit aeff93d1 by 前端

完善数据结构,消息通知简易版完成

1 parent bcbbaf9a
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Node.js CI
on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
schedule:
- cron: '0 2 * * *'
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
node-version: [10]
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Checkout Git Source
uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install Dependencies
run: npm i -g npminstall@5 && npminstall
- name: Continuous Integration
run: npm run ci
- name: Code Coverage
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
'use strict';
const Controller = require('egg').Controller;
class baseController extends Controller {
async create() {
if (this.createRule) this.ctx.validate(this.createRule, this.ctx.request.body);
const data = await this.ctx.service[this.entity].create(this.ctx.request.body);
if (data) this.success('创建成功', data);
}
async findAll() {
const param = {order: [["createDate", "DESC"]]}
if(this.findAllQuery) param = {...param, ...this.findAllQuery}
const data = await this.ctx.service[this.entity].findAll(param);
if (data) this.success('请求成功', data);
}
async findOne() {
const param = {id: this.ctx.request.query.id}
if(this.findOneQuery) param = {...param, ...this.findOneQuery}
const data = await this.ctx.service[this.entity].findOne(param);
if (data) this.success('请求成功', data);
}
async update() {
const param = this.ctx.request.body
if(this.updateParam) param = {...param, ...this.updateParam}
const data = await this.ctx.service[this.entity].update(param);
if (data) this.success('修改成功', data);
}
async destroy() {
const param = {id: this.ctx.request.body.id}
if(this.destroyeQuery) param = {...param, ...this.destroyQuery}
const data = await this.ctx.service[this.entity].destroy(param);
if (data) this.success('删除成功', data);
}
success(msg, data) {
this.ctx.body = {
code: 200,
message: msg || '请求成功',
data: data || null,
};
}
notFound(msg, data) {
this.ctx.body = {
code: -1,
message: msg || 'not Found',
data: data || null,
};
}
}
module.exports = baseController;
"use strict";
const Controller = require("egg").Controller;
class HomeController extends Controller {
async index() {
const { ctx } = this;
ctx.body = "hi, egg";
}
}
module.exports = HomeController;
......@@ -13,21 +13,27 @@ class SentryController extends Controller {
params,
request: { body },
} = this.ctx;
console.log(params);
console.log(body);
let bodyJson = JSON.stringify(body);
let paramsJson = JSON.stringify(params);
let data = body && body.data && body.data.issue ? body.data.issue : {};
const ROBOT_DATA = {
msgtype: "markdown",
markdown: {
content: `!!!前端项目<font color=\"warning\">${
body.project_name
data.shortId
}</font>发生错误:
> 错误原因: <font color=\"info\">${body.culprit}</font>
> 错误原因: <font color=\"info\">${data.title}</font>
> 错误目录: <font color=\"info\">${data.culprit}</font>
> 错误时间: <font color=\"info\">${fmtDateTime()}</font>
> 错误级别: <font color=\"info\">${body.level}</font>
> 错误链接: [查看日志](${body.url})
> 错误级别: <font color=\"info\">${data.level}</font>
> 错误链接: [查看日志](${data.url || data.permalink})
> 错误body: <font color=\"info\">${bodyJson}</font>
\n
请以下同事注意:${genProjectOwners(SENTRY_HOOKS.SCRM.owners)}`,
},
};
console.log(this.ctx.curl);
const result = await this.ctx.curl(
"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=2f2ba84b-1b7f-4556-8508-e6c605e2671c",
{
......
'use strict';
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const Project = app.model.define('project', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
addr: {
type: STRING(20),
unique: {
args: true,
msg: '项目地址不能重复',
},
},
name: {
type: STRING(30),
unique: {
args: true,
msg: '项目名称不能重复',
},
},
remark: STRING(200)
}, {
timestamps: true,
createdAt: 'createDate',
updatedAt: 'updateDate',
});
return Project;
};
......@@ -5,7 +5,6 @@
*/
module.exports = (app) => {
const { router, controller } = app;
router.get("/", controller.home.index);
router.post("/sentry", controller.robot.recvSentryWebhook);
};
const Service = require("egg").Service;
// [this.entity] 对应的是model中的文件名
class BaseService extends Service {
// 创建
async create(data) {
return await this.app.model[this.entity].create(data);
}
async findAll(where) {
return await this.app.model[this.entity].findAll(where);
}
// 查询一条
async findOne(where) {
return await this.app.model[this.entity].findOne({ where });
}
// 修改
async update(data) {
const { id, ...where } = data;
return await this.app.model[this.entity].update(where, {
where: { id },
});
}
// 删除
async destroy(where) {
return await this.app.model[this.entity].destroy({ where });
}
}
module.exports = BaseService;
exports.mysql = {
// 单数据库信息配置
client: {
// host
host: 'localhost',
// 端口号
port: '3306',
// 用户名
user: 'root',
// 密码
password: '123456',
// 数据库名
database: 'base_egg',
},
// 是否加载到 app 上,默认开启
app: true,
// 是否加载到 agent 上,默认关闭
agent: false,
};
\ No newline at end of file
/* eslint valid-jsdoc: "off" */
'use strict';
const { mysql } = require('../config/confg.dev');
"use strict";
/**
* @param {Egg.EggAppInfo} appInfo app info
*/
module.exports = appInfo => {
module.exports = (appInfo) => {
/**
* built-in config
* @type {Egg.EggAppConfig}
**/
const config = exports = {};
const config = (exports = {});
// use for cookie sign key, should change to your own and keep security
// config.keys = appInfo.name + '_1646015306357_8919';
......@@ -46,34 +44,33 @@ module.exports = appInfo => {
csrf: {
enable: false,
},
domainWhiteList: [ '*' ],
domainWhiteList: ["*"],
};
config.cors = {
origin: '*',
allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS',
origin: "*",
allowMethods: "GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS",
};
// config.mysql = mysql;
config.sequelize = {
dialect: 'mysql', // support: mysql, mariadb, postgres, mssql
database: 'base_egg',
host: 'localhost',
port: 3306,
username: 'root',
password: '123456',
define: {
underscored: false,
freezeTableName: true,
timestamps: false,
},
};
// config.sequelize = {
// dialect: "mysql", // support: mysql, mariadb, postgres, mssql
// database: "base_egg",
// host: "localhost",
// port: 3306,
// username: "root",
// password: "123456",
// define: {
// underscored: false,
// freezeTableName: true,
// timestamps: false,
// },
// };
// 登录鉴权
config.jwt = {
secret: 'glsx-config-center',
};
// config.jwt = {
// secret: "glsx-config-center",
// };
// 错误监听
// config.onerror = {
......@@ -96,7 +93,7 @@ module.exports = appInfo => {
listen: {
// path: '',
// port: 7001,
hostname: '0.0.0.0',
hostname: "0.0.0.0",
},
};
......
'use strict';
"use strict";
/** @type Egg.EggPlugin */
module.exports = {
......@@ -7,26 +7,26 @@ module.exports = {
// enable: true,
// }
// 跨域配置
cors: {
enable: true,
package: 'egg-cors'
},
// cors: {
// enable: true,
// package: 'egg-cors'
// },
// 登录鉴权
jwt: {
enable: true,
package: 'egg-jwt',
},
// jwt: {
// enable: true,
// package: "egg-jwt",
// },
// 数据格式校验
validate: {
enable: true,
package: 'egg-validate',
package: "egg-validate",
},
//egg-sequelize
sequelize: {
enable: true,
package: 'egg-sequelize',
},
};
\ No newline at end of file
// sequelize: {
// enable: true,
// package: "egg-sequelize",
// },
};
......@@ -7,17 +7,11 @@
"declarations": true
},
"dependencies": {
"ali-oss": "^6.17.1",
"crypto": "^1.0.1",
"egg": "^2.15.1",
"egg-cors": "^2.2.3",
"egg-jwt": "^3.1.7",
"egg-mysql": "^3.1.0",
"egg-scripts": "^2.11.0",
"egg-sequelize": "^6.0.0",
"egg-validate": "^2.0.2",
"moment": "^2.29.1",
"mysql2": "^2.3.3"
"moment": "^2.29.1"
},
"devDependencies": {
"autod": "^3.0.1",
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!