-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config/migration): migrate config with a PR (#15122)
Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com> Co-authored-by: Michael Kriese <michael.kriese@visualon.de> Co-authored-by: Rhys Arkins <rhys@arkins.net>
- Loading branch information
1 parent
7f51e58
commit dd3598c
Showing
27 changed files
with
1,435 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
lib/workers/repository/config-migration/branch/__fixtures__/migrated-data.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"filename": "renovate.json", | ||
"content": "{\n \"extends\": [\n \":separateMajorReleases\",\n \":prImmediately\",\n \":renovatePrefix\",\n \":semanticPrefixFixDepsChoreOthers\",\n \":updateNotScheduled\",\n \":automergeDisabled\",\n \":maintainLockFilesDisabled\",\n \":autodetectPinVersions\",\n \"group:monorepos\"\n ],\n \"onboarding\": false,\n \"rangeStrategy\": \"replace\",\n \"semanticCommits\": \"enabled\",\n \"timezone\": \"US/Central\",\n \"baseBranches\": [\n \"main\"\n ]\n}\n" | ||
} |
4 changes: 4 additions & 0 deletions
4
lib/workers/repository/config-migration/branch/__fixtures__/migrated-data.json5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"filename": "renovate.json5", | ||
"content": "{\n extends: [\n ':separateMajorReleases',\n ':prImmediately',\n ':renovatePrefix',\n ':semanticPrefixFixDepsChoreOthers',\n ':updateNotScheduled',\n ':automergeDisabled',\n ':maintainLockFilesDisabled',\n ':autodetectPinVersions',\n 'group:monorepos',\n ],\n onboarding: false,\n rangeStrategy: 'replace',\n semanticCommits: 'enabled',\n timezone: 'US/Central',\n baseBranches: [\n 'main',\n ],\n}\n" | ||
} |
20 changes: 20 additions & 0 deletions
20
lib/workers/repository/config-migration/branch/__fixtures__/migrated.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"extends": [ | ||
":separateMajorReleases", | ||
":prImmediately", | ||
":renovatePrefix", | ||
":semanticPrefixFixDepsChoreOthers", | ||
":updateNotScheduled", | ||
":automergeDisabled", | ||
":maintainLockFilesDisabled", | ||
":autodetectPinVersions", | ||
"group:monorepos" | ||
], | ||
"onboarding": false, | ||
"rangeStrategy": "replace", | ||
"semanticCommits": "enabled", | ||
"timezone": "US/Central", | ||
"baseBranches": [ | ||
"main" | ||
] | ||
} |
19 changes: 19 additions & 0 deletions
19
lib/workers/repository/config-migration/branch/__fixtures__/renovate.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"extends": [ | ||
":separateMajorReleases", | ||
":prImmediately", | ||
":renovatePrefix", | ||
":semanticPrefixFixDepsChoreOthers", | ||
":updateNotScheduled", | ||
":automergeDisabled", | ||
":maintainLockFilesDisabled", | ||
":autodetectPinVersions", | ||
"group:monorepos", | ||
"helpers:oddIsUnstablePackages" | ||
], | ||
"onboarding": false, | ||
"pinVersions": false, | ||
"semanticCommits": true, | ||
"timezone": "US/Central", | ||
"baseBranch": "main" | ||
} |
19 changes: 19 additions & 0 deletions
19
lib/workers/repository/config-migration/branch/__fixtures__/renovate.json5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
extends: [ | ||
':separateMajorReleases', | ||
':prImmediately', | ||
':renovatePrefix', | ||
':semanticPrefixFixDepsChoreOthers', | ||
':updateNotScheduled', | ||
':automergeDisabled', | ||
':maintainLockFilesDisabled', | ||
':autodetectPinVersions', | ||
'group:monorepos', | ||
'helpers:oddIsUnstablePackages' | ||
], | ||
onboarding: false, | ||
pinVersions: false, | ||
semanticCommits: true, | ||
timezone: 'US/Central', | ||
baseBranch: 'main' // thats a comment | ||
} |
46 changes: 46 additions & 0 deletions
46
lib/workers/repository/config-migration/branch/commit-message.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import type { RenovateConfig } from '../../../../config/types'; | ||
import * as template from '../../../../util/template'; | ||
import type { CommitMessage } from '../../model/commit-message'; | ||
import { CommitMessageFactory } from '../../model/commit-message-factory'; | ||
|
||
export class ConfigMigrationCommitMessageFactory { | ||
private readonly config: RenovateConfig; | ||
|
||
private readonly configFile: string; | ||
|
||
constructor(config: RenovateConfig, configFile: string) { | ||
this.config = config; | ||
this.configFile = configFile; | ||
} | ||
|
||
create(): CommitMessage { | ||
const { commitMessage } = this.config; | ||
|
||
this.config.commitMessageAction = | ||
this.config.commitMessageAction === 'Update' | ||
? '' | ||
: this.config.commitMessageAction; | ||
|
||
this.config.commitMessageTopic = | ||
this.config.commitMessageTopic === 'dependency {{depName}}' | ||
? `Migrate config ${this.configFile}` | ||
: this.config.commitMessageTopic; | ||
|
||
this.config.commitMessageExtra = ''; | ||
this.config.semanticCommitScope = 'config'; | ||
|
||
const commitMessageFactory = new CommitMessageFactory(this.config); | ||
const commit = commitMessageFactory.create(); | ||
|
||
if (commitMessage) { | ||
commit.subject = template.compile(commitMessage, { | ||
...this.config, | ||
commitMessagePrefix: '', | ||
}); | ||
} else { | ||
commit.subject = `Migrate config ${this.configFile}`; | ||
} | ||
|
||
return commit; | ||
} | ||
} |
179 changes: 179 additions & 0 deletions
179
lib/workers/repository/config-migration/branch/create.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
import { Fixtures } from '../../../../../test/fixtures'; | ||
import { RenovateConfig, getConfig, platform } from '../../../../../test/util'; | ||
import { commitFiles } from '../../../../util/git'; | ||
import { createConfigMigrationBranch } from './create'; | ||
import type { MigratedData } from './migrated-data'; | ||
|
||
jest.mock('../../../../util/git'); | ||
|
||
describe('workers/repository/config-migration/branch/create', () => { | ||
const raw = Fixtures.getJson('./renovate.json'); | ||
const indent = ' '; | ||
const renovateConfig = JSON.stringify(raw, undefined, indent) + '\n'; | ||
const filename = 'renovate.json'; | ||
|
||
let config: RenovateConfig; | ||
let migratedConfigData: MigratedData; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
config = getConfig(); | ||
migratedConfigData = { content: renovateConfig, filename }; | ||
}); | ||
|
||
describe('createConfigMigrationBranch', () => { | ||
it('applies the default commit message', async () => { | ||
await createConfigMigrationBranch(config, migratedConfigData); | ||
expect(commitFiles).toHaveBeenCalledWith({ | ||
branchName: 'renovate/migrate-config', | ||
files: [ | ||
{ | ||
type: 'addition', | ||
path: 'renovate.json', | ||
contents: renovateConfig, | ||
}, | ||
], | ||
message: 'Migrate config renovate.json', | ||
platformCommit: false, | ||
}); | ||
}); | ||
|
||
it('commits via platform', async () => { | ||
config.platformCommit = true; | ||
|
||
await createConfigMigrationBranch(config, migratedConfigData); | ||
|
||
expect(platform.commitFiles).toHaveBeenCalledWith({ | ||
branchName: 'renovate/migrate-config', | ||
files: [ | ||
{ | ||
type: 'addition', | ||
path: 'renovate.json', | ||
contents: renovateConfig, | ||
}, | ||
], | ||
message: 'Migrate config renovate.json', | ||
platformCommit: true, | ||
}); | ||
}); | ||
|
||
it('applies supplied commit message', async () => { | ||
const message = 'We can migrate config if we want to, or we can not'; | ||
|
||
config.commitMessage = message; | ||
|
||
await createConfigMigrationBranch(config, migratedConfigData); | ||
|
||
expect(commitFiles).toHaveBeenCalledWith({ | ||
branchName: 'renovate/migrate-config', | ||
files: [ | ||
{ | ||
type: 'addition', | ||
path: 'renovate.json', | ||
contents: renovateConfig, | ||
}, | ||
], | ||
message: message, | ||
platformCommit: false, | ||
}); | ||
}); | ||
|
||
describe('applies the commitMessagePrefix value', () => { | ||
it('to the default commit message', async () => { | ||
config.commitMessagePrefix = 'PREFIX:'; | ||
config.commitMessage = ''; | ||
|
||
const message = `PREFIX: migrate config renovate.json`; | ||
await createConfigMigrationBranch(config, migratedConfigData); | ||
|
||
expect(commitFiles).toHaveBeenCalledWith({ | ||
branchName: 'renovate/migrate-config', | ||
files: [ | ||
{ | ||
type: 'addition', | ||
path: 'renovate.json', | ||
contents: renovateConfig, | ||
}, | ||
], | ||
message: message, | ||
platformCommit: false, | ||
}); | ||
}); | ||
|
||
it('to the supplied commit message prefix, topic & action', async () => { | ||
const prefix = 'PREFIX:'; | ||
const topic = 'thats a topic'; | ||
const action = 'action'; | ||
|
||
const message = `${prefix} ${action} ${topic}`; | ||
|
||
config.commitMessagePrefix = prefix; | ||
config.commitMessageTopic = topic; | ||
config.commitMessageAction = action; | ||
|
||
await createConfigMigrationBranch(config, migratedConfigData); | ||
|
||
expect(commitFiles).toHaveBeenCalledWith({ | ||
branchName: 'renovate/migrate-config', | ||
files: [ | ||
{ | ||
type: 'addition', | ||
path: 'renovate.json', | ||
contents: renovateConfig, | ||
}, | ||
], | ||
message: message, | ||
platformCommit: false, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('applies semanticCommit prefix', () => { | ||
it('to the default commit message', async () => { | ||
const prefix = 'chore(config)'; | ||
const message = `${prefix}: migrate config renovate.json`; | ||
|
||
config.semanticCommits = 'enabled'; | ||
|
||
await createConfigMigrationBranch(config, migratedConfigData); | ||
|
||
expect(commitFiles).toHaveBeenCalledWith({ | ||
branchName: 'renovate/migrate-config', | ||
files: [ | ||
{ | ||
type: 'addition', | ||
path: 'renovate.json', | ||
contents: renovateConfig, | ||
}, | ||
], | ||
message: message, | ||
platformCommit: false, | ||
}); | ||
}); | ||
|
||
it('to the supplied commit message topic', async () => { | ||
const prefix = 'chore(config)'; | ||
const topic = 'supplied topic'; | ||
const message = `${prefix}: ${topic}`; | ||
|
||
config.semanticCommits = 'enabled'; | ||
config.commitMessageTopic = topic; | ||
|
||
await createConfigMigrationBranch(config, migratedConfigData); | ||
|
||
expect(commitFiles).toHaveBeenCalledWith({ | ||
branchName: 'renovate/migrate-config', | ||
files: [ | ||
{ | ||
type: 'addition', | ||
path: 'renovate.json', | ||
contents: renovateConfig, | ||
}, | ||
], | ||
message: message, | ||
platformCommit: false, | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.