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

fix(changelog): fix previous version links #364

Merged
merged 14 commits into from Dec 10, 2023

Conversation

tvcsantos
Copy link
Contributor

@tvcsantos tvcsantos commented Dec 3, 2023

Description

In this PR the main goal was to simplify and fix the previous version links on all scenarios.

Motivation and Context

There were some scenarios where the previous version link was incorrect. For example

sh test-fixtures-locally.sh test-keep-a-changelog-links-current-arg --current

was producing the wrong link for the current tag, considering it as the only release.

How Has This Been Tested?

Created several extra tests for fixtures to address the several combinations and provide a strong test suite to avoid regressions further on the line.

Screenshots / Logs (if applicable)

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (no code change)
  • Refactor (refactoring production code)
  • Other

Checklist:

  • My code follows the code style of this project.
  • I have updated the documentation accordingly.
  • I have formatted the code with rustfmt.
  • I checked the lints with clippy.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@codecov-commenter
Copy link

codecov-commenter commented Dec 3, 2023

Codecov Report

Attention: 18 lines in your changes are missing coverage. Please review.

Comparison is base (ff2881b) 42.73% compared to head (c55537d) 41.98%.

Files Patch % Lines
git-cliff/src/lib.rs 0.00% 18 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #364      +/-   ##
==========================================
- Coverage   42.73%   41.98%   -0.75%     
==========================================
  Files          13       13              
  Lines         667      679      +12     
==========================================
  Hits          285      285              
- Misses        382      394      +12     
Flag Coverage Δ
unit-tests 41.98% <0.00%> (-0.75%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tvcsantos
Copy link
Contributor Author

Note the first pipeline run is on purpose, and follows a TDD approach, so that we can see the current failing scenarios.

@tvcsantos tvcsantos force-pushed the bugfix/fix-wrong-previous-version branch from b333bd8 to a6f36fc Compare December 3, 2023 10:03
@tvcsantos tvcsantos marked this pull request as ready for review December 3, 2023 11:44
@tvcsantos tvcsantos requested a review from orhun as a code owner December 3, 2023 11:44
@tvcsantos tvcsantos changed the title fix: fix previous version links fix(changelog): fix previous version links Dec 3, 2023
@orhun
Copy link
Owner

orhun commented Dec 3, 2023

Hey, thanks for creating this! 🐻

I didn't quite get which issue this PR is solving. Can you elaborate what's the problem before and what was your approach for solving it? Giving example input/output would be really helpful since it is kind of difficult to infer it from the code.

@tvcsantos
Copy link
Contributor Author

tvcsantos commented Dec 3, 2023

Hey, thanks for creating this! 🐻

I didn't quite get which issue this PR is solving. Can you elaborate what's the problem before and what was your approach for solving it? Giving example input/output would be really helpful since it is kind of difficult to infer it from the code.

Sure

With the current code before the PR with the following commits

GIT_COMMITTER_DATE="2021-01-23 01:23:45" git commit --allow-empty -m "feat: add feature 1"
git tag v0.1.0

GIT_COMMITTER_DATE="2021-01-24 01:23:46" git commit --allow-empty -m "feat: add feature 2"
git tag v0.2.0

Running

git-cliff --current

will result in a scenario where we won't have a previous version correctly set for v0.2.0.

(you can check this here https://github.com/orhun/git-cliff/actions/runs/7075903455/job/19258554935#step:3:569)

After this PR this is correctly fixed and the previous tag v0.1.0 is set.

(you can check it here https://github.com/orhun/git-cliff/actions/runs/7076145622/job/19259077413#step:3:573)

Ty, if you need something else ping me :)

@tvcsantos
Copy link
Contributor Author

tvcsantos commented Dec 3, 2023

Also a bit more in detail on the approach to solve the previous links in a uniform approach. The idea was the following:

  1. Find the first tag that is processed in the releases loop.
  2. Get the tag before this one, that will in the end always in any scenario be the previous of the first release.
  3. If no tag is ever processed then we are seeing commits after the last tag, hence previous is set to the last tag.

@tvcsantos
Copy link
Contributor Author

Btw just merged with latest changes on main. If you need I can rebase everything to avoid the merge commit (I guess that if you are using squash you don't need it, but please do tell me if it is required).

@orhun
Copy link
Owner

orhun commented Dec 4, 2023

I think there is a general confusion about the usage of --latest vs --current. I tried to explain the use-case for --current here: https://git-cliff.org/blog/git-cliff-0.5.0#--current

Also see #37 for the implementation details.

So in your case, if you want the previous release to be set, you can simply use --latest:

$ git cliff --context --latest | jq .[].previous

{
  "version": "v0.1.0",
  "commits": [],
  "commit_id": "0b5b2e2cb8c5e921e1c34b0ba60e442255d2a659",
  "timestamp": 0,
  "previous": null
}

I hope this helps, let me know! I think I can update the docs about clarifying the usage of --current / happily accept a PR about that! 🐻

@orhun
Copy link
Owner

orhun commented Dec 6, 2023

ping 🐻

@tvcsantos
Copy link
Contributor Author

tvcsantos commented Dec 6, 2023

Hey hey sorry for the delayed response.

Okay so let me use this example

suppose that I have 3 tags

v1.0.0
v2.0.0
v3.0.0

And now at this moment I'm on tag v3.0.0. What is the previous version of v3.0.0? It's v2.0.0

From what I got If I use git-cliff --current previous should not be set, is that it?!

@orhun
Copy link
Owner

orhun commented Dec 7, 2023

And now at this moment I'm on tag v3.0.0. What is the previous version of v3.0.0? It's v2.0.0
From what I got If I use git-cliff --current previous should not be set, is that it?!

I think there is a misunderstanding. What I'm saying is simply there is no need to use --current if you are already on the latest tag (v3.0.0), you should use --latest instead which correctly sets the previous version.

However, if you check out v2.0.0 for example and use --current, then previous version should be set of course. Is this what this PR is fixing?

git-cliff/src/lib.rs Outdated Show resolved Hide resolved
@tvcsantos
Copy link
Contributor Author

tvcsantos commented Dec 8, 2023

And now at this moment I'm on tag v3.0.0. What is the previous version of v3.0.0? It's v2.0.0
From what I got If I use git-cliff --current previous should not be set, is that it?!

I think there is a misunderstanding. What I'm saying is simply there is no need to use --current if you are already on the latest tag (v3.0.0), you should use --latest instead which correctly sets the previous version.

However, if you check out v2.0.0 for example and use --current, then previous version should be set of course. Is this what this PR is fixing?

Sorry for the delay on the response. I've tried to be thorough and did a in depth analysis to check that I didn't messed up anything. I've documented it here https://github.com/tvcsantos/git-cliff-test. And yes the PR is fixing the last issue you mentioned and with that also makes the code uniform for all cases, without requiring special ifs and the cumbersome check for tag lens.

Extracting the example from my test that is it:

diff --color -r results/1_4_0/at_2_0_0/context/current.json results/new/at_2_0_0/context/current.json
31c31
<       "version": null,
---
>       "version": "v1.0.0",
33c33
<       "commit_id": null,
---
>       "commit_id": "fa211a975e7c2a60053561e45660b0c57b847c72",
diff --color -r results/1_4_0/at_2_0_0/render/current.md results/new/at_2_0_0/render/current.md
1c1
< ## [2.0.0](https://github.com/tvcsantos/git-cliff-test/releases/tag/v2.0.0) - 2023-12-08
---
> ## [2.0.0](https://github.com/tvcsantos/git-cliff-test/compare/v1.0.0...v2.0.0) - 2023-12-08

@orhun
Copy link
Owner

orhun commented Dec 9, 2023

And yes the PR is fixing the last issue you mentioned and with that also makes the code uniform for all cases, without requiring special ifs and the cumbersome check for tag lens.

That's nice! I guess we can confirm that the behavior isn't changed from the fixture tests as well.

@orhun
Copy link
Owner

orhun commented Dec 9, 2023

There are some conflicts with main, can you fix those and address the review comments for proceeding with this? 🐻

@tvcsantos
Copy link
Contributor Author

All updated and merged with the last changes from main. Ty 💚

@tvcsantos
Copy link
Contributor Author

All seems good except for the failing "Continuous Integration / Links (pull_request)" that I think is not related. I've checked the failure and the links seem correct on the CHANGELOG 🤔

Copy link
Owner

@orhun orhun left a comment

Choose a reason for hiding this comment

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

Last comment 🐻

git-cliff/src/lib.rs Show resolved Hide resolved
Copy link
Owner

@orhun orhun 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 your contribution! 💖

@orhun orhun merged commit 44c93b7 into orhun:main Dec 10, 2023
39 of 40 checks passed
@tvcsantos tvcsantos deleted the bugfix/fix-wrong-previous-version branch December 10, 2023 17:10
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.

None yet

3 participants