Skip to content
Clone
5f84089
46 lines 1.3 KB Rust
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::{FetchResultDto, RemoteAuthDto};
#[derive(Debug, Clone, serde::Deserialize, utoipa::ToSchema)]
pub struct RemoteFetchBody {
pub remote: String,
#[serde(default)]
pub auth: Option<RemoteAuthDto>,
}
#[utoipa::path(
post,
path = "/repos/{space_name}/{repo_name}/remotes/fetch",
tag = "remotes",
description = "从指定远程抓取引用并修剪已删除的远端分支。",
params(RepoPath),
request_body = RemoteFetchBody,
responses(
(status = 200, description = "fetch from remote", body = AppResponseData<FetchResultDto>)
)
)]
pub async fn fetch(
State(service): State<GitService>,
session: Session,
Path(path): Path<RepoPath>,
Json(body): Json<RemoteFetchBody>,
) -> Result<AppResponseData<FetchResultDto>, ApiError> {
require_writer(
&service,
&session,
path.space_name.clone(),
path.repo_name.clone(),
)
.await?;
let out = service
.remote_fetch(path.space_name, path.repo_name, body.remote, body.auth)
.await
.map_err(GitApiError::from)?;
Ok(AppResponseData::ok(out))
}