-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Add --changelog-preset option to customize --conventional-commits output #1111
Conversation
01c0f71
to
0eef606
Compare
e667ab1
to
ed47f70
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few tweaks and we're good to go. Thanks!
test/PublishCommand.js
Outdated
cwd: testDir | ||
}); | ||
|
||
const execOptsWithChangelogPreset = (testDir) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only used a handful of places (compared to the execOpts
helper), just inline the expect.objectContaining()
call.
test/PublishCommand.js
Outdated
@@ -878,7 +884,9 @@ describe("PublishCommand", () => { | |||
|
|||
it("should use conventional-commits utility to guess version bump and generate CHANGELOG", () => { | |||
return run(testDir)( | |||
"--conventional-commits" | |||
"--conventional-commits", | |||
"--changelog-preset", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in a separate test case (it()
) in both modes to preserve the default cases. It only needs to assert one call, and none of the snapshots, of the existing --conventional-commits
tests.
diff --git a/test/PublishCommand.js b/test/PublishCommand.js
index c6d14eb8..ae0e8dde 100644
--- a/test/PublishCommand.js
+++ b/test/PublishCommand.js
@@ -905,6 +905,33 @@ describe("PublishCommand", () => {
});
});
});
+
+ it("accepts --changelog-preset option", () => {
+ return run(testDir)(
+ "--conventional-commits",
+ "--changelog-preset",
+ "foo-bar"
+ ).then(() => {
+ const name = "package-3";
+ const version = "3.0.0";
+ const location = path.join(testDir, "packages", name);
+
+ expect(ConventionalCommitUtilities.recommendIndependentVersion).toBeCalledWith(
+ expect.objectContaining({ name, version }),
+ expect.objectContaining({
+ cwd: testDir,
+ changelogPreset: "foo-bar",
+ })
+ );
+ expect(ConventionalCommitUtilities.updateIndependentChangelog).toBeCalledWith(
+ expect.objectContaining({ name, location }),
+ expect.objectContaining({
+ cwd: testDir,
+ changelogPreset: "foo-bar",
+ })
+ );
+ });
+ });
});
describe("fixed mode", () => {
@@ -960,6 +987,33 @@ describe("PublishCommand", () => {
);
});
});
+
+ it("accepts --changelog-preset option", () => {
+ return run(testDir)(
+ "--conventional-commits",
+ "--changelog-preset",
+ "baz-qux"
+ ).then(() => {
+ const name = "package-5";
+ const version = "1.0.0";
+ const location = path.join(testDir, "packages", name);
+
+ expect(ConventionalCommitUtilities.recommendFixedVersion).toBeCalledWith(
+ expect.objectContaining({ name, version, location }),
+ expect.objectContaining({
+ cwd: testDir,
+ changelogPreset: "baz-qux",
+ })
+ );
+ expect(ConventionalCommitUtilities.updateFixedChangelog).toBeCalledWith(
+ expect.objectContaining({ name, location }),
+ expect.objectContaining({
+ cwd: testDir,
+ changelogPreset: "baz-qux",
+ })
+ );
+ });
+ });
});
});
rejectCycles: this.options.rejectCycles | ||
}) | ||
: [this.packagesToPublish]; | ||
this.batchedPackagesToPublish = this.toposort |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this missing indent!
src/commands/PublishCommand.js
Outdated
@@ -419,7 +425,12 @@ export default class PublishCommand extends Command { | |||
version: update.package.version, | |||
location: update.package.location | |||
}; | |||
const recommendedVersion = recommendVersionFn(pkg, this.execOpts); | |||
|
|||
const changelogOptions = Object.assign({}, this.execOpts, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make this a lazy getter, so we only have to merge the options once:
diff --git a/src/commands/PublishCommand.js b/src/commands/PublishCommand.js
index 9edf8ad5..65222478 100644
--- a/src/commands/PublishCommand.js
+++ b/src/commands/PublishCommand.js
@@ -152,6 +152,20 @@ export default class PublishCommand extends Command {
});
}
+ get changelogOpts() {
+ if (!this._changelogOpts) {
+ const {
+ changelogPreset,
+ } = this.options;
+
+ this._changelogOpts = Object.assign({}, this.execOpts, {
+ changelogPreset,
+ });
+ }
+
+ return this._changelogOpts;
+ }
+
initialize(callback) {
this.gitRemote = this.options.gitRemote || "origin";
this.gitEnabled = !(this.options.canary || this.options.skipGit);
Then just pass this.changelogOpts
to the various functions.
@@ -574,18 +589,17 @@ export default class PublishCommand extends Command { | |||
|
|||
// we can now generate the Changelog, based on the | |||
// the updated version that we're about to release. | |||
if (this.options.conventionalCommits) { | |||
if (conventionalCommits) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this was bugging me. :)
3bfe55d
to
1a5026b
Compare
@evocateur, thanks for the feedback. I updated it :) |
4365b3c
to
d3cd95c
Compare
--changelog-preset
option to customize --conventional-commits
output
--changelog-preset
option to customize --conventional-commits
output
Thanks! |
@alan-agius4 This However this new and exciting option doesn't seem to work for me. I'm using lerna v2.9.0 (but I also tried with v2.6.0), yarn 1.3.2, node 8. I'm trying to run It makes me think that Should I add anything to my Thank you for your help Update: the result I'm referring to is that a |
The changelog preset in lerna 2.x is unfortunately not passed into the recommended-bump cli (choosing the version), only to the conventional-changelog cli (that generates the actual changelog output).
Lerna 3.0’s first alpha (available under the “next” dist-tag) passes the preset to both APIs programmatically, perhaps that might solve your issue?
… On Feb 22, 2018, at 18:50, Francesca Guiducci ***@***.***> wrote:
@alan-agius4 This --changelog-preset option to customize --conventional-commits is exactly what I need right now, since my organization hosts code on bitbucket as well (I know...).
However this new and exciting option doesn't seem to work for me. I'm using lerna v2.9.0 (but I also tried with v2.6.0), yarn 1.3.2, node 8.
I'm trying to run lerna publish this way: lerna publish --skip-npm --skip-git --conventional-commits --changelog-preset angular-bitbucket but I get the same result of lerna publish --skip-npm --skip-git --conventional-commits (same command, but without --changelog-preset option).
It makes me think that --changelog-preset gets completely ignored, also because I get the same result even if I do --changelog-preset foo-bar or passing any other invalid changelog preset.
Should I add anything to my package.json and/or install additional yarn dependencies?
Thank you
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Yes, you need to install this @evocateur the reason why the preset is only passed to the conventional-changelog is I’ll try to test the alpha soon, to see if thats still a problem |
Thank you both. I just updated my previous comment, clarifying what result I expect ( From your answers it looks like the bitbucket preset should correctly be passed to I tried installing https://www.npmjs.com/package/conventional-changelog-angular-bitbucket and then |
Hey @engfragui, Sorry that I didn't provide a lot of info earlier but I was getting on a plane. I tried things out a bit on one of my bitbuckets repos, and you need to do a couple of things.
"repository": "https://bitbucketsson.betsson.local/projects/WF/repos/obg.ngx.packages", // note, this should not end with `.git` and this is typically the url you use to browse the repo.
"bugs": {
"url": "https://jirasson.betsson.local/browse" // this can be a link to your Jira. If you don't have one the whole section can be omitted.
},
"publish": {
"changelogPreset": "angular-bitbucket",
"conventionalCommits": true
}, Alternatively, you can use the command line argument Note re invalid presets |
Thank you @alan-agius4, your comment was extremely helpful. In the end it was sufficient to add:
to the root level My mistake was that I didn't have Just for the sake of future readers, the few lines that need to be add to
( Thank you again for your help, I would buy you lunch for a week if I could. |
Thanks @alan-agius4! |
Glad to hear the issue is solved 😁 If yo are not using the ‘bugs’ field, indeed the root package.json sill suffice. |
How to use a custom preset? the |
@evocateur When I use the
But the following command ignore my preset:
The two lerna have the same version (2.9.0), |
Your preset is also installed globally?
… On Apr 6, 2018, at 04:14, Kévin Berthommier ***@***.***> wrote:
@evocateur When I use the changelogPreset option with the value @openagenda/oa, it's works with:
./node_modules/.bin/lerna publish
But the following command ignore my preset:
lerna publish
The two lerna have the same version (2.9.0), @openagenda/oa is replaced by @openagenda/conventional-changelog-oa by conventional-changelog but not found/used by my global lerna.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
No my preset is in my lerna monorepo, but I am in it (it's my current working directory). |
If I had to guess, it's a limitation of how Lerna 3 always uses the locally-installed version, even when called from a global installation. Also, |
I have a customized preset installed at root Upgrade to v3 beta version solves the problem. |
This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
…gular`
Description
Lerna uses
angular
as changelog preset, in my case my lerna repo is hosted on a privatebitbucket
server. For theangular
preset is built for usage withgithub
in my case I want to use some other preset such asangular-bitbucket
Motivation and Context
this issue has already been highlighted in #850
How Has This Been Tested?
Unit Tests
Types of changes
Checklist: