Add body content to catalog import PR

This commit is contained in:
Adam Harvey
2020-12-10 14:44:32 -05:00
parent 3e981aa51d
commit f63f1aff88
2 changed files with 22 additions and 4 deletions
@@ -15,7 +15,7 @@
*/
import { Octokit } from '@octokit/rest';
import { DiscoveryApi, OAuthApi } from '@backstage/core';
import { DiscoveryApi, OAuthApi, ConfigApi } from '@backstage/core';
import { CatalogImportApi } from './CatalogImportApi';
import { AnalyzeLocationResponse } from '@backstage/plugin-catalog-backend';
import { PartialEntity } from '../util/types';
@@ -24,13 +24,16 @@ import { GitHubIntegrationConfig } from '@backstage/integration';
export class CatalogImportClient implements CatalogImportApi {
private readonly discoveryApi: DiscoveryApi;
private readonly githubAuthApi: OAuthApi;
private readonly configApi: ConfigApi;
constructor(options: {
discoveryApi: DiscoveryApi;
githubAuthApi: OAuthApi;
configApi: ConfigApi;
}) {
this.discoveryApi = options.discoveryApi;
this.githubAuthApi = options.githubAuthApi;
this.configApi = options.configApi;
}
async generateEntityDefinitions({
@@ -164,12 +167,22 @@ export class CatalogImportClient implements CatalogImportApi {
);
});
const appTitle = this.configApi.getString('app.title');
const appBaseUrl = this.configApi.getString('app.baseUrl');
const prBody = `This pull request adds a **Backstage entity metadata file** \
to this repository so that the component can be added to the \
${appTitle} software catalog.\n\nAfter you merge this pull request, \
you can [return to Backstage](${appBaseUrl}/catalog-import) \
to register the component with the direct URL to the ${fileName} file.`;
const pullRequestResponse = await octo.pulls
.create({
owner,
repo,
title: `Add ${fileName} config file`,
head: branchName,
body: prBody,
base: repoData.data.default_branch,
})
.catch(e => {
+8 -3
View File
@@ -20,6 +20,7 @@ import {
createRouteRef,
discoveryApiRef,
githubAuthApiRef,
configApiRef,
} from '@backstage/core';
import { catalogImportApiRef } from './api/CatalogImportApi';
import { CatalogImportClient } from './api/CatalogImportClient';
@@ -34,9 +35,13 @@ export const plugin = createPlugin({
apis: [
createApiFactory({
api: catalogImportApiRef,
deps: { discoveryApi: discoveryApiRef, githubAuthApi: githubAuthApiRef },
factory: ({ discoveryApi, githubAuthApi }) =>
new CatalogImportClient({ discoveryApi, githubAuthApi }),
deps: {
discoveryApi: discoveryApiRef,
githubAuthApi: githubAuthApiRef,
configApi: configApiRef,
},
factory: ({ discoveryApi, githubAuthApi, configApi }) =>
new CatalogImportClient({ discoveryApi, githubAuthApi, configApi }),
}),
],
});