Skip to content
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

Add --base-url option to aio app init --repo #822

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ Create a new Adobe I/O App
USAGE
$ aio app init [PATH] [-v] [--version] [--install] [-y] [--login] [-e <value> | -t <value> | --repo <value>]
[--standalone-app | | ] [-w <value> | -i <value>] [--confirm-new-workspace] [--use-jwt] [--github-pat <value> ]
[--linter none|basic|adobe-recommended]
[--repo-base-url <value> ] [--linter none|basic|adobe-recommended]

ARGUMENTS
PATH [default: .] Path to the app directory
Expand All @@ -534,6 +534,9 @@ FLAGS
<options: none|basic|adobe-recommended>
--[no-]login Login using your Adobe ID for interacting with Adobe I/O Developer Console
--repo=<value> Init from gh quick-start repo. Expected to be of the form <owner>/<repo>/<path>
--repo-base-url=<value> 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
Expand Down
13 changes: 9 additions & 4 deletions src/commands/app/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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['repo-base-url'])
} else {
// 2. prompt for templates to be installed
const templates = await this.getTemplatesForFlags(flags)
Expand Down Expand Up @@ -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['repo-base-url'])
}
// this will trigger a login
const consoleCLI = await this.getLibConsoleCLI()
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -489,6 +490,10 @@ InitCommand.flags = {
description: 'github personal access token to use for downloading private quickstart repos',
dependsOn: ['repo']
}),
'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'],
Expand Down
22 changes: 22 additions & 0 deletions test/commands/app/init.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 --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', '--repo-base-url', baseUrl]

await command.run()

expect(Octokit).toHaveBeenCalledWith(expect.objectContaining({ baseUrl }))
})

test('--yes --no-install, select excshell', async () => {
const installOptions = {
useDefaultValues: true,
Expand Down