From 611ecde4f5240b95fdf346271670cb1fe9b0ee53 Mon Sep 17 00:00:00 2001 From: pan <1029559041@qq.com> Date: Sat, 10 Oct 2020 15:22:15 +0800 Subject: [PATCH] init --- routes/index.js | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/routes/index.js b/routes/index.js index 23ca5ba..f1d6d57 100644 --- a/routes/index.js +++ b/routes/index.js @@ -6,6 +6,7 @@ const {spawn} = require('child_process'); const _info='info' const _error='error' +const access_token='' function log(param,message){ console[param](`${moment().utcOffset(480).format('yyyy-MM-DD HH:mm:ss')}:${message}`) @@ -19,15 +20,43 @@ function error(message){ log(_error,message) } - +function dingding(message){ + info(message) + fetch(`https://oapi.dingtalk.com/robot/send?access_token=${access_token}`,{ + method:'POST', + headers:{ + 'Content-Type':'application/json' + }, + body:{ + msgtype:'text', + text:{ + content:message + } + } + }).then(res=>res.json()).then(res=>info(`钉钉推送结果:${res}`)).catch(err=>error(err)) +} +//记录开始部署的时间 +const startDeploy={} //web钩子事件 //git@gogs.kirito.cool:panqihua/RiskCloudMock.git push事件 router.post('/deploy', function(req, res, next) { + //提交日志,多次提交只取第一个 + const commitsMsg=req.body.commits[0].message + //更新时间 const updated_at=req.body.repository.updated_at + //仓库名字 const name=req.body.repository.name - info(`开始自动部署${name}`) + //仓库描述信息 + const description=req.body.repository.description + + startDeploy[name]={ + startTime:moment(updated_at), + description:description + } + + dingding(`开始自动部署${c.repository.description}|${name},更新日志${commitsMsg}`) const promise = new Promise((resolve, reject) => { const spawnObj = spawn('updateRisk', [name], {encoding: 'utf-8'}); @@ -52,7 +81,8 @@ router.post('/deploy', function(req, res, next) { //部署完毕事件 router.get('/finsh', function(req, res, next) { - info(`仓库代码${req.query.name}部署成功`) + dingding(`${req.query.name}|${startDeploy[req.query.name].description}自动部署成功, + 花费时间:${moment().diff(startDeploy[req.query.name].startTime,'seconds')}`) res.json({message:`仓库代码${req.query.name}部署成功`}) });