#![cfg_attr(coverage_nightly, coverage(off))]
use anyhow::{Context, Result};
use git2::{Commit, DiffOptions, Repository, Sort};
use std::path::Path;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ChangeType {
Added,
Modified,
Deleted,
Renamed,
}
impl ChangeType {
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn as_str(&self) -> &'static str {
match self {
ChangeType::Added => "A",
ChangeType::Modified => "M",
ChangeType::Deleted => "D",
ChangeType::Renamed => "R",
}
}
}
#[derive(Debug, Clone)]
pub struct FileChange {
pub path: String,
pub change_type: ChangeType,
pub lines_added: u32,
pub lines_deleted: u32,
}
#[derive(Debug, Clone)]
pub struct CommitInfo {
pub hash: String,
pub message_subject: String,
pub message_body: Option<String>,
pub author_name: String,
pub author_email: String,
pub timestamp: i64,
pub is_merge: bool,
pub is_fix: bool,
pub is_feat: bool,
pub issue_refs: Vec<String>,
pub files: Vec<FileChange>,
}
impl CommitInfo {
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn full_message(&self) -> String {
match &self.message_body {
Some(body) if !body.is_empty() => format!("{}\n\n{}", self.message_subject, body),
_ => self.message_subject.clone(),
}
}
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn is_indexable(&self) -> bool {
if self.is_merge && self.message_subject.starts_with("Merge ") {
return false;
}
if self.message_subject.len() < 10 {
return false;
}
true
}
}
pub struct CommitParser {
repo: Repository,
}
include!("commit_parser_parsing.rs");
include!("commit_parser_tests.rs");