Skip to content

Commit

Permalink
feat: determine semver version increments
Browse files Browse the repository at this point in the history
  • Loading branch information
justinrubek committed May 13, 2024
1 parent 6923be3 commit 1d16393
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 3 deletions.
127 changes: 127 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ anyhow = "1.0.59"
cargo-lock = "8.0.3"
cargo_metadata = "0.15.3"
cargo_toml = "0.15.2"
conventional_commit_parser = "0.9.4"
gix = "0.62.0"
memmap = "0.7.0"
parking_lot = "0.12.1"
Expand Down
17 changes: 15 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bomper::{
cargo::CargoReplacer, search::SearchReplacer, simple::SimpleReplacer, Replacer,
VersionReplacement,
},
versioning::get_latest_tag,
versioning::{determine_increment, get_latest_tag, increment_version, VersionIncrement},
};

pub struct App {
Expand All @@ -33,10 +33,23 @@ impl App {
}

impl App {
pub fn bump(&self, _opts: &Bump) -> Result<()> {
pub fn bump(&self, opts: &Bump) -> Result<()> {
let repo = gix::discover(".")?;

let tag = get_latest_tag(&repo)?;
// TODO: determine commits from tag to HEAD
let commits = vec![];

let increment = match &opts.options.version {
Some(version) => VersionIncrement::Manual(semver::Version::parse(version)?),
None if opts.options.automatic => determine_increment(commits),
None if opts.options.major => VersionIncrement::Major,
None if opts.options.minor => VersionIncrement::Minor,
None if opts.options.patch => VersionIncrement::Patch,
_ => unreachable!(),
};
let new_version = increment_version(tag.version, increment);
println!("New version: {}", new_version);
todo!()
}

Expand Down
20 changes: 19 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,22 @@ pub(crate) struct RawBump {
}

#[derive(clap::Args, Debug)]
pub(crate) struct Bump {}
pub(crate) struct Bump {
#[clap(flatten)]
pub options: BumpOptions,
}

#[derive(clap::Args, Debug)]
#[command(group = clap::ArgGroup::new("bump-type").required(true))]
pub(crate) struct BumpOptions {
#[arg(short, long, group = "bump-type")]
pub version: Option<String>,
#[arg(short, long, group = "bump-type")]
pub automatic: bool,
#[arg(short = 'M', long, group = "bump-type")]
pub major: bool,
#[arg(short, long, group = "bump-type")]
pub minor: bool,
#[arg(short, long, group = "bump-type")]
pub patch: bool,
}
34 changes: 34 additions & 0 deletions src/versioning.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::error::{Error, Result};
use conventional_commit_parser::commit::ConventionalCommit;

#[derive(Clone, Debug, Eq)]
pub struct Tag {
Expand All @@ -23,6 +24,14 @@ impl PartialEq for Tag {
}
}

#[derive(Debug)]
pub enum VersionIncrement {
Manual(semver::Version),
Major,
Minor,
Patch,
}

pub fn get_latest_tag(repo: &gix::Repository) -> Result<Tag> {
// TODO: should we only look for tags that are from the current branch?
// TODO: should we ignore tags that are not semver?
Expand All @@ -40,3 +49,28 @@ pub fn get_latest_tag(repo: &gix::Repository) -> Result<Tag> {

Ok(tag)
}

pub fn determine_increment(_commits: Vec<ConventionalCommit>) -> VersionIncrement {
todo!()
}

pub fn increment_version(
mut version: semver::Version,
increment: VersionIncrement,
) -> semver::Version {
match increment {
VersionIncrement::Manual(version) => version,
VersionIncrement::Major => {
version.major += 1;
version
}
VersionIncrement::Minor => {
version.minor += 1;
version
}
VersionIncrement::Patch => {
version.patch += 1;
version
}
}
}

0 comments on commit 1d16393

Please sign in to comment.