diff --git a/src/backends/github/API.js b/src/backends/github/API.js index 13025037..fa165b9a 100644 --- a/src/backends/github/API.js +++ b/src/backends/github/API.js @@ -35,9 +35,23 @@ export default class API { }); } + urlFor(path, options) { + const params = []; + if (options.params) { + for (const key in options.params) { + params.push(`${key}=${encodeURIComponent(options.params[key])}`); + } + } + if (params.length) { + path += `?${params.join('&')}`; + } + return API_ROOT + path; + } + request(path, options = {}) { const headers = this.requestHeaders(options.headers || {}); - return fetch(API_ROOT + path, { ...options, headers: headers }).then((response) => { + const url = this.urlFor(path, options); + return fetch(url, { ...options, headers: headers }).then((response) => { if (response.headers.get('Content-Type').match(/json/)) { return this.parseJsonResponse(response); } @@ -111,7 +125,7 @@ export default class API { return this.request(`${this.repoURL}/contents/${path}`, { headers: { Accept: 'application/vnd.github.VERSION.raw' }, - body: { ref: this.branch }, + params: { ref: this.branch }, cache: false }).then((result) => { if (sha) { @@ -125,7 +139,7 @@ export default class API { listFiles(path) { return this.request(`${this.repoURL}/contents/${path}`, { - body: { ref: this.branch } + params: { ref: this.branch } }); } diff --git a/src/backends/github/implementation.js b/src/backends/github/implementation.js index acabf3fd..f1583492 100644 --- a/src/backends/github/implementation.js +++ b/src/backends/github/implementation.js @@ -1,4 +1,4 @@ -import { createEntry } from '../../valueObjects/Entry'; +import {createEntry} from '../../valueObjects/Entry'; import AuthenticationPage from './AuthenticationPage'; import API from './API'; @@ -9,6 +9,7 @@ export default class GitHub { throw 'The GitHub backend needs a "repo" in the backend configuration.'; } this.repo = config.getIn(['backend', 'repo']); + this.branch = config.getIn(['backend', 'branch']) || 'master'; } authComponent() {