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::remotes::{PushResultDto, RemoteAuthDto}; #[derive(Debug, Clone, serde::Deserialize, utoipa::ToSchema)] pub struct RemotePushBody { pub remote: String, #[serde(default)] pub refspec: Option, #[serde(default)] pub auth: Option, } #[utoipa::path( post, path = "/repos/{space_name}/{repo_name}/remotes/push", tag = "remotes", description = "推送指定 refspec 到远程,并返回成功与被拒绝的引用。", params(RepoPath), request_body = RemotePushBody, responses( (status = 200, description = "push to remote", body = AppResponseData) ) )] pub async fn push( 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 .remote_push( path.space_name, path.repo_name, body.remote, body.refspec, body.auth, ) .await .map_err(GitApiError::from)?; Ok(AppResponseData::ok(out)) }