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

feat(sub-directory): add -s, --sub-directory option #32

Closed
wants to merge 11 commits into from

Conversation

altJake
Copy link
Contributor

@altJake altJake commented Dec 7, 2017

Add an option to generate a changelog for a specific sub-directory in the repository, using the git log -- <path> command ability.

Also add a reconciling/normalizing of the input/output file path to handle the read/write in a sub-directory, when it is given.

closes #13

@robinjoseph08 robinjoseph08 self-assigned this Dec 13, 2017
Copy link
Contributor

@robinjoseph08 robinjoseph08 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing, @altJake! Sorry for the delay in the review, but hopefully we can get this merged soon. I left some comments, but if you have any questions, feel free to ask!

lib/file.js Outdated

file = Path.normalize(file);

if (Path.dirname(file) === '.') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for not replying on the issue earlier, but I think the desired behavior of how -f and -s will work together will be to always have it be relative from the subdirectory. I think that will give the most options for where the file should go. For example, in the current implementation, I'm not sure there's any way to write the file to root directory of the repo (I tried CHANGELOG.md, ../CHANGELOG.md, ./../CHANGELOG.md).

And since this is a completely new feature, we don't have to worry about backwards compatibility as long as we don't affect the current functionality. So we should pick what makes the most sense and provides the greatest control.

lib/file.js Outdated
* @returns {Promise}
*/
exports.normalizeFilePath = function (file, subDirectory) {
return Bluebird.resolve()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like anything in this function is actually asynchronous so you don't have to make it return a promise. It should make the implementation a bit simpler.

lib/file.js Outdated
@@ -2,6 +2,7 @@

var Bluebird = require('bluebird');
var Fs = Bluebird.promisifyAll(require('fs'));
var Path = Bluebird.promisifyAll(require('path'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not using any async functions in path so we don't have to promisify it.

lib/git.js Outdated
@@ -33,8 +33,14 @@ exports.getCommits = function (options) {
revisions = tag ? tag + '..HEAD' : '';
}

var gitLogCommand = 'git log -E --format=' + FORMAT + ' ' + revisions;

if (options.subDirectory) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like if you do git log -- ., it behaves the same way as git log, so it might simplify the logic if you make the default value of subDirectory . in lib/cli.js.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The combination of using default value for 'subDirectory' and discarding all the explicit path handling - make this PR way simpler 😅
Liked it way better though 👍

@@ -7,6 +7,7 @@ var Sinon = require('sinon');

var File = require('../lib/file');

var DEFAULT_FILE = './CHANGELOG.md';
var NONEXISTENT = Path.resolve(__dirname, '../fake-file.txt');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you align the equal signs within this block of vars?

lib/cli.js Outdated
@@ -17,4 +17,5 @@ module.exports = CLI
.option('-t, --tag <range>', 'generate from specific tag or range (e.g. v1.2.3 or v1.2.3..v1.2.4)')
.option('-x, --exclude <types>', 'exclude selected commit types (comma separated)', list)
.option('-f, --file [file]', 'file to write to, defaults to ./CHANGELOG.md, use - for stdout', './CHANGELOG.md')
.option('-u, --repo-url [url]', 'specify the repo URL for commit links, defaults to checking the package.json');
.option('-u, --repo-url [url]', 'specify the repo URL for commit links, defaults to checking the package.json')
.option('-s, --sub-directory <path>', 'specify an explicit relatvie path to a sub-directory');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make the description specify a path to be passed into git log? And then maybe add a subsection within ## Usage in the README titled ### Sub-directory under ### Recommended to explain the nuances with how --file is relative from --sub-directory since it is a bit nuanced?

README.md Outdated
@@ -62,6 +62,7 @@ $ changelog -h
-x, --exclude <types> exclude selected commit types (comma separated)
-f, --file [file] file to write to, defaults to ./CHANGELOG.md, use - for stdout
-u, --repo-url [url] specify the repo URL for commit links, defaults to checking the package.json
-s, --sub-directory <path> specify an explicit relatvie path to a sub-directory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the alignment here is also a bit off. Can you generate the help and just replace the whole help text to make sure it's exactly as it would be outputted?

@altJake
Copy link
Contributor Author

altJake commented Dec 17, 2017

Hope it looks better and cleaner now.
@robinjoseph08 let me know if you feel like re-wording or an example are needed for the new section of the usage

@altJake
Copy link
Contributor Author

altJake commented Jan 29, 2018

Hi @robinjoseph08 !

Just bump it, probably has been forgotten (also by me)
Looking forward to hear from you

Copy link
Contributor

@robinjoseph08 robinjoseph08 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @altJake! Yeah, looks like it slipped through the cracks, sorry again about that.

It's all looking really good, the last thing we need to make sure we account for is when using --sub-directory and --file - at the same time. Should be easy enough to fix by deferring the joining of the sub-directory and the file paths.

Let me know if you have any questions! Thanks again for your help!


var CLI = require('../lib/cli');
var Changelog = require('../lib');
var File = require('../lib/file');

CLI.parse(process.argv);

var filePath = Path.join(CLI.subDirectory, CLI.file);
Copy link
Contributor

@robinjoseph08 robinjoseph08 Feb 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'm not sure if we can join the paths together here since some people might be passing in - for stdout. We might need to pass CLI.subDirectory through to the two functions. We also should probably be checking for - explicitly in File.readIfExists, but you don't have to do that in this PR.

@robinjoseph08
Copy link
Contributor

@altJake bump!

1 similar comment
@dmlittle
Copy link
Contributor

dmlittle commented May 9, 2018

@altJake bump!

@dmlittle
Copy link
Contributor

Hey @altJake, I'll be closing this PR as there hasn't been any activity for a while. If you want to revisit this issue in the future feel free to comment and we can re-open this PR.

@dmlittle dmlittle closed this Jul 13, 2018
@picheli20 picheli20 mentioned this pull request Nov 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Add option for filtering commits by path
3 participants