From db889212903a415b3de3ca969d2ecc6d178fdf39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 31 Aug 2024 23:25:53 +0200 Subject: [PATCH] Readd support for GitlabHook::WikiPage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- src/hooks/gitlab.rs | 31 +++++++++++++++++++++++++++++-- src/hooks/mod.rs | 33 ++++++++++++--------------------- src/hooks/types.rs | 16 ++++++++++++++++ 3 files changed, 57 insertions(+), 23 deletions(-) diff --git a/src/hooks/gitlab.rs b/src/hooks/gitlab.rs index ef60cd6..0cea8d6 100644 --- a/src/hooks/gitlab.rs +++ b/src/hooks/gitlab.rs @@ -15,7 +15,7 @@ use crate::hooks::types::{ Commit, Hook, Issue, IssueAction, IssueAttrs, MergeRequest, MergeRequestAction, - MergeRequestAttrs, Note, Push, Repository, User, + MergeRequestAttrs, Note, Push, Repository, User, Wiki, WikiAction, }; use crate::Error; @@ -23,7 +23,8 @@ pub use ::gitlab::webhooks::{ CommitHookAttrs, IssueAction as GlIssueAction, IssueHook as GlIssueHook, IssueHookAttrs as GlIssueHookAttrs, MergeRequestAction as GlMergeRequestAction, MergeRequestHook as GlMergeRequestHook, MergeRequestHookAttrs as GlMergeRequestHookAttrs, - NoteHook as GlNoteHook, PushHook as GlPushHook, WebHook as GitlabHook, + NoteHook as GlNoteHook, PushHook as GlPushHook, WebHook as GitlabHook, WikiPageAction, + WikiPageHook, }; impl From for Commit { @@ -149,6 +150,31 @@ impl From for Note { } } +impl From for WikiAction { + fn from(other: WikiPageAction) -> WikiAction { + match other { + WikiPageAction::Create => WikiAction::Create, + WikiPageAction::Update => WikiAction::Update, + } + } +} + +impl From for Wiki { + fn from(other: WikiPageHook) -> Wiki { + Wiki { + action: other.object_attributes.action.into(), + repository: Repository { + name: other.project.name, + }, + author: User { + name: other.user.name, + }, + title: other.object_attributes.title, + url: other.object_attributes.url, + } + } +} + impl TryFrom for Hook { type Error = Error; @@ -158,6 +184,7 @@ impl TryFrom for Hook { GitlabHook::Issue(issue) => Hook::Issue((*issue).into()), GitlabHook::MergeRequest(mr) => Hook::MergeRequest((*mr).into()), GitlabHook::Note(note) => Hook::Note((*note).into()), + GitlabHook::WikiPage(page) => Hook::Wiki((*page).into()), _ => return Err(Error::UnsupportedHookConversion), }) } diff --git a/src/hooks/mod.rs b/src/hooks/mod.rs index 7f8f971..f250052 100644 --- a/src/hooks/mod.rs +++ b/src/hooks/mod.rs @@ -20,7 +20,7 @@ mod types; pub use crate::hooks::forgejo::ForgejoHook; pub use crate::hooks::gitlab::GitlabHook; pub use crate::hooks::types::Hook; -use crate::hooks::types::{IssueAction, MergeRequestAction}; +use crate::hooks::types::{IssueAction, MergeRequestAction, WikiAction}; pub fn format_hook(hook: &Hook) -> Option { Some(match hook { @@ -129,25 +129,16 @@ pub fn format_hook(hook: &Hook) -> Option { } else { unreachable!() } - } /* - Hook::WikiPage(page) => { - let action = match page.object_attributes.action { - WikiPageAction::Update => "updated", - WikiPageAction::Create => "created", - }; - format!( - "[{}] {} {} wiki page {} <{}>", - page.project.name, - page.user.name, - action, - page.object_attributes.title, - page.object_attributes.url, - ) - } - _ => { - debug!("Hook not supported"); - return None; - } - */ + } + Hook::Wiki(page) => { + let action = match page.action { + WikiAction::Update => "updated", + WikiAction::Create => "created", + }; + format!( + "[{}] {} {} wiki page {} <{}>", + page.repository.name, page.author.name, action, page.title, page.url, + ) + } }) } diff --git a/src/hooks/types.rs b/src/hooks/types.rs index f8d7169..bfe61a5 100644 --- a/src/hooks/types.rs +++ b/src/hooks/types.rs @@ -114,6 +114,21 @@ pub struct Note { pub url: String, } +#[derive(Debug)] +pub enum WikiAction { + Create, + Update, +} + +#[derive(Debug)] +pub struct Wiki { + pub action: WikiAction, + pub repository: Repository, + pub author: User, + pub title: String, + pub url: String, +} + /// Lowest common denominator struct so that we don't have to duplicate our code for each platform /// we support. #[derive(Debug)] @@ -123,4 +138,5 @@ pub enum Hook { Issue(Issue), MergeRequest(MergeRequest), Note(Note), + Wiki(Wiki), }