use export::http::{Json, Path, State}; use export::rest::AppResponseData; use token::Session; use crate::errors::{ApiError, GitApiError}; use crate::handler::{RepoPath, require_writer}; use crate::service::GitService; use crate::service::content::{ObjectKind, SignatureDto, WriteObjectResultDto}; #[derive(Debug, Clone, serde::Deserialize, utoipa::ToSchema)] pub struct CommitObjectBody { pub kind: ObjectKind, pub parents: Vec, pub tree: String, pub message: String, pub author: SignatureDto, pub committer: SignatureDto, } #[utoipa::path( post, path = "/repos/{space_name}/{repo_name}/contents/commits", tag = "content", description = "写入普通、合并或压缩提交对象并返回提交 ID,不移动引用。", params(RepoPath), request_body = CommitObjectBody, responses( (status = 200, description = "write commit object", body = AppResponseData) ) )] pub async fn commit_object( State(service): State, session: Session, Path(path): Path, Json(body): Json, ) -> Result, ApiError> { require_writer( &service, &session, path.space_name.clone(), path.repo_name.clone(), ) .await?; let out = service .commit_object( path.space_name, path.repo_name, body.kind, body.parents, body.tree, body.message, body.author, body.committer, ) .await .map_err(GitApiError::from)?; Ok(AppResponseData::ok(out)) }