diff --git a/packages/netlify-cms-backend-git-gateway/src/GitHubAPI.js b/packages/netlify-cms-backend-git-gateway/src/GitHubAPI.js index eeb5b405..2ba63299 100644 --- a/packages/netlify-cms-backend-git-gateway/src/GitHubAPI.js +++ b/packages/netlify-cms-backend-git-gateway/src/GitHubAPI.js @@ -70,22 +70,14 @@ export default class API extends GithubAPI { return Promise.resolve(this.commitAuthor); } - request(path, options = {}) { + request(path, options = {}, parseResponse = response => this.parseResponse(response)) { const url = this.urlFor(path, options); let responseStatus; return this.getRequestHeaders(options.headers || {}) .then(headers => fetch(url, { ...options, headers })) .then(response => { responseStatus = response.status; - const contentType = response.headers.get('Content-Type'); - if (contentType && contentType.match(/json/)) { - return this.parseJsonResponse(response); - } - const text = response.text(); - if (!response.ok) { - return Promise.reject(text); - } - return text; + return parseResponse(response); }) .catch(error => { throw new APIError(error.message || error.msg, responseStatus, 'Git Gateway'); diff --git a/packages/netlify-cms-backend-github/src/GraphQLAPI.js b/packages/netlify-cms-backend-github/src/GraphQLAPI.js index 81770f17..205d3439 100644 --- a/packages/netlify-cms-backend-github/src/GraphQLAPI.js +++ b/packages/netlify-cms-backend-github/src/GraphQLAPI.js @@ -186,11 +186,11 @@ export default class GraphQLAPI extends API { } } - async listFiles(path) { - const { repo_owner: owner, repo_name: name } = this; + async listFiles(path, { repoURL = this.repoURL, branch = this.branch } = {}) { + const { owner, name } = this.getOwnerAndNameFromRepoUrl(repoURL); const { data } = await this.query({ query: queries.files, - variables: { owner, name, expression: `${this.branch}:${path}` }, + variables: { owner, name, expression: `${branch}:${path}` }, }); if (data.repository.object) { diff --git a/packages/netlify-cms-backend-github/src/implementation.js b/packages/netlify-cms-backend-github/src/implementation.js index f4f9123e..3244bb9b 100644 --- a/packages/netlify-cms-backend-github/src/implementation.js +++ b/packages/netlify-cms-backend-github/src/implementation.js @@ -221,14 +221,14 @@ export default class GitHub { } async entriesByFolder(collection, extension) { - const repoURL = `/repos/${this.useOpenAuthoring ? this.originRepo : this.repo}`; + const repoURL = this.useOpenAuthoring ? this.api.originRepoURL : this.api.repoURL; const files = await this.api.listFiles(collection.get('folder'), { repoURL }); const filteredFiles = files.filter(file => file.name.endsWith('.' + extension)); return this.fetchFiles(filteredFiles, { repoURL }); } entriesByFiles(collection) { - const repoURL = `/repos/${this.useOpenAuthoring ? this.originRepo : this.repo}`; + const repoURL = this.useOpenAuthoring ? this.api.originRepoURL : this.api.repoURL; const files = collection.get('files').map(collectionFile => ({ path: collectionFile.get('file'), label: collectionFile.get('label'), @@ -236,7 +236,7 @@ export default class GitHub { return this.fetchFiles(files, { repoURL }); } - fetchFiles = (files, { repoURL = `/repos/${this.repo}` } = {}) => { + fetchFiles = (files, { repoURL = this.api.repoURL } = {}) => { const sem = semaphore(MAX_CONCURRENT_DOWNLOADS); const promises = []; files.forEach(file => { @@ -265,7 +265,7 @@ export default class GitHub { // Fetches a single entry. getEntry(collection, slug, path) { - const repoURL = `/repos/${this.originRepo}`; + const repoURL = this.api.originRepoURL; return this.api.readFile(path, null, { repoURL }).then(data => ({ file: { path }, data,