Merge pull request #21880 from npiyush97/commit-fix

Fixed Bug related defaultCommitMessage
This commit is contained in:
Ben Lambert
2023-12-19 10:37:23 +01:00
committed by GitHub
6 changed files with 56 additions and 15 deletions
+5
View File
@@ -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.
@@ -14,7 +14,6 @@
* limitations under the License.
*/
import { Config } from '@backstage/config';
import { assertError } from '@backstage/errors';
import { Octokit } from 'octokit';
import { Logger } from 'winston';
@@ -129,15 +128,6 @@ export const enableBranchProtectionOnDefaultRepoBranch = async ({
}
};
export function getGitCommitMessage(
gitCommitMessage: string | undefined,
config: Config,
): string | undefined {
return gitCommitMessage
? gitCommitMessage
: config.getOptionalString('scaffolder.defaultCommitMessage');
}
export function entityRefToName(name: string): string {
return name.replace(/^.*[:/]/g, '');
}
@@ -564,7 +564,7 @@ describe('publish:github', () => {
defaultBranch: 'master',
auth: { username: 'x-access-token', password: 'tokenlols' },
logger: mockContext.logger,
commitMessage: 'initial commit',
commitMessage: 'Test commit message',
gitAuthorInfo: { email: undefined, name: undefined },
});
});
@@ -187,7 +187,7 @@ export function createPublishGithubAction(options: {
protectDefaultBranch = true,
protectEnforceAdmins = true,
deleteBranchOnMerge = false,
gitCommitMessage = 'initial commit',
gitCommitMessage,
gitAuthorName,
gitAuthorEmail,
allowMergeCommit = true,
@@ -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();
});
});
@@ -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),