From 1aee1cd618bbd4b64d264c1b18baa5d2822634c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Wed, 7 Jun 2023 14:14:53 +0200 Subject: [PATCH] Display only pushes to main branch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- src/webhook.rs | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/webhook.rs b/src/webhook.rs index 42f5bb3..2173ef9 100644 --- a/src/webhook.rs +++ b/src/webhook.rs @@ -19,28 +19,31 @@ use log::debug; pub fn format_webhook(wh: &WebHook) -> Option { Some(match wh { WebHook::Push(push) => { - if push.commits.len() != 0 { - let mut text = format!( - "[{}] {} pushed {} commits branch {}", - push.project.name, - push.user_name, - push.commits.len(), - push.ref_, - ); - // Display max 3 commits - for commit in push.commits.clone().into_iter().take(3) { - match commit.message.lines().nth(0) { - Some(subject) => { - text = format!("{}\n• {} <{}>", text, subject, commit.url); - } - None => {} - } - } - text - } else { + if push.ref_ != "refs/heads/main" { + // Ignore: Action not on 'main' branch + return None; + } + // Unlikely to be reached as 'main' is probably never going to be deleted + if push.commits.len() == 0 { // Ignore: Branch got deleted return None; } + let mut text = format!( + "[{}] {} pushed {} commits to main", + push.project.name, + push.user_name, + push.commits.len(), + ); + // Display max 3 commits + for commit in push.commits.clone().into_iter().take(3) { + match commit.message.lines().nth(0) { + Some(subject) => { + text = format!("{}\n• {} <{}>", text, subject, commit.url); + } + None => {} + } + } + text } WebHook::Issue(issue) => { let action = match issue.object_attributes.action {