Make GitHub backend respect branch setting
This commit is contained in:
parent
4a55bb0296
commit
e04b1e80c5
@ -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 = {}) {
|
request(path, options = {}) {
|
||||||
const headers = this.requestHeaders(options.headers || {});
|
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/)) {
|
if (response.headers.get('Content-Type').match(/json/)) {
|
||||||
return this.parseJsonResponse(response);
|
return this.parseJsonResponse(response);
|
||||||
}
|
}
|
||||||
@ -111,7 +125,7 @@ export default class API {
|
|||||||
|
|
||||||
return this.request(`${this.repoURL}/contents/${path}`, {
|
return this.request(`${this.repoURL}/contents/${path}`, {
|
||||||
headers: { Accept: 'application/vnd.github.VERSION.raw' },
|
headers: { Accept: 'application/vnd.github.VERSION.raw' },
|
||||||
body: { ref: this.branch },
|
params: { ref: this.branch },
|
||||||
cache: false
|
cache: false
|
||||||
}).then((result) => {
|
}).then((result) => {
|
||||||
if (sha) {
|
if (sha) {
|
||||||
@ -125,7 +139,7 @@ export default class API {
|
|||||||
|
|
||||||
listFiles(path) {
|
listFiles(path) {
|
||||||
return this.request(`${this.repoURL}/contents/${path}`, {
|
return this.request(`${this.repoURL}/contents/${path}`, {
|
||||||
body: { ref: this.branch }
|
params: { ref: this.branch }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ export default class GitHub {
|
|||||||
throw 'The GitHub backend needs a "repo" in the backend configuration.';
|
throw 'The GitHub backend needs a "repo" in the backend configuration.';
|
||||||
}
|
}
|
||||||
this.repo = config.getIn(['backend', 'repo']);
|
this.repo = config.getIn(['backend', 'repo']);
|
||||||
|
this.branch = config.getIn(['backend', 'branch']) || 'master';
|
||||||
}
|
}
|
||||||
|
|
||||||
authComponent() {
|
authComponent() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user