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 { ...@@ -13,21 +13,27 @@ class SentryController extends Controller {
params, params,
request: { body }, request: { body },
} = this.ctx; } = 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 = { const ROBOT_DATA = {
msgtype: "markdown", msgtype: "markdown",
markdown: { markdown: {
content: `!!!前端项目<font color=\"warning\">${ content: `!!!前端项目<font color=\"warning\">${
body.project_name data.shortId
}</font>发生错误: }</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\">${fmtDateTime()}</font>
> 错误级别: <font color=\"info\">${body.level}</font> > 错误级别: <font color=\"info\">${data.level}</font>
> 错误链接: [查看日志](${body.url}) > 错误链接: [查看日志](${data.url || data.permalink})
> 错误body: <font color=\"info\">${bodyJson}</font>
\n \n
请以下同事注意:${genProjectOwners(SENTRY_HOOKS.SCRM.owners)}`, 请以下同事注意:${genProjectOwners(SENTRY_HOOKS.SCRM.owners)}`,
}, },
}; };
console.log(this.ctx.curl);
const result = await this.ctx.curl( const result = await this.ctx.curl(
"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=2f2ba84b-1b7f-4556-8508-e6c605e2671c", "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 @@ ...@@ -5,7 +5,6 @@
*/ */
module.exports = (app) => { module.exports = (app) => {
const { router, controller } = app; const { router, controller } = app;
router.get("/", controller.home.index);
router.post("/sentry", controller.robot.recvSentryWebhook); 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 \ No newline at end of file
/* eslint valid-jsdoc: "off" */ /* eslint valid-jsdoc: "off" */
'use strict'; "use strict";
const { mysql } = require('../config/confg.dev');
/** /**
* @param {Egg.EggAppInfo} appInfo app info * @param {Egg.EggAppInfo} appInfo app info
*/ */
module.exports = appInfo => { module.exports = (appInfo) => {
/** /**
* built-in config * built-in config
* @type {Egg.EggAppConfig} * @type {Egg.EggAppConfig}
**/ **/
const config = exports = {}; const config = (exports = {});
// use for cookie sign key, should change to your own and keep security // use for cookie sign key, should change to your own and keep security
// config.keys = appInfo.name + '_1646015306357_8919'; // config.keys = appInfo.name + '_1646015306357_8919';
...@@ -46,34 +44,33 @@ module.exports = appInfo => { ...@@ -46,34 +44,33 @@ module.exports = appInfo => {
csrf: { csrf: {
enable: false, enable: false,
}, },
domainWhiteList: [ '*' ], domainWhiteList: ["*"],
}; };
config.cors = { config.cors = {
origin: '*', origin: "*",
allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS', allowMethods: "GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS",
}; };
// config.mysql = mysql; // config.mysql = mysql;
config.sequelize = { // config.sequelize = {
dialect: 'mysql', // support: mysql, mariadb, postgres, mssql // dialect: "mysql", // support: mysql, mariadb, postgres, mssql
database: 'base_egg', // database: "base_egg",
host: 'localhost', // host: "localhost",
port: 3306, // port: 3306,
username: 'root', // username: "root",
password: '123456', // password: "123456",
define: { // define: {
underscored: false, // underscored: false,
freezeTableName: true, // freezeTableName: true,
timestamps: false, // timestamps: false,
}, // },
}; // };
// 登录鉴权 // 登录鉴权
config.jwt = { // config.jwt = {
secret: 'glsx-config-center', // secret: "glsx-config-center",
}; // };
// 错误监听 // 错误监听
// config.onerror = { // config.onerror = {
...@@ -96,7 +93,7 @@ module.exports = appInfo => { ...@@ -96,7 +93,7 @@ module.exports = appInfo => {
listen: { listen: {
// path: '', // path: '',
// port: 7001, // port: 7001,
hostname: '0.0.0.0', hostname: "0.0.0.0",
}, },
}; };
......
'use strict'; "use strict";
/** @type Egg.EggPlugin */ /** @type Egg.EggPlugin */
module.exports = { module.exports = {
...@@ -7,26 +7,26 @@ module.exports = { ...@@ -7,26 +7,26 @@ module.exports = {
// enable: true, // enable: true,
// } // }
// 跨域配置 // 跨域配置
cors: { // cors: {
enable: true, // enable: true,
package: 'egg-cors' // package: 'egg-cors'
}, // },
// 登录鉴权 // 登录鉴权
jwt: { // jwt: {
enable: true, // enable: true,
package: 'egg-jwt', // package: "egg-jwt",
}, // },
// 数据格式校验 // 数据格式校验
validate: { validate: {
enable: true, enable: true,
package: 'egg-validate', package: "egg-validate",
}, },
//egg-sequelize //egg-sequelize
sequelize: { // sequelize: {
enable: true, // enable: true,
package: 'egg-sequelize', // package: "egg-sequelize",
}, // },
}; };
...@@ -7,17 +7,11 @@ ...@@ -7,17 +7,11 @@
"declarations": true "declarations": true
}, },
"dependencies": { "dependencies": {
"ali-oss": "^6.17.1",
"crypto": "^1.0.1",
"egg": "^2.15.1", "egg": "^2.15.1",
"egg-cors": "^2.2.3", "egg-cors": "^2.2.3",
"egg-jwt": "^3.1.7",
"egg-mysql": "^3.1.0",
"egg-scripts": "^2.11.0", "egg-scripts": "^2.11.0",
"egg-sequelize": "^6.0.0",
"egg-validate": "^2.0.2", "egg-validate": "^2.0.2",
"moment": "^2.29.1", "moment": "^2.29.1"
"mysql2": "^2.3.3"
}, },
"devDependencies": { "devDependencies": {
"autod": "^3.0.1", "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!