当触发事件触发时,我在项目中添加了一个git钩子。
触发钩子并且ref值为refs/heads/master
时,将更新prod index.html
文件。
我想阅读新的index.html
内容
router.post('/gitHook', async (ctx, next) => {
const body = ctx.request.body;
const matches = body.ref.match(/^refs\/heads\/(.*)/);
const branchName = matches[1];
console.log(branchName);
if(branchName === 'master'){
console.log('should get new code from git origin master')
}
await next();
});
答案 0 :(得分:0)
我使用index.html
软件包获得了gitlab
的内容。
const { Gitlab } = require('gitlab');
const api = new Gitlab({
host: 'myhost',
token: 'myToken',
});
api.RepositoryFiles.show(body.project_id, '/build/index.html', body.ref).then(res => {
const content = res.content;
const stringContent = new Buffer(content, 'base64').toString();
console.log(stringContent);
});