cli/create-github-app: prompt for read or write permissions during setup
Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/cli': patch
|
||||
---
|
||||
|
||||
Updated `create-github-app` command to prompt for read or write permissions to simplify setup.
|
||||
@@ -60,14 +60,20 @@ export class GithubCreateAppServer {
|
||||
private baseUrl?: string;
|
||||
private webhookUrl?: string;
|
||||
|
||||
static async run({ org }: { org: string }): Promise<GithubAppConfig> {
|
||||
const encodedOrg = encodeURIComponent(org);
|
||||
static async run(options: {
|
||||
org: string;
|
||||
readWrite: boolean;
|
||||
}): Promise<GithubAppConfig> {
|
||||
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, '"');
|
||||
|
||||
|
||||
@@ -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)}`;
|
||||
|
||||
Reference in New Issue
Block a user