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(prepare): return correct releaseType #885

Merged
merged 1 commit into from
Jun 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions packages/shipjs-lib/src/lib/util/__tests__/getReleaseType.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,16 @@ import getReleaseType from '../getReleaseType';
describe('getReleaseType', () => {
it('works', () => {
const list = [
['1.2.3', '2.0.0', 'major'],
['1.2.3', '1.3.0', 'minor'],
['1.2.3', '1.2.4', 'patch'],
['1.2.3', '1.2.4-alpha.0', 'prerelease'],

['1.2.4-alpha.0', '1.2.4-alpha.1', 'prerelease'],
['1.2.4-alpha.0', '1.2.4', 'patch'],
['1.2.4-alpha.0', '1.2.5', 'patch'],
['1.2.4-alpha.0', '1.3.0', 'minor'],
['1.2.4-alpha.0', '2.0.0', 'major'],

['1.3.0-alpha.0', '1.3.0', 'minor'],
['2.0.0', 'major'],
['1.3.0', 'minor'],
['1.2.4', 'patch'],
['1.2.5', 'patch'],
['1.2.4-alpha.0', 'prerelease'],
];

list.forEach(([currentVersion, nextVersion, expected]) => {
const actual = getReleaseType(currentVersion, nextVersion);
expect({ currentVersion, nextVersion, result: actual }).toEqual({
currentVersion,
list.forEach(([nextVersion, expected]) => {
const actual = getReleaseType(nextVersion);
expect({ nextVersion, result: actual }).toEqual({
nextVersion,
result: expected,
});
Expand Down
22 changes: 10 additions & 12 deletions packages/shipjs-lib/src/lib/util/getReleaseType.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { diff, prerelease, minor, patch } from 'semver';
import { prerelease, minor, patch } from 'semver';

export default function getReleaseType(currentVersion, nextVersion) {
if (prerelease(currentVersion) === null && prerelease(nextVersion) !== null) {
export default function getReleaseType(nextVersion) {
if (prerelease(nextVersion) !== null) {
return 'prerelease';
}
if (prerelease(currentVersion) !== null && prerelease(nextVersion) === null) {
if (patch(nextVersion) === 0) {
if (minor(nextVersion) === 0) {
return 'major';
} else {
return 'minor';
}

if (patch(nextVersion) === 0) {
if (minor(nextVersion) === 0) {
return 'major';
} else {
return 'patch';
return 'minor';
}
} else {
return 'patch';
}
return diff(currentVersion, nextVersion);
}
2 changes: 1 addition & 1 deletion packages/shipjs/src/flow/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async function prepare({
nextVersion,
dryRun,
});
const releaseType = getReleaseType(currentVersion, nextVersion);
const releaseType = getReleaseType(nextVersion);
await validatePreparationConditions({
config,
releaseType,
Expand Down