Есть ли способ, которым я могу получить код ветви git origin от nodejs - PullRequest
0 голосов
/ 30 сентября 2019

Я добавил ловушку git в свой проект при срабатывании события push.

Когда ловушка запущена и значение 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();
});

1 Ответ

0 голосов
/ 30 сентября 2019

Я получил содержимое 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);
});
...