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,