Skip to content

Commit

Permalink
fix: change formatCommitMessage and introduce formatPullRequestTitle (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Eunjae Lee authored Sep 23, 2019
1 parent 53862e8 commit f21e167
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 37 deletions.
44 changes: 26 additions & 18 deletions packages/shipjs-lib/src/lib/config/__tests__/defaultConfig.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import defaultConfig from '../defaultConfig';
const {
formatCommitMessage,
formatPullRequestTitle,
formatPullRequestMessage,
mergeStrategy: defaultMergeStrategy,
shouldRelease,
Expand All @@ -13,7 +14,7 @@ describe('defaultConfig', () => {

it('formatCommitMessage', () => {
const version = '0.1.2';
expect(formatCommitMessage({ version })).toBe(`chore: release v0.1.2`);
expect(formatCommitMessage({ version })).toBe(`chore: prepare v0.1.2`);
});

describe('formatPullRequestMessage', () => {
Expand All @@ -29,15 +30,19 @@ describe('defaultConfig', () => {
toReleaseBranch: {},
};
const destinationBranch = 'master';
const message = formatPullRequestMessage({
repoURL,
baseBranch,
stagingBranch,
destinationBranch,
mergeStrategy,
currentVersion,
nextVersion,
});
const message = [
formatPullRequestTitle({ version: nextVersion }),
'',
formatPullRequestMessage({
repoURL,
baseBranch,
stagingBranch,
destinationBranch,
mergeStrategy,
currentVersion,
nextVersion,
}),
].join('\n');
expect(message).toMatchInlineSnapshot(`
"chore: release v0.1.1
Expand All @@ -62,7 +67,9 @@ describe('defaultConfig', () => {
},
};
const destinationBranch = 'release/stable';
expect(
const message = [
formatPullRequestTitle({ version: nextVersion }),
'',
formatPullRequestMessage({
repoURL,
baseBranch,
Expand All @@ -71,8 +78,9 @@ describe('defaultConfig', () => {
mergeStrategy,
currentVersion,
nextVersion,
})
).toMatchInlineSnapshot(`
}),
].join('\n');
expect(message).toMatchInlineSnapshot(`
"chore: release v0.1.1
## Release Summary
Expand Down Expand Up @@ -111,11 +119,11 @@ describe('defaultConfig', () => {
currentVersion,
currentBranch,
mergeStrategy,
formatCommitMessage,
formatPullRequestTitle,
});
expect(result).toMatchInlineSnapshot(`
"The commit message should have started with the following:
chore: release v0.1.2"
${commitMessage}"
`);
});

Expand All @@ -130,7 +138,7 @@ describe('defaultConfig', () => {
currentVersion,
currentBranch,
mergeStrategy,
formatCommitMessage,
formatPullRequestTitle,
});
expect(result).toBe(true);
});
Expand All @@ -148,7 +156,7 @@ describe('defaultConfig', () => {
currentVersion,
currentBranch,
mergeStrategy,
formatCommitMessage,
formatPullRequestTitle,
});
expect(result).toBe(true);
});
Expand All @@ -166,7 +174,7 @@ describe('defaultConfig', () => {
currentVersion,
currentBranch,
mergeStrategy,
formatCommitMessage,
formatPullRequestTitle,
});
expect(result).toMatchInlineSnapshot(
`"The current branch needs to be one of [master, release/legacy]"`
Expand Down
16 changes: 8 additions & 8 deletions packages/shipjs-lib/src/lib/config/defaultConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export default {
versionUpdated: ({ version, dir, exec }) => {},
beforeCommitChanges: ({ exec }) => {},
getStagingBranchName: ({ nextVersion }) => `releases/v${nextVersion}`,
formatCommitMessage: ({ version }) => `chore: release v${version}`,
formatCommitMessage: ({ version }) => `chore: prepare v${version}`,
formatPullRequestTitle: ({ version }) => `chore: release v${version}`,
formatPullRequestMessage: ({
repoURL,
baseBranch,
Expand All @@ -23,8 +24,6 @@ export default {
nextVersion,
}) => {
const lines = [
`chore: release v${nextVersion}`,
'',
'## Release Summary',
`- Version change: \`v${currentVersion}\` → \`v${nextVersion}\``,
`- Merge: \`${stagingBranch}\` → \`${destinationBranch}\``,
Expand All @@ -51,15 +50,16 @@ export default {
currentVersion,
currentBranch,
mergeStrategy,
formatCommitMessage,
formatPullRequestTitle,
}) => {
const correctCommitMessage =
commitMessage.trim() === formatCommitMessage({ version: currentVersion });
if (!correctCommitMessage) {
const correctCommitMessage = formatPullRequestTitle({
version: currentVersion,
});
if (commitMessage.trim() !== correctCommitMessage) {
return (
'The commit message should have started with the following:' +
'\n' +
`chore: release v${currentVersion}`
`${correctCommitMessage}`
);
}
if (
Expand Down
23 changes: 14 additions & 9 deletions packages/shipjs/src/step/prepare/createPullRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default ({
({ print, warning, run, exitProcess }) => {
const {
mergeStrategy,
formatPullRequestTitle,
formatPullRequestMessage,
pullRequestReviewer,
remote,
Expand Down Expand Up @@ -47,15 +48,19 @@ export default ({
exitProcess(0);
}
const repoURL = getRepoURL(remote, dir);
const message = formatPullRequestMessage({
repoURL,
baseBranch,
stagingBranch,
destinationBranch,
mergeStrategy,
currentVersion,
nextVersion,
});
const message = [
formatPullRequestTitle({ version: nextVersion }),
'',
formatPullRequestMessage({
repoURL,
baseBranch,
stagingBranch,
destinationBranch,
mergeStrategy,
currentVersion,
nextVersion,
}),
].join('\n');
const filePath = tempWrite.sync(message);
run(`git remote prune ${remote}`, dir, dryRun);
const createPullRequestCommand = [
Expand Down
4 changes: 2 additions & 2 deletions packages/shipjs/src/step/release/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default ({ config, dir }) =>
({ print, info, warning, exitProcess }) => {
const {
mergeStrategy,
formatCommitMessage,
formatPullRequestTitle,
shouldRelease,
monorepo,
} = config;
Expand All @@ -26,7 +26,7 @@ export default ({ config, dir }) =>
currentVersion,
currentBranch,
mergeStrategy,
formatCommitMessage,
formatPullRequestTitle,
});
if (validationResult !== true) {
print(warning('Skipping a release due to the following reason:'));
Expand Down

0 comments on commit f21e167

Please sign in to comment.