use git;
use report;
use commit;
use config;
mod exit {
pub const OK: i32 = 0;
pub const NOT_GIT: i32 = 1;
pub const NO_COMMITS: i32 = 2;
}
pub fn run(config: &config::Configuration, given_range: Option<Vec<String>>) -> i32 {
if git::in_git_repository().is_err() {
return exit::NOT_GIT;
}
config.categories.show("category", true);
config.scopes.show("scope", false);
let range = match given_range {
Some(vec) => vec,
None => {
let from = match git::last_tag() {
Ok(Some(tag)) => tag,
_ => {
warn!("No tags found, using HEAD^");
String::from("HEAD^")
}
};
let to = String::from("HEAD");
vec![format!("^{}", from), to]
}
};
info!("Using revision range {}", range.join(" "));
let hashes = git::commits_in_range(&range);
if hashes.is_err() {
error!("No commits in range. {:?}", hashes);
return exit::NO_COMMITS;
}
let mut commits = Vec::new();
for sha in hashes.unwrap() {
let message = git::get_commit_message(&sha);
if message.is_err() {
warn!("Commit {} could not be read. {:?}", sha, message);
continue;
}
let commit = commit::parse(&message.unwrap(), &config.report.date_format);
if config.is_interesting(&commit) {
commits.push(commit);
}
}
let report = report::generate(&commits, config);
println!("{}", report::render(&report, config));
exit::OK
}