feat(catalog-import): use title for commit message

Signed-off-by: Andrew Thauer <athauer@wealthsimple.com>
This commit is contained in:
Andrew Thauer
2021-03-13 17:27:32 -05:00
parent 4344ef8be8
commit a0dacc1842
4 changed files with 41 additions and 12 deletions
+20
View File
@@ -0,0 +1,20 @@
---
'@backstage/plugin-catalog-import': patch
---
Use title form field value for the commit message on catalog import PRs. Also allow customization of the pull requests title or body only. For example:
```tsx
<Route
path="/catalog-import"
element={
<CatalogImportPage
pullRequest={{
preparePullRequest: () => ({
title: 'chore: add backstage catalog file [skip ci]',
}),
}}
/>
}
/>
```
@@ -301,7 +301,7 @@ describe('CatalogImportClient', () => {
catalogImportClient.submitPullRequest({
repositoryUrl: 'https://github.com/backstage/backstage',
fileContent: 'some content',
title: 'A title',
title: 'A title/message',
body: 'A body',
}),
).resolves.toEqual({
@@ -325,7 +325,7 @@ describe('CatalogImportClient', () => {
owner: 'backstage',
repo: 'backstage',
path: 'catalog-info.yaml',
message: 'Add catalog-info.yaml config file',
message: 'A title/message',
content: 'c29tZSBjb250ZW50',
branch: 'backstage-integration',
});
@@ -334,7 +334,7 @@ describe('CatalogImportClient', () => {
).toEqual({
owner: 'backstage',
repo: 'backstage',
title: 'A title',
title: 'A title/message',
head: 'backstage-integration',
body: 'A body',
base: 'main',
@@ -297,7 +297,7 @@ export class CatalogImportClient implements CatalogImportApi {
owner,
repo,
path: fileName,
message: `Add ${fileName} config file`,
message: title,
content: btoa(fileContent),
branch: branchName,
})
@@ -39,7 +39,9 @@ import { ImportFlows, ImportState } from '../useImportState';
export type StepperProviderOpts = {
pullRequest?: {
disable?: boolean;
preparePullRequest?: (apis: StepperApis) => { title: string; body: string };
preparePullRequest?: (
apis: StepperApis,
) => { title?: string; body?: string };
};
};
@@ -71,13 +73,18 @@ export type StepperProvider = {
) => StepConfiguration;
};
function defaultPreparePullRequest(apis: StepperApis) {
function defaultPreparePullRequest(
apis: StepperApis,
{ title, body }: { title?: string; body?: string } = {},
) {
const appTitle = apis.configApi.getOptionalString('app.title') ?? 'Backstage';
const appBaseUrl = apis.configApi.getString('app.baseUrl');
return {
title: 'Add catalog-info.yaml config file',
body: `This pull request adds a **Backstage entity metadata file** \
title: title ?? 'Add catalog-info.yaml config file',
body:
body ??
`This pull request adds a **Backstage entity metadata file** \
to this repository so that the component can be added to the \
[${appTitle} software catalog](${appBaseUrl}).\n\nAfter this pull request is merged, \
the component will become available.\n\nFor more information, read an \
@@ -160,10 +167,12 @@ export function defaultGenerateStepper(
return defaults.prepare(state, opts);
}
const { title, body } = (
opts?.opts?.pullRequest?.preparePullRequest ??
defaultPreparePullRequest
)(opts.apis);
const preparePullRequest =
opts?.opts?.pullRequest?.preparePullRequest;
const { title, body } = defaultPreparePullRequest(
opts.apis,
preparePullRequest ? preparePullRequest(opts.apis) : {},
);
return {
stepLabel: <StepLabel>Create Pull Request</StepLabel>,