mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 22:46:27 +00:00
fix: escape gitlab branch name forward slash (#758)
Forward slash is replaced with %2F. It is assumed that this is backwards compatible with api v3 too. Closes #749
This commit is contained in:
parent
2afa16d63d
commit
ddbbacb363
3 changed files with 32 additions and 9 deletions
|
@ -135,7 +135,10 @@ async function findFilePaths() {
|
||||||
async function branchExists(branchName) {
|
async function branchExists(branchName) {
|
||||||
logger.debug(`Checking if branch exists: ${branchName}`);
|
logger.debug(`Checking if branch exists: ${branchName}`);
|
||||||
try {
|
try {
|
||||||
const url = `projects/${config.repoName}/repository/branches/${branchName}`;
|
const url = `projects/${config.repoName}/repository/branches/${branchName.replace(
|
||||||
|
'/',
|
||||||
|
'%2F'
|
||||||
|
)}`;
|
||||||
const res = await glGot(url);
|
const res = await glGot(url);
|
||||||
if (res.statusCode === 200) {
|
if (res.statusCode === 200) {
|
||||||
logger.debug('Branch exists');
|
logger.debug('Branch exists');
|
||||||
|
@ -158,7 +161,10 @@ async function branchExists(branchName) {
|
||||||
// Returns branch object
|
// Returns branch object
|
||||||
async function getBranch(branchName) {
|
async function getBranch(branchName) {
|
||||||
logger.debug(`getBranch(${branchName})`);
|
logger.debug(`getBranch(${branchName})`);
|
||||||
const url = `projects/${config.repoName}/repository/branches/${branchName}`;
|
const url = `projects/${config.repoName}/repository/branches/${branchName.replace(
|
||||||
|
'/',
|
||||||
|
'%2F'
|
||||||
|
)}`;
|
||||||
try {
|
try {
|
||||||
return (await glGot(url)).body;
|
return (await glGot(url)).body;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -198,7 +204,10 @@ async function getBranchStatus(branchName, requiredStatusChecks) {
|
||||||
return 'failed';
|
return 'failed';
|
||||||
}
|
}
|
||||||
// First, get the branch to find the commit SHA
|
// First, get the branch to find the commit SHA
|
||||||
let url = `projects/${config.repoName}/repository/branches/${branchName}`;
|
let url = `projects/${config.repoName}/repository/branches/${branchName.replace(
|
||||||
|
'/',
|
||||||
|
'%2F'
|
||||||
|
)}`;
|
||||||
let res = await glGot(url);
|
let res = await glGot(url);
|
||||||
const branchSha = res.body.commit.id;
|
const branchSha = res.body.commit.id;
|
||||||
// Now, check the statuses for that commit
|
// Now, check the statuses for that commit
|
||||||
|
@ -226,7 +235,10 @@ async function getBranchStatus(branchName, requiredStatusChecks) {
|
||||||
|
|
||||||
async function getBranchStatusCheck(branchName, context) {
|
async function getBranchStatusCheck(branchName, context) {
|
||||||
// First, get the branch to find the commit SHA
|
// First, get the branch to find the commit SHA
|
||||||
let url = `projects/${config.repoName}/repository/branches/${branchName}`;
|
let url = `projects/${config.repoName}/repository/branches/${branchName.replace(
|
||||||
|
'/',
|
||||||
|
'%2F'
|
||||||
|
)}`;
|
||||||
let res = await glGot(url);
|
let res = await glGot(url);
|
||||||
const branchSha = res.body.commit.id;
|
const branchSha = res.body.commit.id;
|
||||||
// Now, check the statuses for that commit
|
// Now, check the statuses for that commit
|
||||||
|
@ -249,7 +261,10 @@ async function setBranchStatus(
|
||||||
targetUrl
|
targetUrl
|
||||||
) {
|
) {
|
||||||
// First, get the branch to find the commit SHA
|
// First, get the branch to find the commit SHA
|
||||||
let url = `projects/${config.repoName}/repository/branches/${branchName}`;
|
let url = `projects/${config.repoName}/repository/branches/${branchName.replace(
|
||||||
|
'/',
|
||||||
|
'%2F'
|
||||||
|
)}`;
|
||||||
const res = await glGot(url);
|
const res = await glGot(url);
|
||||||
const branchSha = res.body.commit.id;
|
const branchSha = res.body.commit.id;
|
||||||
// Now, check the statuses for that commit
|
// Now, check the statuses for that commit
|
||||||
|
@ -267,7 +282,10 @@ async function setBranchStatus(
|
||||||
|
|
||||||
async function deleteBranch(branchName) {
|
async function deleteBranch(branchName) {
|
||||||
await glGot.delete(
|
await glGot.delete(
|
||||||
`projects/${config.repoName}/repository/branches/${branchName}`
|
`projects/${config.repoName}/repository/branches/${branchName.replace(
|
||||||
|
'/',
|
||||||
|
'%2F'
|
||||||
|
)}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -232,7 +232,7 @@ Array [
|
||||||
"projects/some%2Frepo/merge_requests/undefined",
|
"projects/some%2Frepo/merge_requests/undefined",
|
||||||
],
|
],
|
||||||
Array [
|
Array [
|
||||||
"projects/some%2Frepo/repository/branches/undefined",
|
"projects/some%2Frepo/repository/branches/some-branch",
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
`;
|
`;
|
||||||
|
@ -246,8 +246,10 @@ Object {
|
||||||
"body": undefined,
|
"body": undefined,
|
||||||
"commits": 1,
|
"commits": 1,
|
||||||
"deletions": 1,
|
"deletions": 1,
|
||||||
"displayNumber": "Merge Request #undefined",
|
"displayNumber": "Merge Request #91",
|
||||||
|
"iid": 91,
|
||||||
"number": undefined,
|
"number": undefined,
|
||||||
|
"source_branch": "some-branch",
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
@ -284,6 +286,7 @@ Object {
|
||||||
"isUnmergeable": true,
|
"isUnmergeable": true,
|
||||||
"merge_status": "cannot_be_merged",
|
"merge_status": "cannot_be_merged",
|
||||||
"number": 12345,
|
"number": 12345,
|
||||||
|
"source_branch": "some-branch",
|
||||||
"state": "merged",
|
"state": "merged",
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
|
@ -263,10 +263,11 @@ describe('api/gitlab', () => {
|
||||||
}));
|
}));
|
||||||
glGot.mockImplementationOnce(() => ({
|
glGot.mockImplementationOnce(() => ({
|
||||||
body: {
|
body: {
|
||||||
number: 91,
|
iid: 91,
|
||||||
additions: 1,
|
additions: 1,
|
||||||
deletions: 1,
|
deletions: 1,
|
||||||
commits: 1,
|
commits: 1,
|
||||||
|
source_branch: 'some-branch',
|
||||||
base: {
|
base: {
|
||||||
sha: '1234',
|
sha: '1234',
|
||||||
},
|
},
|
||||||
|
@ -574,6 +575,7 @@ describe('api/gitlab', () => {
|
||||||
description: 'a merge request',
|
description: 'a merge request',
|
||||||
state: 'merged',
|
state: 'merged',
|
||||||
merge_status: 'cannot_be_merged',
|
merge_status: 'cannot_be_merged',
|
||||||
|
source_branch: 'some-branch',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
glGot.mockReturnValueOnce({
|
glGot.mockReturnValueOnce({
|
||||||
|
|
Loading…
Reference in a new issue