diff --git a/lib/platform/bitbucket-server/index.ts b/lib/platform/bitbucket-server/index.ts index 138b3a509b382f..56901a18c2a848 100644 --- a/lib/platform/bitbucket-server/index.ts +++ b/lib/platform/bitbucket-server/index.ts @@ -723,6 +723,8 @@ export async function findPr( // Pull Request +const escapeHash = input => (input ? input.replace(/#/g, '%23') : input); + export async function createPr( branchName: string, title: string, @@ -743,7 +745,11 @@ export async function createPr( )).body; const defReviewers = (await api.get( - `./rest/default-reviewers/1.0/projects/${config.projectKey}/repos/${config.repositorySlug}/reviewers?sourceRefId=refs/heads/${branchName}&targetRefId=refs/heads/${base}&sourceRepoId=${id}&targetRepoId=${id}` + `./rest/default-reviewers/1.0/projects/${config.projectKey}/repos/${ + config.repositorySlug + }/reviewers?sourceRefId=refs/heads/${escapeHash( + branchName + )}&targetRefId=refs/heads/${base}&sourceRepoId=${id}&targetRepoId=${id}` )).body; reviewers = defReviewers.map((u: { name: string }) => ({ diff --git a/lib/platform/bitbucket/index.ts b/lib/platform/bitbucket/index.ts index 2ae735f1f37f2a..0044ea30642c20 100644 --- a/lib/platform/bitbucket/index.ts +++ b/lib/platform/bitbucket/index.ts @@ -712,11 +712,15 @@ export function getPrBody(input: string) { .replace(/\]\(\.\.\/pull\//g, '](../../pull-requests/'); } +const escapeHash = input => (input ? input.replace(/#/g, '%23') : input); + // Return the commit SHA for a branch async function getBranchCommit(branchName: string) { try { const branch = (await api.get( - `/2.0/repositories/${config.repository}/refs/branches/${branchName}` + `/2.0/repositories/${config.repository}/refs/branches/${escapeHash( + branchName + )}` )).body; return branch.target.hash; } catch (err) /* istanbul ignore next */ { diff --git a/lib/platform/github/index.ts b/lib/platform/github/index.ts index 7d47d25d42f830..0bfc58a4acfe03 100644 --- a/lib/platform/github/index.ts +++ b/lib/platform/github/index.ts @@ -73,6 +73,8 @@ const defaults = { endpoint: 'https://api.github.com/', }; +const escapeHash = input => (input ? input.replace(/#/g, '%23') : input); + export async function initPlatform({ endpoint, token, @@ -431,7 +433,7 @@ export async function getRepoForceRebase() { async function getBranchCommit(branchName: string) { try { const res = await api.get( - `repos/${config.repository}/git/refs/heads/${branchName}` + `repos/${config.repository}/git/refs/heads/${escapeHash(branchName)}` ); return res.body.object.sha; } catch (err) /* istanbul ignore next */ { @@ -459,7 +461,7 @@ async function getBranchProtection(branchName: string) { return {}; } const res = await api.get( - `repos/${config.repository}/branches/${branchName}/protection` + `repos/${config.repository}/branches/${escapeHash(branchName)}/protection` ); return res.body; } @@ -574,7 +576,9 @@ export async function getBranchStatus( logger.warn({ requiredStatusChecks }, `Unsupported requiredStatusChecks`); return 'failed'; } - const commitStatusUrl = `repos/${config.repository}/commits/${branchName}/status`; + const commitStatusUrl = `repos/${config.repository}/commits/${escapeHash( + branchName + )}/status`; let commitStatus; try { commitStatus = (await api.get(commitStatusUrl)).body; @@ -595,7 +599,9 @@ export async function getBranchStatus( let checkRuns: { name: string; status: string; conclusion: string }[] = []; if (!config.isGhe) { try { - const checkRunsUrl = `repos/${config.repository}/commits/${branchName}/check-runs`; + const checkRunsUrl = `repos/${config.repository}/commits/${escapeHash( + branchName + )}/check-runs`; const opts = { headers: { Accept: 'application/vnd.github.antiope-preview+json',