Skip to content
Clone
69f12aa
43 lines 1.2 KB Rust
use axum::extract::{Path, State};
use export::rest::AppResponseData;
use jwt::Session;
use crate::errors::{ApiError, GitApiError};
use crate::handler::resolve_reader;
use crate::service::GitService;
#[derive(Debug, Clone, serde::Deserialize, utoipa::IntoParams)]
pub struct RevPath {
pub space_name: String,
pub repo_name: String,
pub revision: String,
}
#[utoipa::path(
get,
path = "/repos/{space_name}/{repo_name}/rev/{revision}",
tag = "commits",
description = "将分支、标签、短 SHA 或相对修订表达式解析为对象 ID。",
params(RevPath),
responses(
(status = 200, description = "parse revision", body = AppResponseData<String>)
)
)]
pub async fn rev_parse(
State(service): State<GitService>,
session: Session,
Path(path): Path<RevPath>,
) -> Result<AppResponseData<String>, ApiError> {
let _ = resolve_reader(
&service,
&session,
path.space_name.clone(),
path.repo_name.clone(),
)
.await?;
let out = service
.rev_parse(path.space_name, path.repo_name, path.revision)
.await
.map_err(GitApiError::from)?;
Ok(AppResponseData::ok(out))
}