Skip to content
Clone
951a522
76 lines 1.9 KB Rust
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<String>,
pub new_oid: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HookEventDto {
pub kind: HookEventKind,
pub repo_id: String,
pub refs: Vec<HookRefDto>,
pub actor: String,
pub timestamp: i64,
}
#[derive(Debug, Clone, Serialize)]
pub struct HookResultDto {
pub accepted: bool,
pub message: Option<String>,
}
#[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<HookResultDto, GitError> {
Ok(HookResultDto {
accepted: false,
message: Some("no pre-receive policy configured".to_string()),
})
}
pub async fn hook_post_receive(&self, _event: HookEventDto) -> Result<HookResultDto, GitError> {
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<String>,
) -> Result<ScriptOutputDto, GitError> {
Err(GitError::Unimplemented(
"hook script execution requires a KenShell HookService",
))
}
}