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:
Johan Haals
2022-04-20 14:00:45 +02:00
parent 84e9e7c7af
commit 8ab2a8226b
3 changed files with 19 additions and 0 deletions
+5
View File
@@ -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.
+1
View File
@@ -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.`,
);
}
}