diff --git a/.changeset/clever-monkeys-double.md b/.changeset/clever-monkeys-double.md new file mode 100644 index 0000000000..9fbf541201 --- /dev/null +++ b/.changeset/clever-monkeys-double.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend-module-github': patch +--- + +The `scaffolder.defaultCommitMessage` config value is now being used if provided and uses "initial commit" when it is not provided. diff --git a/plugins/scaffolder-backend-module-github/src/actions/github.ts b/plugins/scaffolder-backend-module-github/src/actions/github.ts index 62f657b01c..91d7a34aea 100644 --- a/plugins/scaffolder-backend-module-github/src/actions/github.ts +++ b/plugins/scaffolder-backend-module-github/src/actions/github.ts @@ -187,7 +187,7 @@ export function createPublishGithubAction(options: { protectDefaultBranch = true, protectEnforceAdmins = true, deleteBranchOnMerge = false, - gitCommitMessage = 'initial commit', + gitCommitMessage, gitAuthorName, gitAuthorEmail, allowMergeCommit = true, diff --git a/plugins/scaffolder-backend-module-github/src/actions/helper.test.ts b/plugins/scaffolder-backend-module-github/src/actions/helper.test.ts new file mode 100644 index 0000000000..3934e07db7 --- /dev/null +++ b/plugins/scaffolder-backend-module-github/src/actions/helper.test.ts @@ -0,0 +1,47 @@ +/* + * Copyright 2023 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { ConfigReader } from '@backstage/config'; +import { getGitCommitMessage } from './helpers'; + +describe('getGitCommitMessage', () => { + it('should return gitCommitMessage when provided', () => { + const mockConfig = new ConfigReader({}); + const gitCommitMessage = 'Custom commit message'; + + const result = getGitCommitMessage(gitCommitMessage, mockConfig); + + expect(result).toEqual('Custom commit message'); + }); + + it('should return default commit message from config when gitCommitMessage is undefined', () => { + const mockConfig = new ConfigReader({ + scaffolder: { + defaultCommitMessage: 'Default commit message', + }, + }); + const result = getGitCommitMessage(undefined, mockConfig); + + expect(result).toEqual('Default commit message'); + }); + + it('should return undefined when both gitCommitMessage and default commit message are undefined', () => { + const mockConfig = new ConfigReader({}); + const result = getGitCommitMessage(undefined, mockConfig); + + expect(result).toBeUndefined(); + }); +}); diff --git a/plugins/scaffolder-backend-module-github/src/actions/helpers.ts b/plugins/scaffolder-backend-module-github/src/actions/helpers.ts index c6c4bd4ce5..4d95a6494f 100644 --- a/plugins/scaffolder-backend-module-github/src/actions/helpers.ts +++ b/plugins/scaffolder-backend-module-github/src/actions/helpers.ts @@ -354,9 +354,8 @@ export async function initRepoPushAndProtect( : config.getOptionalString('scaffolder.defaultAuthor.email'), }; - const commitMessage = gitCommitMessage - ? gitCommitMessage - : config.getOptionalString('scaffolder.defaultCommitMessage'); + const commitMessage = + getGitCommitMessage(gitCommitMessage, config) || 'initial commit'; const commitResult = await initRepoAndPush({ dir: getRepoSourceDirectory(workspacePath, sourcePath),