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 4 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
44 changes: 44 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,50 @@ describe('workers/repository/onboarding/branch/create', () => {
});
});

describe('applies the commitBody value', () => {
const commitBody = 'Signed Off: {{gitAuthor}}';
const gitAuthor = 'Bot bot@botland.com';

it('to the default commit message', async () => {
await createOnboardingBranch({ ...config, commitBody, gitAuthor });
expect(scm.commitAndPush).toHaveBeenCalledWith({
branchName: 'renovate/configure',
files: [
{
type: 'addition',
path: 'renovate.json',
contents: '{"foo":"bar"}',
},
],
force: true,
message: `Add renovate.json\n\nSigned Off: Bot bot@botland.com`,
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, gitAuthor });
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
14 changes: 12 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 * as template from '../../../../util/template';
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
import { OnboardingCommitMessageFactory } from './commit-message';
import { getOnboardingConfigContents } from './config';

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

if (config.commitBody) {
commitMessage = `${commitMessage}\n\n${template.compile(
config.commitBody,
config,
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
)}`;

logger.trace(`commitMessage: ` + JSON.stringify(commitMessage));
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
}

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