diff --git a/.changeset/three-tips-hunt.md b/.changeset/three-tips-hunt.md new file mode 100644 index 0000000000..3782fc315b --- /dev/null +++ b/.changeset/three-tips-hunt.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +Updated `create-github-app` command to prompt for read or write permissions to simplify setup. diff --git a/packages/cli/src/commands/create-github-app/GithubCreateAppServer.ts b/packages/cli/src/commands/create-github-app/GithubCreateAppServer.ts index 58a3e97a9a..0fe321541e 100644 --- a/packages/cli/src/commands/create-github-app/GithubCreateAppServer.ts +++ b/packages/cli/src/commands/create-github-app/GithubCreateAppServer.ts @@ -60,14 +60,20 @@ export class GithubCreateAppServer { private baseUrl?: string; private webhookUrl?: string; - static async run({ org }: { org: string }): Promise { - const encodedOrg = encodeURIComponent(org); + static async run(options: { + org: string; + readWrite: boolean; + }): Promise { + const encodedOrg = encodeURIComponent(options.org); const actionUrl = `https://github.com/organizations/${encodedOrg}/settings/apps/new`; - const server = new GithubCreateAppServer(actionUrl); + const server = new GithubCreateAppServer(actionUrl, options.readWrite); return server.start(); } - constructor(private readonly actionUrl: string) { + private constructor( + private readonly actionUrl: string, + private readonly readWrite: boolean, + ) { const webhookId = crypto .randomBytes(15) .toString('base64') @@ -122,6 +128,13 @@ export class GithubCreateAppServer { url: this.webhookUrl, active: false, }, + ...(this.readWrite && { + default_permissions: { + contents: 'write', + actions: 'write', + metadata: 'read', + }, + }), }; const manifestJson = JSON.stringify(manifest).replace(/\"/g, '"'); diff --git a/packages/cli/src/commands/create-github-app/index.ts b/packages/cli/src/commands/create-github-app/index.ts index 2e5dd01072..e84e010c60 100644 --- a/packages/cli/src/commands/create-github-app/index.ts +++ b/packages/cli/src/commands/create-github-app/index.ts @@ -16,6 +16,7 @@ import fs from 'fs-extra'; import chalk from 'chalk'; +import inquirer, { Answers } from 'inquirer'; import { stringify as stringifyYaml } from 'yaml'; import inquirer, { Question } from 'inquirer'; import { paths } from '../../lib/paths'; @@ -26,8 +27,23 @@ import openBrowser from 'react-dev-utils/openBrowser'; // due to lacking support for creating apps from manifests. // https://docs.github.com/en/free-pro-team@latest/developers/apps/creating-a-github-app-from-a-manifest export default async (org: string) => { + const answers: Answers = await inquirer.prompt([ + { + type: 'list', + name: 'appType', + message: chalk.blue('What will the app be used for [required]'), + choices: [ + 'Read and Write(needed by the scaffolding to create new projects)', + 'Read only', + ], + }, + ]); + const readWrite = answers.appType !== 'Read only'; await verifyGithubOrg(org); - const { slug, name, ...config } = await GithubCreateAppServer.run({ org }); + const { slug, name, ...config } = await GithubCreateAppServer.run({ + org, + readWrite, + }); const fileName = `github-app-${slug}-credentials.yaml`; const content = `# Name: ${name}\n${stringifyYaml(config)}`;