From 3d121668268fd1f1494d3d4471e055e50cdd8190 Mon Sep 17 00:00:00 2001 From: Philipp Hugenroth Date: Mon, 6 Mar 2023 13:14:37 +0100 Subject: [PATCH] Chain Scaffolder inquirer prompts Signed-off-by: Philipp Hugenroth --- .../src/commands/onboard/auth/gitlab/index.ts | 2 +- .../onboard/integrations/github/index.ts | 54 +++++++++---------- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/packages/cli/src/commands/onboard/auth/gitlab/index.ts b/packages/cli/src/commands/onboard/auth/gitlab/index.ts index 9e2a674a9a..702537fe70 100644 --- a/packages/cli/src/commands/onboard/auth/gitlab/index.ts +++ b/packages/cli/src/commands/onboard/auth/gitlab/index.ts @@ -52,7 +52,7 @@ type Answers = { export const gitlab = async () => { Task.log(` - To add GitLub authentication, you must create an Application from the GitLab Settings: ${chalk.blue( + To add GitLab authentication, you must create an Application from the GitLab Settings: ${chalk.blue( 'https://gitlab.com/-/profile/applications', )} The Redirect URI should point to your Backstage backend auth handler. diff --git a/packages/cli/src/commands/onboard/integrations/github/index.ts b/packages/cli/src/commands/onboard/integrations/github/index.ts index 1a0d7a5ef5..ac4fd37406 100644 --- a/packages/cli/src/commands/onboard/integrations/github/index.ts +++ b/packages/cli/src/commands/onboard/integrations/github/index.ts @@ -48,46 +48,42 @@ const getConfig = ({ isEnterprise, host, apiBaseUrl, token }: Answers) => ({ export const github = async () => { let host = 'github.com'; - let apiBaseUrl: string | undefined; // TODO(tudi2d): Is GitHub Enterprise a valid setup if there is no Authentication? - const { isEnterprise } = await inquirer.prompt<{ + const { + isEnterprise, + host: _host, + apiBaseUrl, + } = await inquirer.prompt<{ isEnterprise: Answers['isEnterprise']; + apiBaseUrl: Answers['apiBaseUrl']; + host: Answers['host']; }>([ { type: 'confirm', name: 'isEnterprise', message: 'Are you using GitHub Enterprise?', }, + { + type: 'input', + name: 'apiBaseUrl', + when: ({ isEnterprise: _isEnterprise }) => _isEnterprise, + message: + 'What is your GitHub Enterprise REST API URL (e.g. https://ghe.example.net/api/v3)?', + // TODO(tudi2d): Fetch API using OAuth Token if Auth was set up + validate: (input: string) => Boolean(new URL(input)), + }, + { + type: 'input', + name: 'host', + when: ({ isEnterprise: _isEnterprise }) => _isEnterprise, + message: 'What is your GitHub Enterprise Host (e.g. ghe.example.net)?', + // TODO(tudi2d): validate: Must the host be part of the REST API URL? + }, ]); if (isEnterprise) { - try { - const answers = await inquirer.prompt< - Pick - >([ - { - type: 'input', - name: 'apiBaseUrl', - message: - 'What is your GitHub Enterprise REST API URL (e.g. https://ghe.example.net/api/v3)?', - // TODO(tudi2d): Fetch API using OAuth Token if Auth was set up - validate: (input: string) => Boolean(new URL(input)), - }, - { - type: 'input', - name: 'host', - message: - 'What is your GitHub Enterprise Host (e.g. ghe.example.net)?', - // TODO(tudi2d): validate: Must the host be part of the REST API URL? - }, - ]); - - host = answers.host; - apiBaseUrl = answers.apiBaseUrl; - } catch (err) { - return; - } + host = _host; } Task.log(` @@ -123,7 +119,7 @@ export const github = async () => { name: 'token', message: 'Please insert your personal access token to setup the GitHub Integration', - // TODO(tudi2d): validate: Must the host be part of the REST API URL? + // TODO(tudi2d): validate }, ]);