Merge pull request #10944 from backstage/jhaals/create-app-warn

cli: Throw error if non org is provided to create-github-app
This commit is contained in:
Johan Haals
2022-04-21 11:40:49 +02:00
committed by GitHub
3 changed files with 31 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,26 @@ integrations:
- $include: ${fileName}`),
);
};
async function verifyGithubOrg(org: string): Promise<void> {
let response;
try {
response = await fetch(
`https://api.github.com/orgs/${encodeURIComponent(org)}`,
);
} catch (e) {
console.log(
chalk.yellow(
'Warning: Unable to verify existence of GitHub organization. ',
e,
),
);
}
if (response?.status === 404) {
throw new Error(
`GitHub organization '${org}' does not exist. Please verify the name and try again.`,
);
}
}