javascript - 有没有办法让我通过 nodejs 获取 git origin 分支代码
问题描述
触发推送事件时,我在项目中添加了一个 git 挂钩。
当 hook 被触发并且 ref 值为refs/heads/master
时,prodindex.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();
});
解决方案
我使用包获得了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);
});
推荐阅读
- java - 将流元素映射到 LocalDate 而不收集到列表
- angular - 角度差分构建和原理图?
- tensorflow2.0 - tf.contrib.layers.optimize_loss 在 2.1 版中不起作用 有什么可以替代的吗?
- javascript - 更新子表时更新父表
- c# - 跨数据库的实体框架查询
- javascript - 为什么本地浏览器什么都不显示?
- c# - 使用组合的类中的 MvvmLight
- asp.net-core - 如何增加 ASP.Net Core SOAP ServiceContract 中的字节限制?
- algorithm - 我错误地计算了这个简单的循环复杂度,如何正确计算?
- java - 添加参数来调用一个类会阻止它打开新窗口方法的工作。爪哇外汇