-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: [PL-56199]: support Open API yaml URL with Github API #34
Open
namanharness
wants to merge
12
commits into
main
Choose a base branch
from
PL-56199
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
54591c5
fix: [PL-56199]: support Open API yaml URL with Github API
namanharness 54b3223
fix: [PL-56199]: support Open API yaml URL with Github API
namanharness 45d2c96
fix: [PL-56199]: support Open API yaml URL with Github API
namanharness 241d146
fix: [PL-56199]: support Open API yaml URL with Github API
namanharness 34d17a4
fix: [PL-56199]: update client to utilise GITHUB PAT to generate serv…
namanharness 5f84abc
fix: [PL-56199]: update client to utilise GITHUB PAT to generate serv…
namanharness 4cac9b0
fix: [PL-56199]: update client to utilise GITHUB PAT to generate serv…
namanharness 6a6d349
fix: [PL-56199]: update client to utilise GITHUB PAT to generate serv…
namanharness ab591ba
fix: [PL-56199]: update client to utilise GITHUB PAT to generate serv…
namanharness 33aba38
fix: [PL-56199]: update client to utilise GITHUB PAT to generate serv…
namanharness 616e944
fix: [PL-56199]: update client to utilise GITHUB PAT to generate serv…
namanharness 1ed0288
fix: [PL-56199]: update client to utilise GITHUB PAT to generate serv…
namanharness File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ on: | |
- opened | ||
- reopened | ||
- synchronize | ||
env: | ||
CI: true | ||
jobs: | ||
eslint: | ||
name: ESLint | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
GITHUB_PAT=GITHUB_PAT | ||
ORGANIZATION=ORGANIZATION | ||
REPO=REPO | ||
DEFAULT_BRANCH=DEFAULT_BRANCH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,17 @@ import { has } from 'lodash-es'; | |
|
||
const DIR_NAME = getDirNameForCurrentFile(import.meta); | ||
|
||
// helpers when when working with url to generate service | ||
export const GITHUB_PAT = process.env.GITHUB_PAT; | ||
const ORGANIZATION = process.env.ORGANIZATION || 'harness'; | ||
const REPO = process.env.REPO || 'harness-core'; | ||
const DEFAULT_BRANCH = process.env.DEFAULT_BRANCH || 'develop'; | ||
namanharness marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const URL_PREFIX = `https://api.github.com/repos/${ORGANIZATION}/${REPO}/contents/`; | ||
|
||
export const generateGithubApiEndpointUrl = (yamlPath: string) => | ||
`${URL_PREFIX}${yamlPath}?ref=${DEFAULT_BRANCH}`; | ||
namanharness marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// internal function | ||
export function _convertToOpenAPI(schema: unknown): Promise<OpenAPIV3.Document> { | ||
return new Promise((resolve, reject) => { | ||
|
@@ -53,3 +64,15 @@ export function getDirNameForCurrentFile(meta: ImportMeta): string { | |
export function pathToTemplate(val: string): string { | ||
return val.replace(/\{/g, '${'); | ||
} | ||
|
||
export function b64DecodeUnicode(str: any) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a way to avoid the need for this decoder? few concerns:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Github API returns bas64 encoded content, hence need to decode the content. |
||
// Going backwards: from bytestream, to percent-encoding, to original string. | ||
return decodeURIComponent( | ||
atob(str) | ||
.split('') | ||
.map(function (c) { | ||
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); | ||
}) | ||
.join(''), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we avoid hardcoded design dependency on Github?
considering that we have most of our repos moving to Harness Code now, we should support querying harness0.harness.io with the Harness PAT as well.
a simpler, more generic design would be to just take a complete url as a param, instead of taking org + repo + branch and constructing github urls via "magic".