Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(onboarding): add commitBody to commitMessage #26426

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/config/types.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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