use ::session::Session; use export::http::{Json, Path, State}; use export::rest::AppResponseData; use crate::errors::{ApiError, GitApiError}; use crate::handler; use crate::service::GitService; use crate::service::hooks::{HookEventKind, ScriptOutputDto}; #[derive(Debug, Clone, serde::Deserialize, utoipa::IntoParams)] pub struct HookScriptPath { pub space_name: String, pub repo_name: String, pub script: HookEventKind, } #[derive(Debug, Clone, serde::Deserialize, utoipa::ToSchema)] pub struct HookExecBody { #[serde(default)] pub args: Vec, } #[utoipa::path( post, path = "/repos/{space_name}/{repo_name}/hooks/{script}", tag = "hooks", description = "以受控参数执行仓库 pre-receive 或 post-receive 脚本并回传结果。", params(HookScriptPath), request_body = HookExecBody, responses( (status = 200, description = "execute hook script", body = AppResponseData) ) )] pub async fn execute_script( State(service): State, session: Session, Path(path): Path, Json(body): Json, ) -> Result, ApiError> { let (ctx, _) = handler::require_writer( &service, &session, path.space_name.clone(), path.repo_name.clone(), ) .await?; let out = service .hook_execute_script(&ctx, path.script, body.args) .await .map_err(GitApiError::from)?; Ok(AppResponseData::ok(out)) }