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);
|
return Promise.resolve(this.commitAuthor);
|
||||||
}
|
}
|
||||||
|
|
||||||
request(path, options = {}) {
|
request(path, options = {}, parseResponse = response => this.parseResponse(response)) {
|
||||||
const url = this.urlFor(path, options);
|
const url = this.urlFor(path, options);
|
||||||
let responseStatus;
|
let responseStatus;
|
||||||
return this.getRequestHeaders(options.headers || {})
|
return this.getRequestHeaders(options.headers || {})
|
||||||
.then(headers => fetch(url, { ...options, headers }))
|
.then(headers => fetch(url, { ...options, headers }))
|
||||||
.then(response => {
|
.then(response => {
|
||||||
responseStatus = response.status;
|
responseStatus = response.status;
|
||||||
const contentType = response.headers.get('Content-Type');
|
return parseResponse(response);
|
||||||
if (contentType && contentType.match(/json/)) {
|
|
||||||
return this.parseJsonResponse(response);
|
|
||||||
}
|
|
||||||
const text = response.text();
|
|
||||||
if (!response.ok) {
|
|
||||||
return Promise.reject(text);
|
|
||||||
}
|
|
||||||
return text;
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
throw new APIError(error.message || error.msg, responseStatus, 'Git Gateway');
|
throw new APIError(error.message || error.msg, responseStatus, 'Git Gateway');
|
||||||
|
@ -186,11 +186,11 @@ export default class GraphQLAPI extends API {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async listFiles(path) {
|
async listFiles(path, { repoURL = this.repoURL, branch = this.branch } = {}) {
|
||||||
const { repo_owner: owner, repo_name: name } = this;
|
const { owner, name } = this.getOwnerAndNameFromRepoUrl(repoURL);
|
||||||
const { data } = await this.query({
|
const { data } = await this.query({
|
||||||
query: queries.files,
|
query: queries.files,
|
||||||
variables: { owner, name, expression: `${this.branch}:${path}` },
|
variables: { owner, name, expression: `${branch}:${path}` },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (data.repository.object) {
|
if (data.repository.object) {
|
||||||
|
@ -221,14 +221,14 @@ export default class GitHub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async entriesByFolder(collection, extension) {
|
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 files = await this.api.listFiles(collection.get('folder'), { repoURL });
|
||||||
const filteredFiles = files.filter(file => file.name.endsWith('.' + extension));
|
const filteredFiles = files.filter(file => file.name.endsWith('.' + extension));
|
||||||
return this.fetchFiles(filteredFiles, { repoURL });
|
return this.fetchFiles(filteredFiles, { repoURL });
|
||||||
}
|
}
|
||||||
|
|
||||||
entriesByFiles(collection) {
|
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 => ({
|
const files = collection.get('files').map(collectionFile => ({
|
||||||
path: collectionFile.get('file'),
|
path: collectionFile.get('file'),
|
||||||
label: collectionFile.get('label'),
|
label: collectionFile.get('label'),
|
||||||
@ -236,7 +236,7 @@ export default class GitHub {
|
|||||||
return this.fetchFiles(files, { repoURL });
|
return this.fetchFiles(files, { repoURL });
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchFiles = (files, { repoURL = `/repos/${this.repo}` } = {}) => {
|
fetchFiles = (files, { repoURL = this.api.repoURL } = {}) => {
|
||||||
const sem = semaphore(MAX_CONCURRENT_DOWNLOADS);
|
const sem = semaphore(MAX_CONCURRENT_DOWNLOADS);
|
||||||
const promises = [];
|
const promises = [];
|
||||||
files.forEach(file => {
|
files.forEach(file => {
|
||||||
@ -265,7 +265,7 @@ export default class GitHub {
|
|||||||
|
|
||||||
// Fetches a single entry.
|
// Fetches a single entry.
|
||||||
getEntry(collection, slug, path) {
|
getEntry(collection, slug, path) {
|
||||||
const repoURL = `/repos/${this.originRepo}`;
|
const repoURL = this.api.originRepoURL;
|
||||||
return this.api.readFile(path, null, { repoURL }).then(data => ({
|
return this.api.readFile(path, null, { repoURL }).then(data => ({
|
||||||
file: { path },
|
file: { path },
|
||||||
data,
|
data,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user