use serde::{Deserialize, Serialize}; use crate::service::GitService; use crate::share::errors::GitError; #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, utoipa::ToSchema)] #[serde(rename_all = "snake_case")] pub enum HookEventKind { PreReceive, PostReceive, Update, Push, Tag, MergeRequest, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct HookRefDto { pub name: String, pub old_oid: Option, pub new_oid: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct HookEventDto { pub kind: HookEventKind, pub repo_id: String, pub refs: Vec, pub actor: String, pub timestamp: i64, } #[derive(Debug, Clone, Serialize)] pub struct HookResultDto { pub accepted: bool, pub message: Option, } #[derive(Debug, Clone, Serialize, utoipa::ToSchema)] pub struct ScriptOutputDto { pub exit_code: i32, pub stdout: String, pub stderr: String, } impl GitService { pub async fn hook_pre_receive(&self, _event: HookEventDto) -> Result { Ok(HookResultDto { accepted: false, message: Some("no pre-receive policy configured".to_string()), }) } pub async fn hook_post_receive(&self, _event: HookEventDto) -> Result { Ok(HookResultDto { accepted: true, message: None, }) } pub fn hook_supported(&self, kind: HookEventKind) -> bool { matches!(kind, HookEventKind::PreReceive | HookEventKind::PostReceive) } pub async fn hook_execute_script( &self, _space_name: String, _repo_name: String, _script: HookEventKind, _args: Vec, ) -> Result { Err(GitError::Unimplemented( "hook script execution requires a KenShell HookService", )) } }