Skip to content

Commit

Permalink
fix: removed stdout noise, adds env_logger
Browse files Browse the repository at this point in the history
  • Loading branch information
ldenefle committed Sep 19, 2019
1 parent e41a3f3 commit 4df0e9c
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 8 deletions.
90 changes: 90 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ edition = "2018"
git2 = "0.9"
semver = "0.9.0"
regex = "1.3.1"
log = "0.4.8"
env_logger = "0.6.2"
18 changes: 10 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[macro_use] extern crate log;
extern crate env_logger;

use git2::{Repository, Error};
use semver::{Version, SemVerError};
use std::cmp::Ordering;
Expand All @@ -21,7 +24,7 @@ fn main() {
};

let mut current_version = validate_tag(&last_tag).unwrap();
println!("Current version is {}", current_version);
info!("Current version is {}", current_version);

match get_bump_type(&repo, &last_tag) {
Ok(BumpType::Major) => current_version.increment_major(),
Expand All @@ -30,7 +33,8 @@ fn main() {
Err(e) => panic!("error: {}", e),
};

println!("Next version is {}", current_version);
info!("Next version is {}", current_version);
println!("{}", current_version);
}

fn get_bump_type(repo: &Repository, tag: &str) -> Result<BumpType, Error> {
Expand All @@ -42,7 +46,7 @@ fn get_bump_type(repo: &Repository, tag: &str) -> Result<BumpType, Error> {
let commit = repo.find_commit(rev?)?;
let message = commit.summary_bytes().unwrap_or_else(|| commit.message_bytes());
let message = String::from_utf8_lossy(message);
println!("Parsing {}", message);
debug!("Parsing {}", message);
if message.contains("BREAKING CHANGE") {
bump = BumpType::Major;
break
Expand All @@ -53,7 +57,7 @@ fn get_bump_type(repo: &Repository, tag: &str) -> Result<BumpType, Error> {
None => continue
};

println!("Commit type {}", commit_type);
debug!("Commit type {}", commit_type);
let commit_bump = match commit_type {
"feat" => BumpType::Minor,
"fix" => BumpType::Patch,
Expand All @@ -65,7 +69,7 @@ fn get_bump_type(repo: &Repository, tag: &str) -> Result<BumpType, Error> {
}

}
println!("Bumping with {:?}", bump);
info!("Bumping with {:?}", bump);
Ok(bump)
}

Expand All @@ -75,7 +79,7 @@ fn validate_tag(tag: &str) -> Result<semver::Version, SemVerError> {
Some(caps) => caps.get(1).map_or(tag, |m| m.as_str()),
None => tag,
};
println!("Validating tag {}", tag);
debug!("Validating tag {}", tag);
Version::parse(tag)
}

Expand All @@ -93,15 +97,13 @@ fn get_version_from_tag(repo: &Repository) -> Result<String, Error> {
else {
let max_tag = tags.iter().max_by(|x, y| {
if let (Some(x), Some(y)) = (x, y) {
println!("{} {}", x, y);
let v1 = validate_tag(x).unwrap();
let v2 = validate_tag(y).unwrap();
return v1.cmp(&v2);
}
Ordering::Greater
}).unwrap();

println!("Older tag is {}", max_tag.unwrap());
Ok(String::from(max_tag.unwrap()))
}
}
Expand Down

0 comments on commit 4df0e9c

Please sign in to comment.