Skip to content

Commit

Permalink
feat(catalog-import): use title for commit message
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Thauer <[email protected]>
  • Loading branch information
andrewthauer committed Mar 13, 2021
1 parent 4344ef8 commit a0dacc1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
20 changes: 20 additions & 0 deletions .changeset/new-suits-mate.md
Original file line number Diff line number Diff line change
@@ -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]',
}),
}}
/>
}
/>
```
6 changes: 3 additions & 3 deletions plugins/catalog-import/src/api/CatalogImportClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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',
});
Expand All @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion plugins/catalog-import/src/api/CatalogImportClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
25 changes: 17 additions & 8 deletions plugins/catalog-import/src/components/ImportStepper/defaults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
};
};

Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -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>,
Expand Down

0 comments on commit a0dacc1

Please sign in to comment.