qlty_coverage/
git.rs

1use anyhow::Result;
2use git2::Repository;
3
4#[derive(Debug, Clone)]
5pub struct CommitMetadata {
6    pub commit_time: git2::Time,
7    pub author_time: git2::Time,
8    pub committer_name: String,
9    pub committer_email: String,
10    pub author_name: String,
11    pub author_email: String,
12    pub commit_message: String,
13}
14
15pub fn retrieve_commit_metadata() -> Result<CommitMetadata> {
16    let repo = Repository::discover(".")?;
17
18    let head = repo.head()?;
19    let oid = head.peel_to_commit()?.id();
20    let commit = repo.find_commit(oid)?;
21
22    let commit_time = commit.time();
23
24    let committer = commit.committer();
25    let committer_name = committer.name().unwrap_or("Unknown").to_string();
26    let committer_email = committer.email().unwrap_or("Unknown").to_string();
27
28    let author = commit.author();
29    let author_name = author.name().unwrap_or("Unknown").to_string();
30    let author_email = author.email().unwrap_or("Unknown").to_string();
31    let author_time = author.when();
32
33    let commit_message = commit.message().unwrap_or("").to_string();
34
35    Ok(CommitMetadata {
36        commit_time,
37        author_time,
38        committer_name,
39        committer_email,
40        author_name,
41        author_email,
42        commit_message,
43    })
44}