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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(next_version): support configuration #1168

Merged
merged 18 commits into from
Dec 30, 2023

Conversation

orhun
Copy link
Sponsor Contributor

@orhun orhun commented Dec 29, 2023

This PR makes it possible to configure the next_version crate to customize the behavior for cases like orhun/git-cliff#343

e.g.:

let next_version = semver
	.next(
		vec![],
		Some(NextVersionConfig {
			uncontrolled_minor_bump: false,
			initial_major_increment: false,
		}),
	)
	.to_string();

A couple of points:

  • This is a breaking change due to the newly added config parameter to the next function. Let me know if you are fine with it or not and we can probably think of a way to make it non-breaking. I think it is fine though.
  • I'm not sure about the names of the config variables.
  • I tried this out with git-cliff directly and it seems to work as expected. However, I must say it was really hard to wrap my head around the conditions so I might have missed something. Please double check.

馃惢

@MarcoIeni
Copy link
Owner

I would prefer a non-breaking change. Let's keep the default behavior as it is.
Let's create another struct and use the builder pattern to configure it.
I will write an example now.

@orhun
Copy link
Sponsor Contributor Author

orhun commented Dec 29, 2023

Added tests.

@MarcoIeni
Copy link
Owner

struct VersionUpdater {
    pub uncontrolled_minor_bump: bool,
    pub initial_major_increment: bool,
}

impl VersionUpdater {
    // builder lite pattern https://matklad.github.io/2022/05/29/builder-lite.html
    fn with_uncontrolled_minor_bump(mut self, uncontrolled_minor_bump) -> Self { self.uncontrolled_minor_bump = uncontrolled_minor_bump; self }
    
    fn next(&self, version: Version, commits: I) -> Version { }
}

Then Version::next calls VersionUpdater with the default options.

@orhun
Copy link
Sponsor Contributor Author

orhun commented Dec 29, 2023

I didn't get it, do you wanna define another struct called VersionUpdater and have the configuration values there? How about config::NextVersionConfig?

@MarcoIeni
Copy link
Owner

do you wanna define another struct called VersionUpdater and have the configuration values there?

yes

How about config::NextVersionConfig?

Let's delete it. The VersionUpdater has the default configuration, which you can override with the builder pattern.

@orhun
Copy link
Sponsor Contributor Author

orhun commented Dec 29, 2023

Sorry, I'm not following. Do you want to achieve the following API?

let next_version = semver
	.next(
		vec![]
	)
    .with_uncontrolled_minor_bump(true)
    .with_initial_major_increment(true)
	.to_string();

@orhun
Copy link
Sponsor Contributor Author

orhun commented Dec 29, 2023

Or is it something like this?

VersionUpdater::new(semver)
    .with_uncontrolled_minor_bump(true)
    .with_initial_major_increment(true)
    .next(vec![])

@MarcoIeni
Copy link
Owner

VersionUpdater::new()
    .with_uncontrolled_minor_bump(true)
    .with_initial_major_increment(true)
    .next(semver, vec![])

I was thinking this what do you think?

@orhun
Copy link
Sponsor Contributor Author

orhun commented Dec 29, 2023

Sure, makes sense. Implemented in d3d3fb0

@orhun orhun requested a review from MarcoIeni December 29, 2023 23:05
@MarcoIeni MarcoIeni enabled auto-merge (squash) December 30, 2023 15:53
@MarcoIeni MarcoIeni merged commit f126c0e into MarcoIeni:main Dec 30, 2023
13 checks passed
This was referenced Dec 30, 2023
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

2 participants