Skip to content

Commit

Permalink
refactor: refactor verify to get current user signature
Browse files Browse the repository at this point in the history
  • Loading branch information
oknozor committed Sep 12, 2020
1 parent a2b7098 commit dad15d1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/bin/cog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ fn main() -> Result<()> {
let subcommand = matches.subcommand_matches(VERIFY).unwrap();
let message = subcommand.value_of("message").unwrap();

match CocoGitto::verify(message) {
match cocogitto.verify(message) {
Ok(()) => exit(0),
Err(err) => {
eprintln!("{}", err);
Expand Down
2 changes: 1 addition & 1 deletion src/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ pub struct Hook {
pub command: String,
}

// TODO
impl Hook {
pub(crate) fn run(&self) -> Result<()> {
todo!();
let command_display = format!("`{}`", &self.command.green());
println!("Running pre-version hook : {}", command_display);

Expand Down
31 changes: 19 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ impl CocoGitto {
let changelog_path = settings
.changelog_path
.unwrap_or_else(|| PathBuf::from("CHANGELOG.md"));

Ok(CocoGitto {
repository,
changelog_path,
Expand Down Expand Up @@ -180,18 +181,24 @@ impl CocoGitto {
Ok(logs)
}

pub fn verify(message: &str) -> Result<()> {
Commit::parse_commit_message(message).map(|commit_message| {
println!(
"{}",
Commit {
shorthand: "not committed".to_string(),
message: commit_message,
author: " ".to_string(),
date: Utc::now().naive_utc(),
}
)
})
pub fn verify(&self, message: &str) -> Result<()> {
let commit = Commit::parse_commit_message(message);

match commit {
Ok(message) => {
println!(
"{}",
Commit {
shorthand: "not committed".to_string(),
message,
author: self.repository.get_author()?,
date: Utc::now().naive_utc(),
}
);
Ok(())
}
Err(err) => Err(err)
}
}

pub fn conventional_commit(
Expand Down
5 changes: 5 additions & 0 deletions src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ impl Repository {
Ok(commits)
}

pub(crate) fn get_author(&self) -> Result<String> {
self.0.signature()?.name()
.map(|name| name.to_string())
.ok_or_else(|| anyhow!("Cannot get committer name"))
}
fn tree_to_treeish<'a>(
repo: &'a Git2Repository,
arg: Option<&String>,
Expand Down

0 comments on commit dad15d1

Please sign in to comment.