Skip to content

refactor: initialize config structs with default values - #1090

Merged
orhun merged 4 commits into
orhun:mainfrom
Cyclonit:feat/initialize_config_structs_with_default_values
Mar 27, 2025
Merged

refactor: initialize config structs with default values#1090
orhun merged 4 commits into
orhun:mainfrom
Cyclonit:feat/initialize_config_structs_with_default_values

Conversation

@Cyclonit

@Cyclonit Cyclonit commented Mar 12, 2025

Copy link
Copy Markdown
Contributor

Description

This change uses the embedded configuration to initialize configuration options with default values whenever possible. This moves the concern of defining default values into the embedded config and reduces complexity when using the configuration.

Motivation and Context

Closes #1087.

Using the embedded config.toml to initialize the config structs allows us to use well defined defaults in the code where previously we had to repeatedly unwrap Option<> in lots of places. The embedded config.toml was chosen because it is the config used by git-cliff itself and should follow all of our best practices.

This change also allowed for minimizing the fixtures' config files. Only values that are different to the defaults remain. Thus fixtures are less cluttered and easier to maintain.

How Has This Been Tested?

Regression testing was done using the existing fixtures and integration tests.

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

codecov-commenter commented Mar 12, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 44.18605% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 41.58%. Comparing base (cdce20f) to head (e61a31f).
⚠️ Report is 197 commits behind head on main.

Files with missing lines Patch % Lines
git-cliff/src/lib.rs 0.00% 19 Missing ⚠️
git-cliff-core/src/config.rs 50.00% 4 Missing ⚠️
git-cliff-core/src/changelog.rs 83.34% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1090      +/-   ##
==========================================
+ Coverage   41.27%   41.58%   +0.32%     
==========================================
  Files          21       21              
  Lines        1820     1816       -4     
==========================================
+ Hits          751      755       +4     
+ Misses       1069     1061       -8     
Flag Coverage Δ
unit-tests 41.58% <44.19%> (+0.32%) ⬆️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Cyclonit
Cyclonit force-pushed the feat/initialize_config_structs_with_default_values branch 14 times, most recently from 2181485 to 27896eb Compare March 13, 2025 09:33
@Cyclonit
Cyclonit marked this pull request as ready for review March 13, 2025 11:26
@Cyclonit
Cyclonit requested a review from orhun as a code owner March 13, 2025 11:26
@Cyclonit Cyclonit changed the title refactor: default to embeded config refactor: initialize config structs with default values Mar 13, 2025

@orhun orhun left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Nice! The config loading is pretty convenient, I added a comment about that.

@orhun

orhun commented Mar 23, 2025

Copy link
Copy Markdown
Owner

Uh-oh, fixtures seems to be broken 😵

@Cyclonit
Cyclonit force-pushed the feat/initialize_config_structs_with_default_values branch 10 times, most recently from 5bde6fb to 97020d8 Compare March 23, 2025 19:27
@Cyclonit
Cyclonit force-pushed the feat/initialize_config_structs_with_default_values branch from 97020d8 to dfe9712 Compare March 23, 2025 19:40
@Cyclonit
Cyclonit force-pushed the feat/initialize_config_structs_with_default_values branch 6 times, most recently from 8cc2acd to a29045d Compare March 25, 2025 16:46

@orhun orhun left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Just to double check: the fixture configs has been trimmed because we now have those values in the default config, right?

Comment thread .github/fixtures/test-fixtures-locally.sh Outdated
Comment thread .github/fixtures/test-bitbucket-integration/expected.md
Comment thread .github/fixtures/test-commit-preprocessors/expected.md
@Cyclonit

Cyclonit commented Mar 26, 2025

Copy link
Copy Markdown
Contributor Author

Just to double check: the fixture configs has been trimmed because we now have those values in the default config, right?

Yes exactly. Imho duplicating default values over and over again is bad practice because it makes it difficult to find differences.

@Cyclonit
Cyclonit force-pushed the feat/initialize_config_structs_with_default_values branch from a29045d to e61a31f Compare March 27, 2025 05:36

@orhun orhun left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Awesome, thanks!

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.

Initialize config structs with default values

3 participants