Skip to content

Commit

Permalink
feat: semantic pr title for migrationPRs (#16490)
Browse files Browse the repository at this point in the history
* generate PR title using ConfigMigrationCommitMessageFactory

* add test
  • Loading branch information
RahulGautamSingh committed Jul 15, 2022
1 parent f506580 commit cc55f15
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
34 changes: 34 additions & 0 deletions lib/workers/repository/config-migration/pr/index.spec.ts
Expand Up @@ -169,6 +169,40 @@ describe('workers/repository/config-migration/pr/index', () => {
expect(platform.createPr.mock.calls[0][0].prBody).toMatchSnapshot();
});

it('creates non-semantic PR title', async () => {
await ensureConfigMigrationPr(
{
...config,
prHeader: '\r\r\nThis should not be the first line of the PR',
prFooter:
'There should be several empty lines at the end of the PR\r\n\n\n',
},
migratedData
);
expect(platform.createPr).toHaveBeenCalledTimes(1);
expect(platform.createPr.mock.calls[0][0].prTitle).toBe(
'Migrate config renovate.json'
);
});

it('creates semantic PR title', async () => {
await ensureConfigMigrationPr(
{
...config,
commitMessagePrefix: '',
semanticCommits: 'enabled',
prHeader: '\r\r\nThis should not be the first line of the PR',
prFooter:
'There should be several empty lines at the end of the PR\r\n\n\n',
},
migratedData
);
expect(platform.createPr).toHaveBeenCalledTimes(1);
expect(platform.createPr.mock.calls[0][0].prTitle).toBe(
'chore(config): migrate config renovate.json'
);
});

it('creates PR with footer and header using templating', async () => {
config.baseBranch = 'some-branch';
config.repository = 'test';
Expand Down
8 changes: 7 additions & 1 deletion lib/workers/repository/config-migration/pr/index.ts
Expand Up @@ -11,6 +11,7 @@ import { joinUrlParts } from '../../../../util/url';
import { getPlatformPrOptions } from '../../update/pr';
import { prepareLabels } from '../../update/pr/labels';
import { addParticipants } from '../../update/pr/participants';
import { ConfigMigrationCommitMessageFactory } from '../branch/commit-message';
import type { MigratedData } from '../branch/migrated-data';
import { getMigrationBranchName } from '../common';

Expand All @@ -24,7 +25,12 @@ export async function ensureConfigMigrationPr(
'configuration-options/#configmigration'
);
const branchName = getMigrationBranchName(config);
const prTitle = 'Migrate Renovate config';
const commitMessageFactory = new ConfigMigrationCommitMessageFactory(
config,
migratedConfigData.filename
);

const prTitle = commitMessageFactory.create().toString();
const existingPr = await platform.getBranchPr(branchName);
const filename = migratedConfigData.filename;
logger.debug('Filling in config migration PR template');
Expand Down

0 comments on commit cc55f15

Please sign in to comment.