Skip to content

Commit

Permalink
fix(bitbucket): branchname containing slash (#2963)
Browse files Browse the repository at this point in the history
  • Loading branch information
barthc authored and erezrokah committed Dec 13, 2019
1 parent 1e77d4b commit afea448
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/netlify-cms-backend-bitbucket/src/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down Expand Up @@ -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 };
};

Expand Down

0 comments on commit afea448

Please sign in to comment.