Skip to content
Clone
b7cd2b1
44 lines 1.1 KB Rust
use crate::rpcgit::refs::types::RefInfo;
use export::http::{Path, State};
use export::rest::AppResponseData;
use jwt::Session;
use crate::errors::{ApiError, GitApiError};
use crate::handler;
use crate::service::GitService;
#[derive(Debug, Clone, serde::Deserialize, utoipa::IntoParams)]
pub struct RefPath {
pub space_name: String,
pub repo_name: String,
pub name: String,
}
#[utoipa::path(
get,
path = "/repos/{space_name}/{repo_name}/refs/{name}",
tag = "refs",
description = "按引用名称读取单个 Git 引用。",
params(RefPath),
responses(
(status = 200, description = "get ref")
)
)]
pub async fn refs_get(
State(service): State<GitService>,
session: Session,
Path(path): Path<RefPath>,
) -> Result<AppResponseData<RefInfo>, ApiError> {
let _ = handler::resolve_reader(
&service,
&session,
path.space_name.clone(),
path.repo_name.clone(),
)
.await?;
let out = service
.refs_get(path.space_name, path.repo_name, path.name)
.await
.map_err(GitApiError::from)?;
Ok(AppResponseData::ok(out))
}