-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app-builder): determine commit type based on upgraded versions
- Loading branch information
1 parent
6639e04
commit c8353fb
Showing
13 changed files
with
166 additions
and
17 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
58 changes: 58 additions & 0 deletions
58
apps/app-builder/src/commands/upgrade/createCommitMessage.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,58 @@ | ||
import {describe, expect, it} from 'vitest'; | ||
import {createTestContext} from '../../__tests__/createTestContext'; | ||
import {type UpgradedEntry, UpgradeMode} from './types'; | ||
import {createCommitMessage} from './createCommitMessage'; | ||
|
||
describe('createCommitMessage', () => { | ||
it('creates commit message for a single node dependency', () => { | ||
const upgradedVersions = [ | ||
{ | ||
name: 'vue', | ||
version: '3.3.0', | ||
oldVersion: '3.2.0', | ||
repository: 'https://github.com/vuejs/vue/', | ||
}, | ||
] satisfies UpgradedEntry[]; | ||
|
||
const context = createTestContext(); | ||
|
||
const commitMessage = createCommitMessage(upgradedVersions, { | ||
...context, | ||
mode: UpgradeMode.Node, | ||
packageName: 'vue', | ||
}); | ||
|
||
expect(commitMessage).toEqual(`feat(deps): upgrade vue to v3.3.0 | ||
Compare changes: | ||
- https://github.com/vuejs/vue/compare/v3.2.0...v3.3.0`); | ||
}); | ||
|
||
it('creates commit message for multiple node dependencies', () => { | ||
const upgradedVersions = [ | ||
{ | ||
name: '@myparcel-pdk/app-builder', | ||
version: '1.1.5', | ||
oldVersion: '1.1.1', | ||
}, | ||
{ | ||
name: '@myparcel-pdk/admin', | ||
version: '1.1.2', | ||
oldVersion: '1.1.1', | ||
}, | ||
] satisfies UpgradedEntry[]; | ||
|
||
const context = createTestContext(); | ||
|
||
const commitMessage = createCommitMessage(upgradedVersions, { | ||
...context, | ||
mode: UpgradeMode.Node, | ||
packageName: '@myparcel-pdk/*', | ||
}); | ||
|
||
expect(commitMessage).toEqual(`fix(deps): upgrade @myparcel-pdk/* | ||
- upgrade @myparcel-pdk/app-builder to v1.1.5 | ||
- upgrade @myparcel-pdk/admin to v1.1.2`); | ||
}); | ||
}); |
10 changes: 5 additions & 5 deletions
10
apps/app-builder/src/commands/upgrade/createCommitMessage.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
59 changes: 59 additions & 0 deletions
59
apps/app-builder/src/commands/upgrade/getCommitType.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,59 @@ | ||
import {describe, expect, it} from 'vitest'; | ||
import {COMMIT_TYPE_AUTO} from '../../constants'; | ||
import {createTestContext} from '../../__tests__/createTestContext'; | ||
import {type UpgradedEntry} from './types'; | ||
import {getCommitType} from './getCommitType'; | ||
|
||
type TestInput = { | ||
commitType: string; | ||
versions: UpgradedEntry[]; | ||
result: string; | ||
}; | ||
|
||
const createEntry = (newVersion: string, oldVersion?: string): UpgradedEntry => { | ||
return {name: 'test', repository: '', oldVersion, version: newVersion}; | ||
}; | ||
|
||
describe('getCommitType', () => { | ||
it.each([ | ||
{ | ||
commitType: 'chore', | ||
versions: [createEntry('1.0.1', '1.0.0')], | ||
result: 'chore', | ||
}, | ||
{ | ||
commitType: 'chore', | ||
versions: [createEntry('1.1.0', '1.0.0')], | ||
result: 'chore', | ||
}, | ||
{ | ||
commitType: COMMIT_TYPE_AUTO, | ||
versions: [createEntry('1.0.1', '1.0.0'), createEntry('3.40.3', '3.40.0'), createEntry('4.14.3', '4.14.0')], | ||
result: 'fix', | ||
}, | ||
{ | ||
commitType: COMMIT_TYPE_AUTO, | ||
versions: [createEntry('1.1.0', '1.0.0')], | ||
result: 'feat', | ||
}, | ||
{ | ||
commitType: COMMIT_TYPE_AUTO, | ||
versions: [createEntry('1.1.0', '1.0.0'), createEntry('3.0.0', '2.0.0'), createEntry('4.14.3', '4.14.0')], | ||
result: 'feat', | ||
}, | ||
{ | ||
commitType: COMMIT_TYPE_AUTO, | ||
versions: [createEntry('1.1.0'), createEntry('3.0.1', '3.0.0')], | ||
result: 'feat', | ||
}, | ||
{ | ||
commitType: COMMIT_TYPE_AUTO, | ||
versions: [createEntry('1.0.0-alpha.62', '1.0.0-alpha.60')], | ||
result: 'feat', | ||
}, | ||
] satisfies TestInput[])('returns string', ({commitType, versions, result}) => { | ||
const context = createTestContext({config: {commitType}}); | ||
|
||
expect(getCommitType(context, versions)).toBe(result); | ||
}); | ||
}); |
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 diff from 'semver/functions/diff'; | ||
import {type PdkBuilderContext} from '../../types'; | ||
import {COMMIT_TYPE_AUTO} from '../../constants'; | ||
import {type UpgradedEntry} from './types'; | ||
|
||
export const getCommitType = (context: PdkBuilderContext, upgradedVersions: UpgradedEntry[]): string => { | ||
if (context.config.commitType === COMMIT_TYPE_AUTO) { | ||
const isPatchUpgrade = upgradedVersions.every((updatedVersion) => { | ||
if (!updatedVersion.oldVersion) { | ||
return false; | ||
} | ||
|
||
const difference = diff(updatedVersion.oldVersion, updatedVersion.version); | ||
|
||
return difference === 'patch'; | ||
}); | ||
|
||
return isPatchUpgrade ? 'fix' : 'feat'; | ||
} | ||
|
||
return context.config.commitType; | ||
}; |
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
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