Skip to content

Commit

Permalink
feat: author and committer on changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
Coenraad Human committed May 27, 2024
1 parent cf078b6 commit cf8d955
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/commands/changelog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ pub fn run(path: Option<String>, _commit_git_hook: Option<String>, scope_filter:
Some(conventional_commit) => {

simple_changelog.insert_str(0,
&format!("|{}|{}|{}.|{}|{}|\n",
&format!("|{}|{}|{}.|{}|{}|{}|{}|\n",
version.format(),
conventional_commit.commit_type,
conventional_commit.commit_description.to_sentence_case(),
if conventional_commit.is_breaking { 'X' } else { ' ' },
if conventional_commit.is_deprecrated { 'X' } else { ' ' },
commit.author.to_string(),
commit.committer.to_string()
).as_str()
);

Expand All @@ -39,9 +41,9 @@ pub fn run(path: Option<String>, _commit_git_hook: Option<String>, scope_filter:
}
}

simple_changelog.insert_str(0, "|---|---|---|---|---|\n");
simple_changelog.insert_str(0, "|---|---|---|---|---|---|---|\n");

simple_changelog.insert_str(0, "|Version|Commit Type|Description|Breaking Change|Deprecation|\n");
simple_changelog.insert_str(0, "|Version|Commit Type|Description|Breaking Change|Deprecation|Author|Committer|\n");

simple_changelog.insert_str(0, &format!("## {}\n\n", version.format()));

Expand Down
76 changes: 75 additions & 1 deletion src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,61 @@ use std::env;

use git2::Repository;

pub struct Author {

pub name: Option<String>,
pub email: Option<String>

}

impl Author {

pub fn to_string(&self) -> String {
let name = match self.name {
Some(ref value) => value,
None => "Not Available",
};

let email = match self.name {
Some(ref value) => value,
None => "not available",
};

format!("{} <{}>", name, email)
}

}

pub struct Committer {

pub name: Option<String>,
pub email: Option<String>

}

impl Committer {

pub fn to_string(&self) -> String {
let name = match self.name {
Some(ref value) => value,
None => "Not Available",
};

let email = match self.name {
Some(ref value) => value,
None => "not available",
};

format!("{} <{}>", name, email)
}

}

pub struct Commit {

pub message: Option<String>,
pub author: Author,
pub committer: Committer

}

Expand Down Expand Up @@ -51,7 +103,29 @@ pub fn retrieve_branch_commits(path: Option<String>) -> Vec<Commit> {
None => Option::None,
};

Commit { message }
let author = Author {
name: match commit.author().name() {
Some(value) => Some(value.to_string()),
None => None,
},
email: match commit.author().email() {
Some(value) => Some(value.to_string()),
None => None,
},
};

let committer = Committer {
name: match commit.committer().name() {
Some(value) => Some(value.to_string()),
None => None,
},
email: match commit.committer().email() {
Some(value) => Some(value.to_string()),
None => None,
},
};

Commit { message, author, committer }
},
Err(_) => panic!("Could not retrieve oid of commit"),
}
Expand Down

0 comments on commit cf8d955

Please sign in to comment.