From d8115cf3c7c6e12b93efc96cfcd4447a33848e29 Mon Sep 17 00:00:00 2001 From: Oriol Barcelona Date: Fri, 29 Nov 2024 23:56:26 +0100 Subject: [PATCH 1/2] Add --base-url option to aio app init --repo --- README.md | 5 ++++- src/commands/app/init.js | 13 +++++++++---- test/commands/app/init.test.js | 22 ++++++++++++++++++++++ 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d17df80e..67c6854f 100644 --- a/README.md +++ b/README.md @@ -514,7 +514,7 @@ Create a new Adobe I/O App USAGE $ aio app init [PATH] [-v] [--version] [--install] [-y] [--login] [-e | -t | --repo ] [--standalone-app | | ] [-w | -i ] [--confirm-new-workspace] [--use-jwt] [--github-pat ] - [--linter none|basic|adobe-recommended] + [--base-url ] [--linter none|basic|adobe-recommended] ARGUMENTS PATH [default: .] Path to the app directory @@ -527,6 +527,9 @@ FLAGS -w, --workspace= [default: Stage] Specify the Adobe Developer Console Workspace to init from, defaults to Stage -y, --yes Skip questions, and use all default values + --base-url= When using with GitHub Enterprise Server, set to the root URL of the API. For example, + if your GitHub Enterprise Server's hostname is `github.acme-inc.com`, then set + `base-url` to `https://github.acme-inc.com/api/v3` --[no-]confirm-new-workspace Prompt to confirm before creating a new workspace --github-pat= github personal access token to use for downloading private quickstart repos --[no-]install [default: true] Run npm installation after files are created diff --git a/src/commands/app/init.js b/src/commands/app/init.js index 63f064b0..7e8a24e4 100644 --- a/src/commands/app/init.js +++ b/src/commands/app/init.js @@ -104,7 +104,7 @@ class InitCommand extends TemplatesCommand { } if (flags.repo) { - await this.withQuickstart(flags.repo, flags['github-pat']) + await this.withQuickstart(flags.repo, flags['github-pat'], flags['base-url']) } else { // 2. prompt for templates to be installed const templates = await this.getTemplatesForFlags(flags) @@ -134,7 +134,7 @@ class InitCommand extends TemplatesCommand { async initWithLogin (flags) { if (flags.repo) { - await this.withQuickstart(flags.repo, flags['github-pat']) + await this.withQuickstart(flags.repo, flags['github-pat'], flags['base-url']) } // this will trigger a login const consoleCLI = await this.getLibConsoleCLI() @@ -368,13 +368,14 @@ class InitCommand extends TemplatesCommand { ) } - async withQuickstart (fullRepo, githubPat) { + async withQuickstart (fullRepo, githubPat, baseUrl) { // telemetry hook for quickstart installs await this.config.runHook('telemetry', { data: `installQuickstart:${fullRepo}` }) const octokit = new Octokit({ auth: githubPat ?? '', - userAgent: 'ADP App Builder v1' + userAgent: 'ADP App Builder v1', + ...(baseUrl && { baseUrl }) }) const spinner = ora('Downloading quickstart repo').start() /** @private */ @@ -489,6 +490,10 @@ InitCommand.flags = { description: 'github personal access token to use for downloading private quickstart repos', dependsOn: ['repo'] }), + 'base-url': Flags.string({ + description: 'When using with GitHub Enterprise Server, set to the root URL of the API. For example, if your GitHub Enterprise Server\'s hostname is `github.acme-inc.com`, then set `base-url` to `https://github.acme-inc.com/api/v3`', + dependsOn: ['repo'] + }), linter: Flags.string({ description: 'Specify the linter to use for the project', options: ['none', 'basic', 'adobe-recommended'], diff --git a/test/commands/app/init.test.js b/test/commands/app/init.test.js index 03379594..2ab071ae 100644 --- a/test/commands/app/init.test.js +++ b/test/commands/app/init.test.js @@ -407,6 +407,28 @@ describe('--no-login', () => { expect(importHelperLib.importConfigJson).not.toHaveBeenCalled() }) + test('--repo --github-pat', async () => { + Octokit.mockImplementation(() => ({ repos: { getContent: () => Promise.resolve({ data: [] }) } })) + + const pat = 'mytoken' + command.argv = ['--repo=adobe/appbuilder-quickstarts/dne', '--github-pat', pat] + + await command.run() + + expect(Octokit).toHaveBeenCalledWith(expect.objectContaining({ auth: pat })) + }) + + test('--repo --base-url', async () => { + Octokit.mockImplementation(() => ({ repos: { getContent: () => Promise.resolve({ data: [] }) } })) + + const baseUrl = 'https://github.acme-inc.com/api/v3' + command.argv = ['--repo=org/repo', '--base-url', baseUrl] + + await command.run() + + expect(Octokit).toHaveBeenCalledWith(expect.objectContaining({ baseUrl })) + }) + test('--yes --no-install, select excshell', async () => { const installOptions = { useDefaultValues: true, From 4072a38ace602daaf6eb6c4d56feca50591eefe2 Mon Sep 17 00:00:00 2001 From: Oriol Barcelona Date: Mon, 2 Dec 2024 15:52:07 +0100 Subject: [PATCH 2/2] Rename to --repo-base-url --- README.md | 8 ++++---- src/commands/app/init.js | 6 +++--- test/commands/app/init.test.js | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 67c6854f..1806d853 100644 --- a/README.md +++ b/README.md @@ -514,7 +514,7 @@ Create a new Adobe I/O App USAGE $ aio app init [PATH] [-v] [--version] [--install] [-y] [--login] [-e | -t | --repo ] [--standalone-app | | ] [-w | -i ] [--confirm-new-workspace] [--use-jwt] [--github-pat ] - [--base-url ] [--linter none|basic|adobe-recommended] + [--repo-base-url ] [--linter none|basic|adobe-recommended] ARGUMENTS PATH [default: .] Path to the app directory @@ -527,9 +527,6 @@ FLAGS -w, --workspace= [default: Stage] Specify the Adobe Developer Console Workspace to init from, defaults to Stage -y, --yes Skip questions, and use all default values - --base-url= When using with GitHub Enterprise Server, set to the root URL of the API. For example, - if your GitHub Enterprise Server's hostname is `github.acme-inc.com`, then set - `base-url` to `https://github.acme-inc.com/api/v3` --[no-]confirm-new-workspace Prompt to confirm before creating a new workspace --github-pat= github personal access token to use for downloading private quickstart repos --[no-]install [default: true] Run npm installation after files are created @@ -537,6 +534,9 @@ FLAGS --[no-]login Login using your Adobe ID for interacting with Adobe I/O Developer Console --repo= Init from gh quick-start repo. Expected to be of the form // + --repo-base-url= When using with GitHub Enterprise Server, set to the root URL of the API. For example, + if your GitHub Enterprise Server's hostname is `github.acme-inc.com`, then set + `base-url` to `https://github.acme-inc.com/api/v3` --standalone-app Create a stand-alone application --use-jwt if the config has both jwt and OAuth Server to Server Credentials (while migrating), prefer the JWT credentials diff --git a/src/commands/app/init.js b/src/commands/app/init.js index 7e8a24e4..9e94857e 100644 --- a/src/commands/app/init.js +++ b/src/commands/app/init.js @@ -104,7 +104,7 @@ class InitCommand extends TemplatesCommand { } if (flags.repo) { - await this.withQuickstart(flags.repo, flags['github-pat'], flags['base-url']) + await this.withQuickstart(flags.repo, flags['github-pat'], flags['repo-base-url']) } else { // 2. prompt for templates to be installed const templates = await this.getTemplatesForFlags(flags) @@ -134,7 +134,7 @@ class InitCommand extends TemplatesCommand { async initWithLogin (flags) { if (flags.repo) { - await this.withQuickstart(flags.repo, flags['github-pat'], flags['base-url']) + await this.withQuickstart(flags.repo, flags['github-pat'], flags['repo-base-url']) } // this will trigger a login const consoleCLI = await this.getLibConsoleCLI() @@ -490,7 +490,7 @@ InitCommand.flags = { description: 'github personal access token to use for downloading private quickstart repos', dependsOn: ['repo'] }), - 'base-url': Flags.string({ + 'repo-base-url': Flags.string({ description: 'When using with GitHub Enterprise Server, set to the root URL of the API. For example, if your GitHub Enterprise Server\'s hostname is `github.acme-inc.com`, then set `base-url` to `https://github.acme-inc.com/api/v3`', dependsOn: ['repo'] }), diff --git a/test/commands/app/init.test.js b/test/commands/app/init.test.js index 2ab071ae..70538511 100644 --- a/test/commands/app/init.test.js +++ b/test/commands/app/init.test.js @@ -418,11 +418,11 @@ describe('--no-login', () => { expect(Octokit).toHaveBeenCalledWith(expect.objectContaining({ auth: pat })) }) - test('--repo --base-url', async () => { + test('--repo --repo-base-url', async () => { Octokit.mockImplementation(() => ({ repos: { getContent: () => Promise.resolve({ data: [] }) } })) const baseUrl = 'https://github.acme-inc.com/api/v3' - command.argv = ['--repo=org/repo', '--base-url', baseUrl] + command.argv = ['--repo=org/repo', '--repo-base-url', baseUrl] await command.run()