Skip to content

Commit

Permalink
Skip bots commits (#9)
Browse files Browse the repository at this point in the history
Signed-off-by: Sergio Castaño Arteaga <[email protected]>
  • Loading branch information
tegioz authored Aug 30, 2024
1 parent 45bcadc commit 9834b7c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
23 changes: 21 additions & 2 deletions dco2/src/dco.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ pub fn check(input: &CheckInput) -> Result<CheckOutput> {
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;
}

Expand Down Expand Up @@ -159,6 +161,23 @@ pub fn check(input: &CheckInput) -> Result<CheckOutput> {
Ok(output)
}

/// Check if we should skip this commit.
fn should_skip_commit(commit: &Commit) -> (bool, Option<String>) {
// 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<CommitError>> {
let mut errors = Vec::new();
Expand Down
3 changes: 3 additions & 0 deletions dco2/src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ pub struct Commit {
pub struct GitUser {
pub name: String,
pub email: String,
pub is_bot: bool,
}

impl From<octorust::types::CommitDataType> for Commit {
Expand All @@ -170,10 +171,12 @@ impl From<octorust::types::CommitDataType> 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,
Expand Down

0 comments on commit 9834b7c

Please sign in to comment.