Skip to content
Snippets Groups Projects
Unverified Commit ef64863f authored by Michael Kriese's avatar Michael Kriese Committed by GitHub
Browse files

fix(preset/gitlab): manual parse json (#16592)

parent 0ed7072a
No related branches found
No related tags found
No related merge requests found
...@@ -3,8 +3,9 @@ import { logger } from '../../../logger'; ...@@ -3,8 +3,9 @@ import { logger } from '../../../logger';
import { ExternalHostError } from '../../../types/errors/external-host-error'; import { ExternalHostError } from '../../../types/errors/external-host-error';
import type { GitLabBranch } from '../../../types/platform/gitlab'; import type { GitLabBranch } from '../../../types/platform/gitlab';
import { GitlabHttp } from '../../../util/http/gitlab'; import { GitlabHttp } from '../../../util/http/gitlab';
import type { HttpResponse } from '../../../util/http/types';
import type { Preset, PresetConfig } from '../types'; import type { Preset, PresetConfig } from '../types';
import { PRESET_DEP_NOT_FOUND, fetchPreset } from '../util'; import { PRESET_DEP_NOT_FOUND, fetchPreset, parsePreset } from '../util';
const gitlabApi = new GitlabHttp(); const gitlabApi = new GitlabHttp();
export const Endpoint = 'https://gitlab.com/api/v4/'; export const Endpoint = 'https://gitlab.com/api/v4/';
...@@ -36,6 +37,7 @@ export async function fetchJSONFile( ...@@ -36,6 +37,7 @@ export async function fetchJSONFile(
): Promise<Preset> { ): Promise<Preset> {
let url = endpoint; let url = endpoint;
let ref = ''; let ref = '';
let res: HttpResponse;
try { try {
const urlEncodedRepo = encodeURIComponent(repo); const urlEncodedRepo = encodeURIComponent(repo);
const urlEncodedPkgName = encodeURIComponent(fileName); const urlEncodedPkgName = encodeURIComponent(fileName);
...@@ -50,7 +52,7 @@ export async function fetchJSONFile( ...@@ -50,7 +52,7 @@ export async function fetchJSONFile(
} }
url += `projects/${urlEncodedRepo}/repository/files/${urlEncodedPkgName}/raw${ref}`; url += `projects/${urlEncodedRepo}/repository/files/${urlEncodedPkgName}/raw${ref}`;
logger.trace({ url }, `Preset URL`); logger.trace({ url }, `Preset URL`);
return (await gitlabApi.getJson<Preset>(url)).body; res = await gitlabApi.get(url);
} catch (err) { } catch (err) {
if (err instanceof ExternalHostError) { if (err instanceof ExternalHostError) {
throw err; throw err;
...@@ -61,6 +63,8 @@ export async function fetchJSONFile( ...@@ -61,6 +63,8 @@ export async function fetchJSONFile(
); );
throw new Error(PRESET_DEP_NOT_FOUND); throw new Error(PRESET_DEP_NOT_FOUND);
} }
return parsePreset(res.body);
} }
export function getPresetFromEndpoint( export function getPresetFromEndpoint(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment