From f63f1aff888ef5b29076b0dac357448dc51b9bd1 Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Thu, 10 Dec 2020 14:44:32 -0500 Subject: [PATCH 1/5] Add body content to catalog import PR --- .../catalog-import/src/api/CatalogImportClient.ts | 15 ++++++++++++++- plugins/catalog-import/src/plugin.ts | 11 ++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/plugins/catalog-import/src/api/CatalogImportClient.ts b/plugins/catalog-import/src/api/CatalogImportClient.ts index 4ac015ffbf..029f7f7fb5 100644 --- a/plugins/catalog-import/src/api/CatalogImportClient.ts +++ b/plugins/catalog-import/src/api/CatalogImportClient.ts @@ -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 => { diff --git a/plugins/catalog-import/src/plugin.ts b/plugins/catalog-import/src/plugin.ts index 3ce4918553..829be22045 100644 --- a/plugins/catalog-import/src/plugin.ts +++ b/plugins/catalog-import/src/plugin.ts @@ -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 }), }), ], }); From f3e75508d66f6dd55b218d683776ee0ed8d55d16 Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Thu, 10 Dec 2020 14:45:55 -0500 Subject: [PATCH 2/5] Add changeset --- .changeset/loud-icons-itch.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/loud-icons-itch.md diff --git a/.changeset/loud-icons-itch.md b/.changeset/loud-icons-itch.md new file mode 100644 index 0000000000..c5741c5d0b --- /dev/null +++ b/.changeset/loud-icons-itch.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-import': patch +--- + +Add description to Pull Request when registering a new component From 803e6df7d122cf63c9320019818935160539ba2f Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Thu, 10 Dec 2020 14:50:29 -0500 Subject: [PATCH 3/5] Wrap filename in code fence --- plugins/catalog-import/src/api/CatalogImportClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/catalog-import/src/api/CatalogImportClient.ts b/plugins/catalog-import/src/api/CatalogImportClient.ts index 029f7f7fb5..185221ba93 100644 --- a/plugins/catalog-import/src/api/CatalogImportClient.ts +++ b/plugins/catalog-import/src/api/CatalogImportClient.ts @@ -174,7 +174,7 @@ export class CatalogImportClient implements CatalogImportApi { 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.`; +to register the component with the direct URL to the \`${fileName}\` file.`; const pullRequestResponse = await octo.pulls .create({ From 483c98bbf0840d9993c06734cd9e93f7e384310f Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Thu, 10 Dec 2020 14:55:24 -0500 Subject: [PATCH 4/5] Allow for optional string --- plugins/catalog-import/src/api/CatalogImportClient.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/catalog-import/src/api/CatalogImportClient.ts b/plugins/catalog-import/src/api/CatalogImportClient.ts index 185221ba93..d9cf4f1327 100644 --- a/plugins/catalog-import/src/api/CatalogImportClient.ts +++ b/plugins/catalog-import/src/api/CatalogImportClient.ts @@ -167,7 +167,8 @@ export class CatalogImportClient implements CatalogImportApi { ); }); - const appTitle = this.configApi.getString('app.title'); + const appTitle = + this.configApi.getOptionalString('app.title') ?? 'Backstage'; const appBaseUrl = this.configApi.getString('app.baseUrl'); const prBody = `This pull request adds a **Backstage entity metadata file** \ From dbd1d73653821bd0bdac872cc977567b35831788 Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Thu, 10 Dec 2020 15:10:28 -0500 Subject: [PATCH 5/5] Update PR wording --- plugins/catalog-import/src/api/CatalogImportClient.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/catalog-import/src/api/CatalogImportClient.ts b/plugins/catalog-import/src/api/CatalogImportClient.ts index d9cf4f1327..0e3ea2e1d6 100644 --- a/plugins/catalog-import/src/api/CatalogImportClient.ts +++ b/plugins/catalog-import/src/api/CatalogImportClient.ts @@ -173,9 +173,9 @@ export class CatalogImportClient implements CatalogImportApi { 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.`; +[${appTitle} software catalog](${appBaseUrl}).\n\nAfter this pull request is merged, \ +the component will become available.\n\nFor more information, read an \ +[overview of the Backstage software catalog](https://backstage.io/docs/features/software-catalog/software-catalog-overview).`; const pullRequestResponse = await octo.pulls .create({