summaryrefslogtreecommitdiff
path: root/src/policies.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/policies.rs')
-rw-r--r--src/policies.rs61
1 files changed, 2 insertions, 59 deletions
diff --git a/src/policies.rs b/src/policies.rs
index 990e141..edeba5f 100644
--- a/src/policies.rs
+++ b/src/policies.rs
@@ -1,77 +1,20 @@
+pub mod policy_result;
use crate::config::VerifyGitCommitsConfig;
use crate::fs::*;
use crate::git::*;
use crate::gpg::*;
use crate::keyring::*;
+use self::policy_result::PolicyResult;
use git2::Oid;
use rayon::prelude::*;
use std::collections::HashSet;
use std::error::Error;
-use std::fmt;
-use std::iter;
use std::path::PathBuf;
use std::time::Instant;
use log::*;
-#[derive(Debug, Clone)]
-pub enum PolicyResult {
- Ok,
- UnsignedCommit(Oid),
- UnsignedMergeCommit(Oid),
- NotEnoughAuthors(Oid),
- InvalidAuthorEmail(Oid, String),
- MissingAuthorEmail(Oid),
- InvalidCommitterEmail(Oid, String),
- MissingCommitterEmail(Oid),
- NotRebased(Oid),
-}
-
-impl PolicyResult {
- pub fn and(self, res: PolicyResult) -> PolicyResult {
- match self {
- PolicyResult::Ok => res,
- x => x,
- }
- }
- pub fn is_ok(&self) -> bool {
- match self {
- PolicyResult::Ok => true,
- _ => false,
- }
- }
- pub fn is_err(&self) -> bool {
- !self.is_ok()
- }
-}
-
-impl fmt::Display for PolicyResult {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- use PolicyResult::*;
-
- match self {
- Ok => write!(f, "Ok"),
- UnsignedCommit(id) => write!(f, "Commit does not have a valid GPG signature: {}", id),
- UnsignedMergeCommit(id) => write!(f, "Commit does not have a valid GPG signature: {}. This is a merge commit, please note that if there were conflicts that needed to be resolved then the commit needs a signature.", id),
- NotEnoughAuthors(id) => write!(f, "Merge commit needs to have multiple authors in the branch: {}", id),
- InvalidAuthorEmail(id, email) => write!(f, "Commit has an invalid author email ({}): {}", email, id),
- MissingAuthorEmail(id) => write!(f, "Commit does not have an author email: {}", id),
- InvalidCommitterEmail(id, email) => write!(f, "Commit has an invalid committer email ({}): {}", email, id),
- MissingCommitterEmail(id) => write!(f, "Commit does not have a committer email: {}", id),
- NotRebased(id) => write!(f, "Merge commit needs to be rebased on the mainline before it can be merged: {}", id)
- }
- }
-}
-
-impl iter::FromIterator<PolicyResult> for PolicyResult {
- fn from_iter<I: IntoIterator<Item = PolicyResult>>(iter: I) -> Self {
- iter.into_iter()
- .find(PolicyResult::is_err)
- .unwrap_or(PolicyResult::Ok)
- }
-}
-
pub fn prepend_branch_name<F: Fs, G: Git>(
git: &G,
commit_file: PathBuf,