renovate/lib/platform/gitlab/helpers.js
Rhys Arkins edfca74ede
refactor: make common platform public API (#1104)
Refactors file system of platforms and adds test to ensure GitHub and GitLab have same module.exports signatures.
2017-11-05 08:18:20 +01:00

49 lines
900 B
JavaScript

const get = require('./gl-got-wrapper');
module.exports = {
createFile,
updateFile,
};
async function createFile(
repoName,
branchName,
filePath,
fileContents,
message
) {
const opts = {};
const url = `projects/${repoName}/repository/files/${filePath.replace(
/\//g,
'%2F'
)}`;
opts.body = {
branch: branchName,
commit_message: message,
encoding: 'base64',
content: Buffer.from(fileContents).toString('base64'),
};
await get.post(url, opts);
}
async function updateFile(
repoName,
branchName,
filePath,
fileContents,
message
) {
const opts = {};
const url = `projects/${repoName}/repository/files/${filePath.replace(
/\//g,
'%2F'
)}`;
opts.body = {
branch: branchName,
commit_message: message,
encoding: 'base64',
content: Buffer.from(fileContents).toString('base64'),
};
await get.put(url, opts);
}