-
-
Notifications
You must be signed in to change notification settings - Fork 256
fix: fixing bug identified in [Issue #1080](https://github.com/orhun/… #1227
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
base: main
Are you sure you want to change the base?
Conversation
|
Thanks for opening this pull request! Please check out our contributing guidelines! ⛰️ |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1227 +/- ##
==========================================
+ Coverage 41.59% 42.41% +0.82%
==========================================
Files 22 22
Lines 1919 1948 +29
==========================================
+ Hits 798 826 +28
- Misses 1121 1122 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks for the PR! I might need to get myself up-to-date with that issue again to understand the changes here so give me some time. In the meantime, there seems to be unrelated formatting changes in this PR. Can you run |
|
Ok, took a few attempts to get my toolchain setup right apparently, but I think I have all the changes in. Let me know if you see any further updates needed. |
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 looking pretty good! I had some questions and suggestions.
Also, can you please adjust the PR title accordingly? It should mention what is being added/changed in this PR instead of a general message like the current one.
| /// This test simulates the scenario described in GitHub issue #1080 where v0.10.0 | ||
| /// was incorrectly considered "less than" v0.9.0 due to alphabetical sorting. |
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 test simulates the scenario described in GitHub issue #1080 where v0.10.0 | |
| /// was incorrectly considered "less than" v0.9.0 due to alphabetical sorting. | |
| /// This test simulates the scenario described in GitHub issue [#1080] where v0.10.0 | |
| /// was incorrectly considered "less than" v0.9.0 due to alphabetical sorting. | |
| /// | |
| /// [#1080]: https://github.com/orhun/git-cliff/issues/1080 |
| Ordering::Less | ||
| ); | ||
|
|
||
| // Test pre-release vs release (lines 574-575) |
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.
Pointing out to lines that might change in the future does not make sense, can you remove them and reference to the function instead?
| // Test the specific case from the GitHub issue | ||
| assert_eq!( | ||
| semantic_version_compare("v0.9.0", "v0.10.0"), | ||
| Ordering::Less | ||
| ); | ||
| assert_eq!( | ||
| semantic_version_compare("v0.10.0", "v0.11.0"), | ||
| Ordering::Less | ||
| ); |
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.
It's not clear which GitHub issue we are referring to here, it should be linked or the comment should be made more clear
| if time_cmp == std::cmp::Ordering::Equal { | ||
| // When commit times are equal, sort by semantic version | ||
| semantic_version_compare(&a.1.name, &b.1.name) |
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.
I'm not sure if I understood how this fixes #1080... In that issue we didn't talk about commit times being equal etc. but we are doing a a check here.
Can you explain it further?
| /// This function attempts to parse version strings and compare them semantically | ||
| /// rather than alphabetically. It handles common version formats like: | ||
| /// - v1.2.3 | ||
| /// - 1.2.3 | ||
| /// - v1.2.3-alpha.1 |
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.
nit:
| /// This function attempts to parse version strings and compare them semantically | |
| /// rather than alphabetically. It handles common version formats like: | |
| /// - v1.2.3 | |
| /// - 1.2.3 | |
| /// - v1.2.3-alpha.1 | |
| /// This function attempts to parse version strings and compare them semantically | |
| /// rather than alphabetically. It handles common version formats like: | |
| /// | |
| /// - v1.2.3 | |
| /// - 1.2.3 | |
| /// - v1.2.3-alpha.1 |
| use std::cmp::Ordering; | ||
|
|
||
| // Helper function to extract version parts and pre-release info | ||
| let parse_version = |version: &str| -> Option<(Vec<u64>, Option<String>)> { |
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.
Hmm, Option<(Vec<u64>, Option<String>)> is a bit complex. Do you think defining an inner struct would make the code better in terms of readability? 🤔
| (Some(_), None) => Ordering::Less, // pre-release < release | ||
| (None, Some(_)) => Ordering::Greater, // release > pre-release | ||
| (Some(pre_a), Some(pre_b)) => pre_a.cmp(&pre_b), /* alphabetical for | ||
| * pre-release */ |
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.
The comments seem a bit off here. Maybe use this format:
// pre-release < release
(Some(_), None) => Ordering::Less,
etc.
…git-cliff/issues/1080)
Description
This is an attempt to fix the issue described in Issue #1080.
Motivation and Context
When multiple tags are included in the next release and the tags jump up in digit size, ex moving from 1.9.0 to 1.10.0, the "highest" version was being identified as 1.9.0 due to the tags being sorted alphabetically instead of by the actual version. This causes the next version to be misidentified as 1.10.0 instead of 1.11.0.
The
semantic_version_comparefunction attempts to sort by version. If it fails, it should fall back to alphabetical sort (see like 589). All my changes were torepo.rs. The other files are the results of me running thecargo +nightly fmt. I am fairly new to the Rust toolchain so if that's not correct and you need me to revert those changes I can.This is an attempt to fix Issue #1080.
How Has This Been Tested?
v0.9.0,v0.10.0andv0.11.0on a temporary repo. The test breaks because it sorted thev0.9.0tag would sort to the end of the vector. Once I could see it happening in a repeatable test I...v0.9.0,v0.10.0thenv0.11.0.semantic_version_comparefunction to have a complete set of tests. It tries to test some "edge" cases, like ensuringv1.0is less thanv1.0.0and how to handle things like alpha releases and the fall-back to alpha-sorting when the comparison is between 2 non- Semver strings.Types of Changes
Checklist: