mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 22:46:27 +00:00
fix: use baseBranch when branchName is null (#643)
Using fallback in function params only replaces if branchName is undefined but we also need to handle when it is `null`.
This commit is contained in:
parent
57091a1cb4
commit
b369f670d6
3 changed files with 12 additions and 8 deletions
|
@ -636,14 +636,16 @@ async function mergePr(pr) {
|
||||||
|
|
||||||
// Generic File operations
|
// Generic File operations
|
||||||
|
|
||||||
async function getFile(filePath, branchName = config.baseBranch) {
|
async function getFile(filePath, branchName) {
|
||||||
|
logger.trace(`getFile(filePath=${filePath}, branchName=${branchName})`);
|
||||||
const res = await ghGotRetry(
|
const res = await ghGotRetry(
|
||||||
`repos/${config.repoName}/contents/${filePath}?ref=${branchName}`
|
`repos/${config.repoName}/contents/${filePath}?ref=${branchName ||
|
||||||
|
config.baseBranch}`
|
||||||
);
|
);
|
||||||
return res.body.content;
|
return res.body.content;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getFileContent(filePath, branchName = config.baseBranch) {
|
async function getFileContent(filePath, branchName) {
|
||||||
logger.trace(
|
logger.trace(
|
||||||
`getFileContent(filePath=${filePath}, branchName=${branchName})`
|
`getFileContent(filePath=${filePath}, branchName=${branchName})`
|
||||||
);
|
);
|
||||||
|
|
|
@ -381,13 +381,15 @@ async function mergePr(pr) {
|
||||||
|
|
||||||
// Generic File operations
|
// Generic File operations
|
||||||
|
|
||||||
async function getFile(filePath, branchName = config.baseBranch) {
|
async function getFile(filePath, branchName) {
|
||||||
// Gitlab API v3 support
|
// Gitlab API v3 support
|
||||||
let url;
|
let url;
|
||||||
if (config.apiVersion === 'v3') {
|
if (config.apiVersion === 'v3') {
|
||||||
url = `projects/${config.repoName}/repository/files?file_path=${filePath}&ref=${branchName}`;
|
url = `projects/${config.repoName}/repository/files?file_path=${filePath}&ref=${branchName ||
|
||||||
|
config.baseBranch}`;
|
||||||
} else {
|
} else {
|
||||||
url = `projects/${config.repoName}/repository/files/${filePath}?ref=${branchName}`;
|
url = `projects/${config.repoName}/repository/files/${filePath}?ref=${branchName ||
|
||||||
|
config.baseBranch}`;
|
||||||
}
|
}
|
||||||
const res = await glGot(url);
|
const res = await glGot(url);
|
||||||
return res.body.content;
|
return res.body.content;
|
||||||
|
|
|
@ -516,7 +516,7 @@ describe('api/gitlab', () => {
|
||||||
content: 'foo',
|
content: 'foo',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const res = await gitlab.getFile('some-path', 'some-branch');
|
const res = await gitlab.getFile('some-path');
|
||||||
expect(res).toMatchSnapshot();
|
expect(res).toMatchSnapshot();
|
||||||
expect(glGot.mock.calls[0][0].indexOf('file_path')).toBe(-1);
|
expect(glGot.mock.calls[0][0].indexOf('file_path')).toBe(-1);
|
||||||
});
|
});
|
||||||
|
@ -537,7 +537,7 @@ describe('api/gitlab', () => {
|
||||||
});
|
});
|
||||||
const config = await gitlab.initRepo('some-repo', 'some-token');
|
const config = await gitlab.initRepo('some-repo', 'some-token');
|
||||||
expect(config).toMatchSnapshot();
|
expect(config).toMatchSnapshot();
|
||||||
const res = await gitlab.getFile('some-path', 'some-branch');
|
const res = await gitlab.getFile('some-path');
|
||||||
expect(res).toMatchSnapshot();
|
expect(res).toMatchSnapshot();
|
||||||
expect(glGot.mock.calls[3][0].indexOf('file_path')).not.toBe(-1);
|
expect(glGot.mock.calls[3][0].indexOf('file_path')).not.toBe(-1);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue