From 9834b7c4a0f9842562b48a50b2763ac015626c52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Casta=C3=B1o=20Arteaga?= Date: Fri, 30 Aug 2024 12:08:20 +0200 Subject: [PATCH] Skip bots commits (#9) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sergio CastaƱo Arteaga --- dco2/src/dco.rs | 23 +++++++++++++++++++++-- dco2/src/github.rs | 3 +++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/dco2/src/dco.rs b/dco2/src/dco.rs index bab1d7a..53fe0e8 100644 --- a/dco2/src/dco.rs +++ b/dco2/src/dco.rs @@ -125,8 +125,10 @@ pub fn check(input: &CheckInput) -> Result { for commit in &input.commits { let mut commit_output = CommitCheckOutput::new(commit.clone()); - // Skip merge commits - if commit.is_merge { + // Check if we should skip this commit + let (commit_should_be_skipped, reason) = should_skip_commit(commit); + if commit_should_be_skipped { + debug!("commit ({}) skipped: {:?}", commit_output.commit.sha, reason); continue; } @@ -159,6 +161,23 @@ pub fn check(input: &CheckInput) -> Result { Ok(output) } +/// Check if we should skip this commit. +fn should_skip_commit(commit: &Commit) -> (bool, Option) { + // Skip merge commits + if commit.is_merge { + return (true, Some("merge commit".to_string())); + } + + // Skip bots commits + if let Some(author) = &commit.author { + if author.is_bot { + return (true, Some("author is a bot".to_string())); + } + } + + (false, None) +} + /// Validate author and committer emails. fn validate_emails(commit: &Commit) -> Result<(), Vec> { let mut errors = Vec::new(); diff --git a/dco2/src/github.rs b/dco2/src/github.rs index d05e957..6f0b487 100644 --- a/dco2/src/github.rs +++ b/dco2/src/github.rs @@ -161,6 +161,7 @@ pub struct Commit { pub struct GitUser { pub name: String, pub email: String, + pub is_bot: bool, } impl From for Commit { @@ -170,10 +171,12 @@ impl From for Commit { author: c.commit.author.map(|author| GitUser { name: author.name, email: author.email, + is_bot: c.author.map_or(false, |a| a.type_ == "Bot"), }), committer: c.commit.committer.map(|committer| GitUser { name: committer.name, email: committer.email, + is_bot: c.committer.map_or(false, |c| c.type_ == "Bot"), }), html_url: c.html_url, is_merge: c.parents.len() > 1,