Skip to content

Commit

Permalink
fix: [PL-56199]: changing pr yaml for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
namanharness committed Aug 18, 2024
1 parent 0a33fab commit 4ec8fc3
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions packages/cli/src/loadSpecFromFileOrUrl.mts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import yaml from 'js-yaml';
import { generateOpenAPISpec } from './generateOpenAPISpec.mjs';
import {
GITHUB_API_ENDPOINT_URL,
GITHUB_PAT,
_convertToOpenAPI,
b64DecodeUnicode,
logInfo,
Expand Down Expand Up @@ -46,13 +47,16 @@ export async function loadSpecFromFileOrUrl(config: IServiceConfig): Promise<IPl
// read from URL
logInfo('Fetching data from URL');
const abcd = 'platform-service/modules/notification-service/contracts/openapi/v1/openapi.yaml';

const configUrl = process.env.CI ? config.url : GITHUB_API_ENDPOINT_URL(abcd);
const response = await fetch(configUrl);
// const response = await fetch(configUrl, {
// headers: {
// Authorization: `Bearer ${GITHUB_PAT}`,
// },
// });
const configHeaders = process.env.CI
? {}
: { headers: { Authorization: `Bearer ${GITHUB_PAT}` } };

const response = await fetch(configUrl, {
...configHeaders,
});

const contentType = response.headers.get('Content-Type');
try {
logInfo('Parsing data from API');
Expand All @@ -66,20 +70,12 @@ export async function loadSpecFromFileOrUrl(config: IServiceConfig): Promise<IPl

logInfo(`Detected format: JSON`);
} else {
if (
configUrl ===
'https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/api.github.com/api.github.com.yaml'
) {
console.log('response', response);
}
const txt = await response.text();
spec = yaml.load(txt) as OpenAPIV3.Document;
console.log('contentType', contentType, configUrl);
// console.log('txt', spec);

logInfo(`Detected format: YAML`);
}
} catch (e) {
console.log('error', e);
} catch (_) {
throw new Error('Something went wrong while trying to parse contents from URL');
}
} else {
Expand Down

0 comments on commit 4ec8fc3

Please sign in to comment.