Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(migrations): migrate node (#16422)
Co-authored-by: Jamie Magee <jamie.magee@gmail.com>
- Loading branch information
1 parent
895218d
commit 8b9d038
Showing
4 changed files
with
50 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { NodeMigration } from './node-migration'; | ||
|
||
describe('config/migrations/custom/node-migration', () => { | ||
it('should migrate node to travis', () => { | ||
expect(NodeMigration).toMigrate( | ||
{ | ||
node: { enabled: true }, | ||
}, | ||
{ | ||
travis: { enabled: true }, | ||
} | ||
); | ||
}); | ||
|
||
it('should not delete node incase it has more than one property', () => { | ||
expect(NodeMigration).toMigrate( | ||
{ | ||
node: { enabled: true, automerge: false }, | ||
}, | ||
{ | ||
node: { automerge: false }, | ||
travis: { enabled: true }, | ||
} | ||
); | ||
}); | ||
}); |
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,22 @@ | ||
import type { RenovateConfig } from '../../types'; | ||
import { AbstractMigration } from '../base/abstract-migration'; | ||
|
||
export class NodeMigration extends AbstractMigration { | ||
override readonly propertyName = 'node'; | ||
|
||
override run(value: unknown): void { | ||
const node = this.get('node') as RenovateConfig; | ||
if ((value as RenovateConfig).enabled === true) { | ||
// validated non-null | ||
delete node.enabled; | ||
const travis = (this.get('travis') ?? {}) as RenovateConfig; | ||
travis.enabled = true; | ||
if (Object.keys(node).length) { | ||
this.rewrite(node); | ||
} else { | ||
this.delete('node'); | ||
} | ||
this.setSafely('travis', travis); | ||
} | ||
} | ||
} |
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