最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

有没有一种方法可以通过nodejs获取git origin分支代码

IT培训 admin 5浏览 0评论

有没有一种方法可以通过nodejs获取git origin分支代码

当触发事件触发时,我在项目中添加了一个git钩子。

当钩子被触发并且参考值为refs/heads/master时,产品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();
});
回答如下:

我使用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);
});

有没有一种方法可以通过nodejs获取git origin分支代码

当触发事件触发时,我在项目中添加了一个git钩子。

当钩子被触发并且参考值为refs/heads/master时,产品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();
});
回答如下:

我使用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);
});
发布评论

评论列表 (0)

  1. 暂无评论