-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(prepare): add
shouldPrepare
(#654)
- Loading branch information
Eunjae Lee
authored
Feb 3, 2020
1 parent
354f853
commit 166626d
Showing
9 changed files
with
157 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import silentExec from '../shell/silentExec'; | ||
|
||
export default function getBodies(revisionRange, dir) { | ||
const cmd = `git log ${revisionRange} --pretty=format:%b`; | ||
return silentExec(cmd, { dir, ignoreError: true }) | ||
.toString() | ||
.trim(); | ||
} |
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,8 @@ | ||
import silentExec from '../shell/silentExec'; | ||
|
||
export default function getCommitTitles(revisionRange, dir) { | ||
const cmd = `git log ${revisionRange} --pretty=format:%s`; | ||
return silentExec(cmd, { dir, ignoreError: true }) | ||
.toString() | ||
.trim(); | ||
} |
31 changes: 31 additions & 0 deletions
31
packages/shipjs-lib/src/lib/util/getCommitNumbersPerType.js
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,31 @@ | ||
import { GIT_COMMIT_PREFIX_PATCH, GIT_COMMIT_PREFIX_MINOR } from '../const'; | ||
|
||
export default function getCommitNumbersPerType(commitTitles) { | ||
const ignoredMessages = []; | ||
const numbers = {}; | ||
commitTitles.split('\n').forEach(rawTitle => { | ||
const title = rawTitle.trim(); | ||
if (!title) { | ||
return; | ||
} | ||
if (title.startsWith('Merge branch')) { | ||
return; | ||
} | ||
const match = title.match(/(.*?)(\(.*?\))?:.*/); | ||
if (!match || !match[1]) { | ||
ignoredMessages.push(title); | ||
return; | ||
} | ||
const prefix = match[1].toLowerCase(); | ||
if ( | ||
GIT_COMMIT_PREFIX_PATCH.has(prefix) || | ||
GIT_COMMIT_PREFIX_MINOR.has(prefix) | ||
) { | ||
numbers[prefix] = numbers[prefix] || 0; | ||
numbers[prefix] += 1; | ||
} else { | ||
ignoredMessages.push(title); | ||
} | ||
}); | ||
return { numbers, ignoredMessages }; | ||
} |
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
49 changes: 49 additions & 0 deletions
49
packages/shipjs/src/step/prepare/validatePreparationConditions.js
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,49 @@ | ||
import { | ||
getReleaseTag, | ||
getCommitTitles, | ||
getCommitNumbersPerType, | ||
} from 'shipjs-lib'; | ||
import runStep from '../runStep'; | ||
import { print, exitProcess } from '../../util'; | ||
import { info } from '../../color'; | ||
|
||
export default async ({ | ||
config, | ||
releaseType, | ||
nextVersion, | ||
revisionRange, | ||
dir, | ||
dryRun, | ||
}) => | ||
await runStep( | ||
{ | ||
title: 'Validating preparation conditions.', | ||
skipIf: () => config.shouldPrepare === undefined, | ||
}, | ||
async () => { | ||
const { shouldPrepare } = config; | ||
if (dryRun) { | ||
print(`-> execute ${info('shouldPrepare()')} callback.`); | ||
return; | ||
} | ||
const releaseTag = getReleaseTag(nextVersion); | ||
const commits = getCommitTitles(revisionRange, dir); | ||
const { numbers: commitNumbersPerType } = getCommitNumbersPerType( | ||
commits | ||
); | ||
|
||
const result = await shouldPrepare({ | ||
commits, | ||
nextVersion, | ||
releaseType, | ||
releaseTag, | ||
commitNumbersPerType, | ||
}); | ||
if (!result) { | ||
print( | ||
info('`shouldPrepare` returned false. So the preparation is skipped.') | ||
); | ||
exitProcess(0); | ||
} | ||
} | ||
); |
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