use ::session::AuthedUser; use api::http::{Json, Path, State}; use api::rest::{AppResponseData, NoData}; use crate::errors::{ApiError, GitApiError}; use crate::handler; use crate::service::GitService; #[derive(Debug, Clone, serde::Deserialize, utoipa::IntoParams)] pub struct BranchPath { pub space_name: String, pub repo_name: String, pub name: String, } #[derive(Debug, Clone, serde::Deserialize, utoipa::ToSchema)] pub struct RenameBranchCmd { pub new_name: String, } #[utoipa::path( patch, path = "/repos/{space_name}/{repo_name}/branches/{name}", tag = "branches", description = "重命名分支引用并同步更新分支元数据记录。", params(BranchPath), request_body = RenameBranchCmd, responses( (status = 200, description = "rename branch", body = AppResponseData) ) )] pub async fn rename_branch( State(service): State, AuthedUser(uid): AuthedUser, Path(path): Path, Json(cmd): Json, ) -> Result, ApiError> { let (ctx, _) = handler::require_writer( &service, uid, path.space_name.clone(), path.repo_name.clone(), ) .await?; service .rename_branch(&ctx, path.name, cmd.new_name) .await .map_err(GitApiError::from)?; Ok(AppResponseData::ok(NoData)) }