Skip to content

Commit

Permalink
fix: [PL-56199]: support Open API yaml URL with Github API
Browse files Browse the repository at this point in the history
  • Loading branch information
namanharness committed Aug 18, 2024
1 parent 4ec8fc3 commit 00fb26d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
1 change: 0 additions & 1 deletion .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ jobs:
run: pnpm install
- name: Lint
run: |
pwd
pnpm run -r build
pnpm run -r lint
typecheck:
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/helpers.mts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import { has } from 'lodash-es';

const DIR_NAME = getDirNameForCurrentFile(import.meta);

export const GITHUB_PAT = process.env.GITHUB_PAT;
// helpers when when working with url to generate service
const DEFAULT_BRANCH = 'develop';
const URL_PREFIX = 'https://api.github.com/repos/harness/harness-core/contents/';
// const yamlPath = '120-ng-manager/contracts/openapi/v1/openapi.yaml';

export const GITHUB_PAT = process.env.GITHUB_PAT;
export const GITHUB_API_ENDPOINT_URL = (yamlPath: string) =>
`${URL_PREFIX}${yamlPath}?ref=${DEFAULT_BRANCH}`;

Expand Down
7 changes: 5 additions & 2 deletions packages/cli/src/loadSpecFromFileOrUrl.mts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ export async function loadSpecFromFileOrUrl(config: IServiceConfig): Promise<IPl
} else if (config.url) {
// 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);
if (!GITHUB_PAT) {
throw new Error('GITHUB PAT is not defined, please set GITHUB_PAT environment variable');
}

const configUrl = process.env.CI ? config.url : GITHUB_API_ENDPOINT_URL(config.url);
const configHeaders = process.env.CI
? {}
: { headers: { Authorization: `Bearer ${GITHUB_PAT}` } };
Expand Down

0 comments on commit 00fb26d

Please sign in to comment.