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

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