chore(plugins/scaffolder-backend-module-github): making config optional
Signed-off-by: Matheus Castiglioni <mahenrique94@users.noreply.github.com>
This commit is contained in:
@@ -128,7 +128,7 @@ export interface CreateGithubPullRequestActionOptions {
|
||||
} | null>;
|
||||
}
|
||||
>;
|
||||
config: Config;
|
||||
config?: Config;
|
||||
githubCredentialsProvider?: GithubCredentialsProvider;
|
||||
integrations: ScmIntegrationRegistry;
|
||||
}
|
||||
|
||||
@@ -955,4 +955,64 @@ describe('createPublishGithubPullRequestAction', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('with author fallback and no config', () => {
|
||||
let input: GithubPullRequestActionInput;
|
||||
let ctx: ActionContext<GithubPullRequestActionInput>;
|
||||
|
||||
beforeEach(() => {
|
||||
input = {
|
||||
repoUrl: 'github.com?owner=myorg&repo=myrepo',
|
||||
title: 'Create my new app',
|
||||
branchName: 'new-app',
|
||||
description: 'This PR is really good',
|
||||
gitAuthorName: 'Foo Bar',
|
||||
};
|
||||
|
||||
mockDir.setContent({
|
||||
[workspacePath]: { 'file.txt': 'Hello there!' },
|
||||
});
|
||||
|
||||
ctx = createMockActionContext({ input, workspacePath });
|
||||
});
|
||||
|
||||
it('creates a pull request with using author name and email fallback when have no config', async () => {
|
||||
const clientFactory = jest.fn(async () => fakeClient as any);
|
||||
const githubCredentialsProvider: GithubCredentialsProvider = {
|
||||
getCredentials: jest.fn(),
|
||||
};
|
||||
|
||||
const instanceWithConfig = createPublishGithubPullRequestAction({
|
||||
integrations,
|
||||
githubCredentialsProvider,
|
||||
clientFactory,
|
||||
});
|
||||
|
||||
await instanceWithConfig.handler(ctx);
|
||||
|
||||
expect(fakeClient.createPullRequest).toHaveBeenCalledWith({
|
||||
owner: 'myorg',
|
||||
repo: 'myrepo',
|
||||
title: 'Create my new app',
|
||||
head: 'new-app',
|
||||
body: 'This PR is really good',
|
||||
changes: [
|
||||
{
|
||||
commit: 'Create my new app',
|
||||
files: {
|
||||
'file.txt': {
|
||||
content: Buffer.from('Hello there!').toString('base64'),
|
||||
encoding: 'base64',
|
||||
mode: '100644',
|
||||
},
|
||||
},
|
||||
author: {
|
||||
email: 'scaffolder@backstage.io',
|
||||
name: 'Foo Bar',
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -104,7 +104,7 @@ export interface CreateGithubPullRequestActionOptions {
|
||||
/**
|
||||
* An instance of {@link @backstage/config#Config} that will be used in the action.
|
||||
*/
|
||||
config: Config;
|
||||
config?: Config;
|
||||
}
|
||||
|
||||
type GithubPullRequest = {
|
||||
@@ -351,7 +351,7 @@ export const createPublishGithubPullRequestAction = (
|
||||
files,
|
||||
commit:
|
||||
commitMessage ??
|
||||
config.getOptionalString('scaffolder.defaultCommitMessage') ??
|
||||
config?.getOptionalString('scaffolder.defaultCommitMessage') ??
|
||||
title,
|
||||
},
|
||||
],
|
||||
@@ -365,10 +365,10 @@ export const createPublishGithubPullRequestAction = (
|
||||
const gitAuthorInfo = {
|
||||
name:
|
||||
gitAuthorName ??
|
||||
config.getOptionalString('scaffolder.defaultAuthor.name'),
|
||||
config?.getOptionalString('scaffolder.defaultAuthor.name'),
|
||||
email:
|
||||
gitAuthorEmail ??
|
||||
config.getOptionalString('scaffolder.defaultAuthor.email'),
|
||||
config?.getOptionalString('scaffolder.defaultAuthor.email'),
|
||||
};
|
||||
|
||||
if (gitAuthorInfo.name || gitAuthorInfo.email) {
|
||||
|
||||
Reference in New Issue
Block a user