Skip to content

Commit

Permalink
feat(changelog): filter max majors/minors/patches
Browse files Browse the repository at this point in the history
Adds the following options

        --max-majors <MAX_MAJORS>
            Only show this number of minor versions

        --max-minors <MAX_MINORS>
            Only print this number of major versions

        --max-patches <MAX_PATCHES>
            Only show this number of patch versions

Refs: #59
  • Loading branch information
hdevalke committed Sep 10, 2022
1 parent 51abd51 commit cb508c6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,18 @@ pub struct ChangelogCommand {
pub rev: String,
#[clap(short, long)]
pub skip_empty: bool,
/// Limits the number of version tags to add in the changelog
/// Limits the number of version tags to add in the changelog.
#[clap(short, long)]
pub max_versions: Option<usize>,
/// Only print this number of major versions.
#[clap(long, default_value_t=u64::MAX, hide_default_value=true)]
pub max_minors: u64,
/// Only show this number of minor versions.
#[clap(long, default_value_t=u64::MAX, hide_default_value=true)]
pub max_majors: u64,

This comment has been minimized.

Copy link
@ite-klass

ite-klass Sep 26, 2022

There is a mixup of major and minor here.

Comment major, var minor, and comment minor and var majors.

This comment has been minimized.

Copy link
@hdevalke

hdevalke Sep 26, 2022

Author Collaborator

The flags are correct, the documentation is wrong.
Will fix this: #83

/// Only show this number of patch versions.
#[clap(long, default_value_t=u64::MAX, hide_default_value=true)]
pub max_patches: u64,
/// Do not generate links. Overrides linkReferences and linkCompare in the config.
#[clap(short, long)]
pub no_links: bool,
Expand Down
11 changes: 11 additions & 0 deletions src/cmd/changelog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,24 @@ impl ChangelogCommand {
} else {
iter.chain(None)
};

let stop_at_major =
(last_version.version.0.major + 1).saturating_sub(self.max_majors);
let stop_at_minor =
(last_version.version.0.minor + 1).saturating_sub(self.max_minors);
let stop_at_patch =
(last_version.version.0.patch + 1).saturating_sub(self.max_patches);

let iter = iter
.chain(
helper
.versions_from(&last_version)
.into_iter()
.rev()
.take_while(|v| v.tag != rev_stop)
.take_while(|v| v.version.major() >= stop_at_major)
.take_while(|v| v.version.minor() >= stop_at_minor)
.take_while(|v| v.version.patch() >= stop_at_patch)
.map(|v| v.into()),
)
.chain(Some(Rev(rev_stop, None)))
Expand Down
4 changes: 4 additions & 0 deletions src/semver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ impl SemVer {
self.0.major
}

pub fn minor(&self) -> u64 {
self.0.minor
}

pub fn patch(&self) -> u64 {
self.0.patch
}
Expand Down

0 comments on commit cb508c6

Please sign in to comment.