Display only pushes to main branch

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2023-06-07 14:14:53 +02:00
commit 1aee1cd618
No known key found for this signature in database
GPG key ID: DEDA74AEECA9D0F2

View file

@ -19,13 +19,20 @@ use log::debug;
pub fn format_webhook(wh: &WebHook) -> Option<String> { pub fn format_webhook(wh: &WebHook) -> Option<String> {
Some(match wh { Some(match wh {
WebHook::Push(push) => { WebHook::Push(push) => {
if push.commits.len() != 0 { 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!( let mut text = format!(
"[{}] {} pushed {} commits branch {}", "[{}] {} pushed {} commits to main",
push.project.name, push.project.name,
push.user_name, push.user_name,
push.commits.len(), push.commits.len(),
push.ref_,
); );
// Display max 3 commits // Display max 3 commits
for commit in push.commits.clone().into_iter().take(3) { for commit in push.commits.clone().into_iter().take(3) {
@ -37,10 +44,6 @@ pub fn format_webhook(wh: &WebHook) -> Option<String> {
} }
} }
text text
} else {
// Ignore: Branch got deleted
return None;
}
} }
WebHook::Issue(issue) => { WebHook::Issue(issue) => {
let action = match issue.object_attributes.action { let action = match issue.object_attributes.action {