cli: Throw error if non org is provided to create-github-app
Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/cli': patch
|
||||
---
|
||||
|
||||
Updated the `create-github-app` command to throw an error if the organization argument is a user or a non existing organization.
|
||||
@@ -93,6 +93,7 @@
|
||||
"lodash": "^4.17.21",
|
||||
"mini-css-extract-plugin": "^2.4.2",
|
||||
"minimatch": "5.0.1",
|
||||
"node-fetch": "^2.6.7",
|
||||
"node-libs-browser": "^2.2.1",
|
||||
"npm-packlist": "^5.0.0",
|
||||
"ora": "^5.3.0",
|
||||
|
||||
@@ -19,11 +19,13 @@ import chalk from 'chalk';
|
||||
import { stringify as stringifyYaml } from 'yaml';
|
||||
import { paths } from '../../lib/paths';
|
||||
import { GithubCreateAppServer } from './GithubCreateAppServer';
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
// This is an experimental command that at this point does not support GitHub Enterprise
|
||||
// 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) => {
|
||||
await verifyGithubOrg(org);
|
||||
const { slug, name, ...config } = await GithubCreateAppServer.run({ org });
|
||||
|
||||
const fileName = `github-app-${slug}-credentials.yaml`;
|
||||
@@ -47,3 +49,14 @@ integrations:
|
||||
- $include: ${fileName}`),
|
||||
);
|
||||
};
|
||||
|
||||
async function verifyGithubOrg(org: string): Promise<void> {
|
||||
const response = await fetch(
|
||||
`https://api.github.com/orgs/${encodeURIComponent(org)}`,
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`GitHub organization '${org}' does not exist. Please verify the name and try again.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user