From afea44895b9ef7379f5a8726a60fb4d371c76ebf Mon Sep 17 00:00:00 2001 From: Bartholomew Date: Fri, 13 Dec 2019 16:23:43 +0100 Subject: [PATCH] fix(bitbucket): branchname containing slash (#2963) --- .../netlify-cms-backend-bitbucket/src/API.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/netlify-cms-backend-bitbucket/src/API.js b/packages/netlify-cms-backend-bitbucket/src/API.js index 437922bb..2ce7bb48 100644 --- a/packages/netlify-cms-backend-bitbucket/src/API.js +++ b/packages/netlify-cms-backend-bitbucket/src/API.js @@ -55,6 +55,15 @@ export default class API { return response.ok; }; + branchCommitSha = async () => { + if (this.branchSha) return this.branchSha; + + ({ + target: { hash: this.branchSha }, + } = await this.requestJSON(`${this.repoURL}/refs/branches/${this.branch}`)); + return this.branchSha; + }; + isFile = ({ type }) => type === 'commit_file'; processFile = file => ({ ...file, @@ -70,14 +79,15 @@ export default class API { }); processFiles = files => files.filter(this.isFile).map(this.processFile); - readFile = async (path, sha, { ref = this.branch, parseText = true } = {}) => { + readFile = async (path, sha, { parseText = true } = {}) => { const cacheKey = parseText ? `bb.${sha}` : `bb.${sha}.blob`; const cachedFile = sha ? await localForage.getItem(cacheKey) : null; if (cachedFile) { return cachedFile; } + const node = await this.branchCommitSha(); const result = await this.request({ - url: `${this.repoURL}/src/${ref}/${path}`, + url: `${this.repoURL}/src/${node}/${path}`, cache: 'no-store', }).then(parseText ? responseParser({ format: 'text' }) : responseParser({ format: 'blob' })); if (sha) { @@ -107,12 +117,13 @@ export default class API { }; listFiles = async path => { + const node = await this.branchCommitSha(); const { entries, cursor } = await flow([ // sort files by filename ascending unsentRequest.withParams({ sort: '-path', max_depth: 10 }), this.requestJSON, then(this.getEntriesAndCursor), - ])(`${this.repoURL}/src/${this.branch}/${path}`); + ])(`${this.repoURL}/src/${node}/${path}`); return { entries: this.processFiles(entries), cursor }; };