1 Star 0 Fork 0

fengyexjtu/gitee-webhook

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index.js 2.16 KB
一键复制 编辑 原始数据 按行查看 历史
fengyexjtu 提交于 2024-08-17 10:16 . fix:shell position
var http = require('http');
var config = require('./config.js');
var createHandler = require('gitee-webhook-handler');
var handler = createHandler({ path: config.path, secret: config.secret});
const log4js = require('log4js');
log4js.configure({
appenders: {
console: { type: 'console' },
file:{type: 'file', filename: "./logs/auto_deploy.log", maxLogSize: 10485760, backups: 5}
},
categories: {
default: {appenders: ['console','file'], level: 'info'}
},
pm2: true,
pm2InstanceVar: 'INSTANCE_ID'
});
const logger = log4js.getLogger("index");
//Windows下执行方法
function win_run_cmd(name) {
var exec = require('child_process').exec;
exec(name+'.bat', function(error, stdout, stderr){
if (error) {
logger.error(name +": "+ error);
}
if (stdout) {
logger.info(name +": "+ stdout);
}
if (stderr) {
logger.error(name +": "+ stderr);
}
});
}
//Linux下执行方法
function linux_run_cmd(cmd, args) {
var spawn = require('child_process').spawn;
var child = spawn(cmd, args);
var resp = "";
child.stdout.on('data', function(buffer) { resp += buffer.toString(); });
child.stdout.on('end', function() {
logger.info(args +": "+ resp);
});
}
handler.on('error', function (err) {
logger.error('Error:', err.message)
});
handler.on('Push Hook', function (event) {
logger.info('Received a push event for %s to %s',
event.payload.repository.name,
event.payload.ref
);
if(event.payload.ref=="refs/heads/master"){
if(os=="linux"){
linux_run_cmd('sh', ['/opt/gardenia.sh']);//需要执行的脚本位置
}
else{
win_run_cmd(event.payload.repository.name);
}
}
});
handler.on('issues', function (event) {
logger.info('Received an issue event for % action=%s: #%d %s',
event.payload.repository.name,
event.payload.action,
event.payload.issue.number,
event.payload.issue.title
);
});
//启动服务器
http.createServer(function (req, res) {
handler(req, res, function (err) {
res.statusCode = 404;
res.end('no such location')
})
}).listen(config.port);
logger.info("Gitee Hook Server running...");
logger.info("Gitee Hook Server port: " + config.port);
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/fengyexjtu/gitee-webhook.git
[email protected]:fengyexjtu/gitee-webhook.git
fengyexjtu
gitee-webhook
gitee-webhook
master

搜索帮助