8000 feat: add `--sort [TYPE]` flag by sanderblue · Pull Request #78 · git-chglog/git-chglog · GitHub
[go: up one dir, main page]

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: add --sort [TYPE] flag #78

Merged
merged 2 commits into from
Mar 29, 2021

Conversation

sanderblue
Copy link
Contributor
@sanderblue sanderblue commented Jul 29, 2020

What does this do / why do we need it?

First off, thank you for creating an awesome tool. We're using git-chglog in many open source repositories at New Relic and we would like to continue doing so.

The PR introduces sorting tags by version number instead of sorting by the date of tag creation. Users can still sort by date by passing the flag --sort-by-date. Using --sort-by-date will perform the original behavior of the git-chglog command.

Per request to integrate with the latest configuration updates from #124 (nice addition @ldelossa 🙂 ), this pull request introduces sorting tags by semver version using the --sort [TYPE] flag where TYPE is either date or semver. Sort by date is still default behavior.

Previous reasoning behind the idea:
Since we support multiple major release branches of a repository, our CHANGELOG gets mangled when we release v1.x and then release an update for v2.x. Essentially the v1.x commits get combined with the v2.x commits in the CHANGELOG and requires manual editing that can be cumbersome with every new release we create. Sorting the tags by version number fixes this issue.

Give it a test drive:

make build

This will build the binaries for supported architectures located in the ./bin directory- e.g. ./bin/{arch}/git-chglog (replace {arch} with darwin, etc)

./bin/darwin/git-chglog

How this PR fixes the problem?

Sorting the tags by version number ensures git-chglog selects the correct previous tag to compare to the new tag.

Current hypothetical ordering for a CHANGELOG might look like this:

v2.1.0 <-- will contain commit messages from v1.1.1 due to how git-chglog sorts from tag timestamp
v1.1.1 <-- patch release for v1.x (this causes an issue for all v2.x release after this one)
v2.0.0
v1.1.0
v1.0.0

This is because the diff that's being checked is github.com/user/repo/compare/v1.1.1...v2.1.0, but we need this to be github.com/user/repo/compare/v2.0.0...v2.1.0 for the latest release in the example above.

This PR introduces ordering for a CHANGELOG that looks like this:

v2.1.0 
v2.0.0
v1.1.1 
v1.1.0
v1.0.0

This ensures the correct previous tag is selected for comparison to create the CHANGELOG entries.

What should your reviewer look out for in this PR?

This PR migrates this project from dep to Go modules. The vendor directory is no longer needed.

Check lists

  • Test passed
  • Coding style (indentation, etc)

Which issue(s) does this PR fix?

Resolves: #74
Resolves: #112

@sanderblue sanderblue changed the title feat(tag_reader): sort by tag version feat: sort by tag version by default, add --sort-by-date flag for previous functionality Jul 29, 2020
@sanderblue sanderblue force-pushed the feat/sort-by-version branch 3 times, most recently from 10acacd to cf0ecc6 Compare July 29, 2020 19:40
@ctrombley
Copy link

👍

Copy link
@zlesnr zlesnr left a comment

Choose a reason for hiding this comment

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

Nice!

@ghostsquad
Copy link
Collaborator

yes please!

@ghostsquad
Copy link
Collaborator

@sanderblue can you rebase this so we can see if we can get the tests to run & pass? We have a few new maintainers/contributors to the project, so now is the time to kick this into high gear.

This is technically not backwards compatible, so maybe we should wait to merge this and add --sort-by-version flag in addition, and a warning that in a future version, --sort-by-version will be the default?

@sanderblue
Copy link
Contributor Author

@ghostsquad good call on the flag idea. I should be able to address this relatively soon - hopefully within the next couple days.

@sanderblue sanderblue force-pushed the feat/sort-by-version branch from cf0ecc6 to 2bc7aff Compare January 23, 2021 16:36
@coveralls
Copy link
coveralls commented Jan 23, 2021

Pull Request Test Coverage Report for Build 695618253

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 11 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.04%) to 76.76%

Files with Coverage Reduction New Missed Lines %
cmd/git-chglog/main.go 11 73.0%
Totals Coverage Status
Change from base Build 688745689: 0.04%
Covered Lines: 1843
Relevant Lines: 2401

💛 - Coveralls

@sanderblue sanderblue force-pushed the feat/sort-by-version branch from 2bc7aff to 3a3564a Compare January 23, 2021 18:21
@khos2ow
Copy link
Collaborator
khos2ow commented Jan 23, 2021

This sounds really cool. To be frank I haven't actually looked at the changeset yet, but wanted to suggest converting the new flag from bool to string, i.e. using --sort TYPE (defaults to date if not present). Then we will have all the flexibility to add more sort types in the future without polluting the flags count.

@sanderblue sanderblue force-pushed the feat/sort-by-version branch from 3a3564a to c2eb966 Compare January 23, 2021 19:12
@sanderblue sanderblue changed the title feat: sort by tag version by default, add --sort-by-date flag for previous functionality feat: add --sort-by-version flag Jan 30, 2021
@sanderblue
Copy link
Contributor Author

Hi @khos2ow, thanks for the feedback, but that kind of feels like premature optimization at this stage and that would also add additional code complexity because some form of validation would be needed to ensure a valid type string was passed which could grow over time. Plus right now there are only two ways to sort and I'm not sure if there would be any other ways to sort that make sense here other than maybe ascending or descending (which could be by date or by version as well). That being said, if there's a use case I'm missing I'm all ears (or eyes in this case) 🙂

@ghostsquad
Copy link
Collaborator
ghostsquad commented Feb 7, 2021

I don't think it's that far fetched to provide a sort-by which takes a field/type or something along those lines. It seems fairly common.

Looking at other tools, it looks like gsort has a --sort flag that takes types but ALSO provides long & short sort-specific flags:

https://www.gnu.org/software/coreutils/manual/html_node/sort-invocation.html

‘-g’
‘--general-numeric-sort’
‘--sort=general-numeric’


‘-h’
‘--human-numeric-sort’
‘--sort=human-numeric’

‘-M’
‘--month-sort’
‘--sort=month’

‘-n’
‘--numeric-sort’
‘--sort=numeric’

‘-R’
‘--random-sort’
‘--sort=random’

@trim21
Copy link
Contributor
trim21 commented Mar 3, 2021

Is it possible to add a config option at the same time?

@zlesnr
Copy link
zlesnr commented Mar 4, 2021

I think I agree with @sanderblue that this feels like premature optimization to include a sort string right now, but perhaps others could change that after merge? What other sorting methods would we implement other than the default behavior, or what this flag introduces? Also, 10 files changed, 3 commits, and the contributor included tests. This seems like a great addition to me. If other folks want a config option, perhaps that can be included after merge also.

@clok
Copy link
Collaborator
clok commented Mar 4, 2021

Just adding my take that the current work is great and the call outs a sort type and config sound like great iterations to extend this feature.

Copy link
Collaborator
@clok clok 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 the work here! Like the sort by feature. Can you please rebase from master to pick up the changes to urfave/cli/v2. You will need to address one compatibility issue with the new CLI flag.

Also, I left a comment concerning the changes to the Makefile.

Awesome work!

@@ -126,6 +126,12 @@ func CreateApp(actionFunc cli.ActionFunc) *cli.App {
Usage: "Regular expression of tag filter. Is specified, only matched tags will be picked",
},

// sort-by-version
cli.BoolFlag{
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will be needed after the rebase with current master and the bump to urfave/cli/v2

Suggested change
cli.BoolFlag{
&cli.BoolFlag{

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated. Should be good to go now 😎

Copy link
Contributor Author

Choose a reason for hiding this comment

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

8000

Thanks for the review as well!

Makefile Outdated
@@ -20,3 +20,35 @@ install:
.PHONY: changelog
changelog:
@git-chglog --next-tag $(tag) $(tag)


.PHONY: compile
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can these changes be moved out to a separate PR please? While potentially useful, they are not related to the addition of the sort by feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing, no worries :)

@sanderblue sanderblue force-pushed the feat/sort-by-version branch from 038d6cb to 346111a Compare March 7, 2021 22:19
@sanderblue sanderblue requested a review from clok March 8, 2021 03:17
@sanderblue
Copy link
Contributor Author

@clok I've updated the PR per latest feedback.

Thanks for all the additional reviews and feedback as well 🙂

Copy link
Collaborator
@clok clok 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 the follow up. Dropped an in-line comment with a link to #112 that we can use to follow up with a more robust sort flag.

Appreciate the follow through and contribution.

tag_reader.go Outdated
Comment on lines 78 to 83
if r.sortByVersion {
err := r.sortTagsByVersion(tags)
if err != nil {
return nil, err
}
} else {
r.sortTagsByDate(tags)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Noting the addition of #112 to follow up with the support for a more robust sort feature.

@clok
Copy link
Collaborator
clok commented Mar 9, 2021

@mavogel @khos2ow can you take a look at this PR? I think it's ready to go.

Copy link
Collaborator
@khos2ow khos2ow left a comment

Choose a reason for hiding this comment

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

Thank you @sanderblue, LGTM!

I think you need to rebase one final time on master to be able to proceed with this.

@clok clok mentioned this pull request Mar 18, 2021
2 tasks
Copy link
Collaborator
@clok clok left a comment

Choose a reason for hiding this comment

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

@sanderblue we have merged #124 which provides this feature via a configuration option. This has been released in v0.12.0 as well.

While the work in that PR overlaps with the work you have done in this feature PR, we do see it as a potentially complementary feature. We would like to add the CLI flag --sort that can provide the functionality of the config value as well.

Would you like to rebase your feature branch and integrate the functionality from #124 with the CLI flag work you have done? Or would you like to have one us take on the work of introducing the --sort flag?

No pressure either way. We wanted to ask you first as you have put in this contribution and we appreciate your work. Thanks again!

@sanderblue
Copy link
Contributor Author

@clok sounds good. I should be able to get this updated within the next day or so once I wrap up a couple things with work.

@clok
Copy link
Collaborator
clok commented Mar 25, 2021

@sanderblue thats great! Totally understand the delay. No worries there. Don't hesitate to reach out if you have questions or feedback. This work will resolve #112 as well. Thanks!

@sanderblue
Copy link
Contributor Author

I've rebased and will be working to get this working soon with the latest updates.

@sanderblue sanderblue force-pushed the feat/sort-by-version branch 4 times, most recently from c71fd01 to 0ad8bbb Compare March 26, 2021 23:52
@sanderblue sanderblue force-pushed the feat/sort-by-version branch from 0ad8bbb to 2f00715 Compare March 26, 2021 23:54
@sanderblue sanderblue changed the title feat: add --sort-by-version flag feat: add --sort [TYPE] flag Mar 26, 2021
@sanderblue
Copy link
Contributor Author

@clok @khos2ow I have rebased and updated the code to use --sort [TYPE] as requested and it's ready for your review. This really slimmed down the pull request as well. Thanks for the patience 😎

@sanderblue sanderblue requested a review from clok March 28, 2021 00:48
Copy link
Collaborator
@clok clok left a comment

Choose a reason for hiding this comment

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

This looks great! Thanks again for keeping on this, following up on the feedback and updating after the config based PR came through. 🥇

If you could update the README with the updated CLI help output in the "CLI Usage" section, that would be awesome. Just helps us keep the repo up-to-date.

Leaving an "Approve" on this as I don't see it as critically blocking and I am happy to pick up that edit in the end.

@@ -308,7 +308,7 @@ func (config *Config) Convert(ctx *CLIContext) *chglog.Config {
Options: &chglog.Options{
NextTag: ctx.NextTag,
TagFilterPattern: ctx.TagFilterPattern,
Sort: opts.Sort,
Sort: orValue(ctx.Sort, opts.Sort),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice. This was what I was looking for. 😀

@sanderblue
Copy link
Contributor Author

@clok updated the CLI usage section with the new --sort flag help output.

@khos2ow khos2ow self-requested a review March 28, 2021 20:54
@clok clok merged commit e523fd4 into git-chglog:master Mar 29, 2021
@clok
Copy link
Collaborator
clok commented Mar 29, 2021

This has been releases as a part of the v0.14.0 release. Thank you for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Idea: --sort [TYPE] flag support git-chglog getting changelog message from old tags
8 participants
0