Skip to content
Clone
b7cd2b1
44 lines 1.2 KB Rust
use export::http::{Path, State};
use export::rest::AppResponseData;
use jwt::Session;
use crate::errors::{ApiError, GitApiError};
use crate::handler;
use crate::service::GitService;
use crate::service::branches::BranchDto;
#[derive(Debug, Clone, serde::Deserialize, utoipa::IntoParams)]
pub struct BranchPath {
pub space_name: String,
pub repo_name: String,
pub name: String,
}
#[utoipa::path(
get,
path = "/repos/{space_name}/{repo_name}/branches/{name}",
tag = "branches",
description = "读取单个分支的当前提交、保护状态和元数据。",
params(BranchPath),
responses(
(status = 200, description = "get branch", body = AppResponseData<BranchDto>)
)
)]
pub async fn get_branch(
State(service): State<GitService>,
session: Session,
Path(path): Path<BranchPath>,
) -> Result<AppResponseData<BranchDto>, ApiError> {
let _ = handler::resolve_reader(
&service,
&session,
path.space_name.clone(),
path.repo_name.clone(),
)
.await?;
let out = service
.get_branch(path.space_name, path.repo_name, path.name)
.await
.map_err(GitApiError::from)?;
Ok(AppResponseData::ok(out))
}