You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
riskcloudrun/routes/index.js

59 lines
1.4 KiB

var express = require('express');
var router = express.Router();
var moment = require('moment')
const {spawn} = require('child_process');
const _info='info'
const _error='error'
function log(param,message){
console[param](`${moment().utcOffset(480).format('yyyy-MM-DD HH:mm:ss')}:${message}`)
}
function info(message){
log(_info,message)
}
function error(message){
log(_error,message)
}
//web钩子事件
//git@gogs.kirito.cool:panqihua/RiskCloudMock.git push事件
router.post('/deploy', function(req, res, next) {
const updated_at=req.body.repository.updated_at
const name=req.body.repository.name
info(`开始自动部署${name}`)
const promise = new Promise((resolve, reject) => {
const spawnObj = spawn('updateRisk', [name], {encoding: 'utf-8'});
spawnObj.stdout.on('data', function(chunk) {
info(chunk.toString());
});
spawnObj.stderr.on('data', (data) => {
error(data);
});
spawnObj.on('close', function(code) {
info('close code : ' + code);
})
spawnObj.on('exit', (code) => {
info('exit code : ' + code);
resolve(true)
})
})
res.json({message:`仓库代码${req.body.repository.ssh_url}部署中`})
});
//部署完毕事件
router.get('/finsh', function(req, res, next) {
info(`仓库代码${req.query.name}部署成功`)
res.json({message:`仓库代码${req.query.name}部署成功`})
});
module.exports = router;