-
-
Notifications
You must be signed in to change notification settings - Fork 342
feat: enable private GitHub/GitLab repository templates (#1157) #1765
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
Draft
Kartikayy007
wants to merge
3
commits into
asyncapi:master
Choose a base branch
from
Kartikayy007:feat/1157-private-git-templates
base: master
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.
Draft
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 |
|---|---|---|
|
|
@@ -39,3 +39,42 @@ const generator = new Generator('@asyncapi/html-template', 'output', | |
| }); | ||
| ``` | ||
| Assuming you host `@asyncapi/html-template` in a private package registry like Verdaccio. To pull this template, you need to provide `registry.url` option that points to the registry URL and `registry.auth` as a base64 encoded value that represents the username and password. Instead of username and password, you can also pass `registry.token`. | ||
|
|
||
| ## Using templates from private Git repositories | ||
|
|
||
| Generator can also use templates hosted in Git repositories, including private repositories on providers such as GitHub and GitLab. | ||
| In this case the template is referenced using a git-compatible specifier, and authentication is handled by your existing Git configuration (SSH keys, HTTPS with personal access tokens, etc.). | ||
|
|
||
| ### CLI example | ||
|
|
||
| ```bash | ||
| asyncapi generate fromTemplate asyncapi.yaml \ | ||
| git+ssh://[email protected]/your-org/your-private-template.git \ | ||
| -o output | ||
| ``` | ||
|
|
||
| You can use any git specifier supported by npm, for example: | ||
|
|
||
| - `git+https://github.com/your-org/your-private-template.git#v1.0.0` | ||
| - `git+ssh://[email protected]/your-org/your-private-template.git#main` | ||
| - `[email protected]:your-org/your-private-template.git` | ||
| - `github:your-org/your-private-template` | ||
|
|
||
| Make sure your Git credentials are configured so the underlying git client can access the repository. For example: | ||
|
|
||
| - Configure SSH keys that have access to the private repository. | ||
| - Use HTTPS URLs with a personal access token (PAT), following your Git provider’s documentation. | ||
|
|
||
| ### Library example | ||
|
|
||
| ```javascript | ||
| const generator = new Generator( | ||
| 'git+https://github.com/your-org/your-private-template.git#v1.0.0', | ||
| 'output', | ||
| { | ||
| debug: true | ||
| } | ||
| ); | ||
| ``` | ||
|
|
||
| In both CLI and library usage, AsyncAPI Generator delegates cloning and authentication to npm and git; no additional generator-specific configuration is required beyond providing a valid git specifier and having your Git credentials set up correctly. | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,11 @@ | ||
| module.exports = { | ||
| /** | ||
| * Minimal mock for requireg.resolve used in tests. | ||
| * It just needs to return a string containing 'index.js' | ||
| * so that generator.js can safely call .replace('index.js',''). | ||
| */ | ||
| resolve() { | ||
| return 'npm/index.js'; | ||
| } | ||
| }; | ||
|
|
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -62,6 +62,44 @@ describe('Utils', () => { | |
| }); | ||
| }); | ||
|
|
||
| describe('#isGitSpecifier', () => { | ||
| it('returns true for git+https url', () => { | ||
| expect(utils.isGitSpecifier('git+https://github.com/org/repo.git')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('returns true for git+ssh url', () => { | ||
| expect(utils.isGitSpecifier('git+ssh://[email protected]/org/repo.git')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('returns true for ssh url', () => { | ||
| expect(utils.isGitSpecifier('ssh://[email protected]/org/repo.git')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('returns true for ssh-style git@host:path', () => { | ||
| expect(utils.isGitSpecifier('[email protected]:org/repo.git')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('returns true for github shorthand', () => { | ||
| expect(utils.isGitSpecifier('github:org/repo')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('returns true for gitlab shorthand', () => { | ||
| expect(utils.isGitSpecifier('gitlab:org/repo')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('returns false for plain https url', () => { | ||
| expect(utils.isGitSpecifier('https://example.com/template.tgz')).toBeFalsy(); | ||
| }); | ||
|
|
||
| it('returns false for npm package name', () => { | ||
| expect(utils.isGitSpecifier('@asyncapi/html-template')).toBeFalsy(); | ||
| }); | ||
|
|
||
| it('returns false for file system path', () => { | ||
| expect(utils.isGitSpecifier('./my-template')).toBeFalsy(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('#exists', () => { | ||
| it('should return true if file exist', async () => { | ||
| const exists = await utils.exists(`${process.cwd()}/package.json`); | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.