5f84089
use ::session::Session;
use export::http::{Json, Path, State};
use export::rest::AppResponseData;
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<String>,
#[serde(default)]
pub auth: Option<RemoteAuthDto>,
}
#[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<PushResultDto>)
)
)]
pub async fn push(
State(service): State<GitService>,
session: Session,
Path(path): Path<RepoPath>,
Json(body): Json<RemotePushBody>,
) -> Result<AppResponseData<PushResultDto>, 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))
}