Skip to content

Commit d8115cf

Browse files
committed
Add --base-url option to aio app init --repo
1 parent fff2504 commit d8115cf

3 files changed

Lines changed: 35 additions & 5 deletions

File tree

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ Create a new Adobe I/O App
514514
USAGE
515515
$ aio app init [PATH] [-v] [--version] [--install] [-y] [--login] [-e <value> | -t <value> | --repo <value>]
516516
[--standalone-app | | ] [-w <value> | -i <value>] [--confirm-new-workspace] [--use-jwt] [--github-pat <value> ]
517-
[--linter none|basic|adobe-recommended]
517+
[--base-url <value> ] [--linter none|basic|adobe-recommended]
518518
519519
ARGUMENTS
520520
PATH [default: .] Path to the app directory
@@ -527,6 +527,9 @@ FLAGS
527527
-w, --workspace=<value> [default: Stage] Specify the Adobe Developer Console Workspace to init from, defaults to
528528
Stage
529529
-y, --yes Skip questions, and use all default values
530+
--base-url=<value> When using with GitHub Enterprise Server, set to the root URL of the API. For example,
531+
if your GitHub Enterprise Server's hostname is `github.acme-inc.com`, then set
532+
`base-url` to `https://github.acme-inc.com/api/v3`
530533
--[no-]confirm-new-workspace Prompt to confirm before creating a new workspace
531534
--github-pat=<value> github personal access token to use for downloading private quickstart repos
532535
--[no-]install [default: true] Run npm installation after files are created

src/commands/app/init.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class InitCommand extends TemplatesCommand {
104104
}
105105

106106
if (flags.repo) {
107-
await this.withQuickstart(flags.repo, flags['github-pat'])
107+
await this.withQuickstart(flags.repo, flags['github-pat'], flags['base-url'])
108108
} else {
109109
// 2. prompt for templates to be installed
110110
const templates = await this.getTemplatesForFlags(flags)
@@ -134,7 +134,7 @@ class InitCommand extends TemplatesCommand {
134134

135135
async initWithLogin (flags) {
136136
if (flags.repo) {
137-
await this.withQuickstart(flags.repo, flags['github-pat'])
137+
await this.withQuickstart(flags.repo, flags['github-pat'], flags['base-url'])
138138
}
139139
// this will trigger a login
140140
const consoleCLI = await this.getLibConsoleCLI()
@@ -368,13 +368,14 @@ class InitCommand extends TemplatesCommand {
368368
)
369369
}
370370

371-
async withQuickstart (fullRepo, githubPat) {
371+
async withQuickstart (fullRepo, githubPat, baseUrl) {
372372
// telemetry hook for quickstart installs
373373
await this.config.runHook('telemetry', { data: `installQuickstart:${fullRepo}` })
374374

375375
const octokit = new Octokit({
376376
auth: githubPat ?? '',
377-
userAgent: 'ADP App Builder v1'
377+
userAgent: 'ADP App Builder v1',
378+
...(baseUrl && { baseUrl })
378379
})
379380
const spinner = ora('Downloading quickstart repo').start()
380381
/** @private */
@@ -489,6 +490,10 @@ InitCommand.flags = {
489490
description: 'github personal access token to use for downloading private quickstart repos',
490491
dependsOn: ['repo']
491492
}),
493+
'base-url': Flags.string({
494+
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`',
495+
dependsOn: ['repo']
496+
}),
492497
linter: Flags.string({
493498
description: 'Specify the linter to use for the project',
494499
options: ['none', 'basic', 'adobe-recommended'],

test/commands/app/init.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,28 @@ describe('--no-login', () => {
407407
expect(importHelperLib.importConfigJson).not.toHaveBeenCalled()
408408
})
409409

410+
test('--repo --github-pat', async () => {
411+
Octokit.mockImplementation(() => ({ repos: { getContent: () => Promise.resolve({ data: [] }) } }))
412+
413+
const pat = 'mytoken'
414+
command.argv = ['--repo=adobe/appbuilder-quickstarts/dne', '--github-pat', pat]
415+
416+
await command.run()
417+
418+
expect(Octokit).toHaveBeenCalledWith(expect.objectContaining({ auth: pat }))
419+
})
420+
421+
test('--repo --base-url', async () => {
422+
Octokit.mockImplementation(() => ({ repos: { getContent: () => Promise.resolve({ data: [] }) } }))
423+
424+
const baseUrl = 'https://github.acme-inc.com/api/v3'
425+
command.argv = ['--repo=org/repo', '--base-url', baseUrl]
426+
427+
await command.run()
428+
429+
expect(Octokit).toHaveBeenCalledWith(expect.objectContaining({ baseUrl }))
430+
})
431+
410432
test('--yes --no-install, select excshell', async () => {
411433
const installOptions = {
412434
useDefaultValues: true,

0 commit comments

Comments
 (0)