Move get_main_author -> lib.rs

This commit is contained in:
Martin Frost 2020-05-22 22:03:28 +02:00
parent 8032a08656
commit 0061c5b112
2 changed files with 18 additions and 13 deletions

View File

@ -1,9 +1,11 @@
use std::fs::File; use git2::Repository;
use std::process; use std::process;
use git2::{Config, Repository}; use std::fs::File;
use git_mob::get_main_author;
fn main() { fn main() {
println!("{}", get_main_author()); let main_author = get_main_author();
println!("{}", main_author);
match Repository::open_from_env() { match Repository::open_from_env() {
Ok(repo) => { Ok(repo) => {
@ -16,16 +18,6 @@ fn main() {
} }
} }
fn get_main_author() -> String {
let cfg = Config::open_default().unwrap();
let name = cfg.get_entry("user.name").unwrap();
let name = name.value().unwrap();
let email = cfg.get_entry("user.email").unwrap();
let email = email.value().unwrap();
format!("{} <{}>", name, email)
}
fn truncate_gitmessage_template(repo: Repository) { fn truncate_gitmessage_template(repo: Repository) {
let template_path = repo.path().join(".gitmessage"); let template_path = repo.path().join(".gitmessage");
let _template = File::create(template_path); let _template = File::create(template_path);

13
src/lib.rs Normal file
View File

@ -0,0 +1,13 @@
use std::fs::File;
use git2::{Config, Repository};
pub fn get_main_author() -> Author {
let cfg = Config::open_default().unwrap();
let name = cfg.get_entry("user.name").unwrap();
let email = cfg.get_entry("user.email").unwrap();
Author {
name: name.value().unwrap().to_string(),
email: email.value().unwrap().to_string(),
}
}