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): include the root commit when --latest is used with one tag #901

Merged
merged 5 commits into from
Oct 5, 2024

Conversation

rarescosma
Copy link
Contributor

Description, Motivation and Context

This is a proof of concept implementation for the fix of including the root commit of a repository when git-cliff is called with the --latest flag and only ONE tag exists in the repository.

Ranges passed to to Repository::commits are left-exclusive. This works well when we have two or more tags:

- sha0 (old_tag)
- sha1
- sha2
- sha3 (new_tag)

We'll get the range argument sha0..sha3, which will make the ::commits call capture only the sha1, sha2 and sha3 commits, which is both expected and great.

However, when dealing with a first release, and a single tag, we'd still like the root commit of the repository to be included in the report. Think of it as having a tag before the root commit itself.

In this case, with the current implementation of ::commits we get the range root_sha..single_tag_sha which, being left-exclusive, will exclude the root commit from the report.

My implementation addresses this by adding a flag to ::commits to tell it to include the root commit explicitly. When this boolean flag is present, we chop the range and include everything up to the ..single_tag_sha.

How Has This Been Tested?

Added both a unit test and adapted the test-latest-with-one-tag fixture for the integration tests.

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. NOTE: unsure where to update this, but would gladly do.
  • 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.

@rarescosma rarescosma requested a review from orhun as a code owner October 2, 2024 14:16
Copy link

welcome bot commented Oct 2, 2024

Thanks for opening this pull request! Please check out our contributing guidelines! ⛰️

@codecov-commenter
Copy link

codecov-commenter commented Oct 2, 2024

Codecov Report

Attention: Patch coverage is 33.33333% with 4 lines in your changes missing coverage. Please review.

Project coverage is 40.06%. Comparing base (f5c39a2) to head (b5ecc35).

Files with missing lines Patch % Lines
git-cliff/src/lib.rs 0.00% 3 Missing ⚠️
git-cliff-core/src/repo.rs 66.67% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #901      +/-   ##
==========================================
- Coverage   40.10%   40.06%   -0.03%     
==========================================
  Files          21       21              
  Lines        1671     1675       +4     
==========================================
+ Hits          670      671       +1     
- Misses       1001     1004       +3     
Flag Coverage Δ
unit-tests 40.06% <33.34%> (-0.03%) ⬇️

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.

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.

Looks good! The implementation could be simplified a bit :)

git-cliff-core/src/repo.rs Outdated Show resolved Hide resolved
git-cliff/src/lib.rs Outdated Show resolved Hide resolved
Use the fact that a range contains (or doesn't) contain
".." as a discriminant between the two cases:

- ".." means full (left-exclusive) range between two commits;
- no ".." means everything from the root commit (inclusive) to
the commit sha in the range
@rarescosma rarescosma force-pushed the latest-with-one-tag-root-commit branch from eda2fd9 to 06f96c2 Compare October 5, 2024 08:25
git-cliff-core/src/repo.rs Outdated Show resolved Hide resolved
@orhun
Copy link
Owner

orhun commented Oct 5, 2024

btw can you revert fa85e95

those are not in the scope of this PR

@rarescosma
Copy link
Contributor Author

Hi, I think the main linting configuration drifted a bit, so I included an extra commit to make the "pedantic" clippy lints pass. Also, not sure what's going on with the "Check NodeJS tarball" check. Everything else seems green. 🥳

@rarescosma
Copy link
Contributor Author

btw can you revert fa85e95

those are not in the scope of this PR

Sure, np

@rarescosma rarescosma force-pushed the latest-with-one-tag-root-commit branch from e625a81 to 90e0202 Compare October 5, 2024 08:47
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!

@orhun orhun changed the title --latest with one tag should include root commit fix(changelog): include the root commit when --latest is used with one tag Oct 5, 2024
@orhun orhun merged commit 508a97e into orhun:main Oct 5, 2024
61 of 63 checks passed
Copy link

welcome bot commented Oct 5, 2024

Congrats on merging your first pull request! ⛰️

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.

3 participants