fix(git-gateway): pass api URL instead of constructing it from repo value (#2631)
This commit is contained in:
parent
dac67a93a0
commit
922c0f38ee
@ -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');
|
||||
|
@ -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) {
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user