Skip to content

Commit

Permalink
fix(onboarding): add commitBody to commitMessage (#26426)
Browse files Browse the repository at this point in the history
  • Loading branch information
RahulGautamSingh committed Dec 27, 2023
1 parent 4345212 commit 9e171ff
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/config/types.ts
Expand Up @@ -208,6 +208,7 @@ export interface RenovateConfig
Record<string, unknown> {
depName?: string;
baseBranches?: string[];
commitBody?: string;
useBaseBranchConfig?: UseBaseBranchConfigType;
baseBranch?: string;
defaultBranch?: string;
Expand Down
48 changes: 48 additions & 0 deletions lib/workers/repository/onboarding/branch/create.spec.ts
Expand Up @@ -57,6 +57,54 @@ describe('workers/repository/onboarding/branch/create', () => {
});
});

describe('applies the commitBody value', () => {
it('to the default commit message', async () => {
await createOnboardingBranch({
...config,
commitBody: 'some commit body',
});
expect(scm.commitAndPush).toHaveBeenCalledWith({
branchName: 'renovate/configure',
files: [
{
type: 'addition',
path: 'renovate.json',
contents: '{"foo":"bar"}',
},
],
force: true,
message: `Add renovate.json\n\nsome commit body`,
platformCommit: false,
});
});

it('to the supplied commit message', async () => {
const message =
'We can Renovate if we want to, we can leave PRs in decline';

config.onboardingCommitMessage = message;

await createOnboardingBranch({
...config,
commitBody: 'Signed Off: {{{gitAuthor}}}',
gitAuthor: '<Bot bot@botland.com>',
});
expect(scm.commitAndPush).toHaveBeenCalledWith({
branchName: 'renovate/configure',
files: [
{
type: 'addition',
path: 'renovate.json',
contents: '{"foo":"bar"}',
},
],
force: true,
message: `We can Renovate if we want to, we can leave PRs in decline\n\nSigned Off: <Bot bot@botland.com>`,
platformCommit: false,
});
});
});

describe('applies the commitMessagePrefix value', () => {
it('to the default commit message', async () => {
const prefix = 'RENOV-123';
Expand Down
15 changes: 13 additions & 2 deletions lib/workers/repository/onboarding/branch/create.ts
Expand Up @@ -3,6 +3,7 @@ import { GlobalConfig } from '../../../../config/global';
import type { RenovateConfig } from '../../../../config/types';
import { logger } from '../../../../logger';
import { scm } from '../../../../modules/platform/scm';
import { compile } from '../../../../util/template';
import { OnboardingCommitMessageFactory } from './commit-message';
import { getOnboardingConfigContents } from './config';

Expand All @@ -25,7 +26,17 @@ export async function createOnboardingBranch(
config,
configFile!,
);
const commitMessage = commitMessageFactory.create();
let commitMessage = commitMessageFactory.create().toString();

if (config.commitBody) {
commitMessage = `${commitMessage}\n\n${compile(
config.commitBody,
// only allow gitAuthor template value in the commitBody
{ gitAuthor: config.gitAuthor },
)}`;

logger.trace(`commitMessage: ${commitMessage}`);
}

// istanbul ignore if
if (GlobalConfig.get('dryRun')) {
Expand All @@ -44,7 +55,7 @@ export async function createOnboardingBranch(
contents,
},
],
message: commitMessage.toString(),
message: commitMessage,
platformCommit: !!config.platformCommit,
force: true,
});
Expand Down

0 comments on commit 9e171ff

Please sign in to comment.