Readd support for GitlabHook::WikiPage

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2024-08-31 23:25:53 +02:00 committed by pep
parent 4e330adb6b
commit db88921290
3 changed files with 57 additions and 23 deletions

View file

@ -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<CommitHookAttrs> for Commit {
@ -149,6 +150,31 @@ impl From<GlNoteHook> for Note {
}
}
impl From<WikiPageAction> for WikiAction {
fn from(other: WikiPageAction) -> WikiAction {
match other {
WikiPageAction::Create => WikiAction::Create,
WikiPageAction::Update => WikiAction::Update,
}
}
}
impl From<WikiPageHook> 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<GitlabHook> for Hook {
type Error = Error;
@ -158,6 +184,7 @@ impl TryFrom<GitlabHook> 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),
})
}

View file

@ -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<String> {
Some(match hook {
@ -129,25 +129,16 @@ pub fn format_hook(hook: &Hook) -> Option<String> {
} 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,
)
}
})
}

View file

@ -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),
}