Skip to content
Clone
eeff292
43 lines 1.1 KB Rust
use ::session::OptionalUser;
use api::http::{Path, State};
use api::rest::AppResponseData;
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}/resolve",
tag = "refs",
description = "将引用名或修订表达式解析为完整对象 ID。",
params(RefPath),
responses(
(status = 200, description = "resolve ref", body = AppResponseData<String>)
)
)]
pub async fn refs_resolve(
State(service): State<GitService>,
OptionalUser(viewer): OptionalUser,
Path(path): Path<RefPath>,
) -> Result<AppResponseData<String>, ApiError> {
let (ctx, _) = handler::resolve_reader(
&service,
viewer,
path.space_name.clone(),
path.repo_name.clone(),
)
.await?;
let out = service
.refs_resolve(&ctx, path.name)
.await
.map_err(GitApiError::from)?;
Ok(AppResponseData::ok(out))
}