Skip to content
Clone
149bec6
44 lines 1.2 KB Rust
use axum::extract::{Path, State};
use export::rest::AppResponseData;
use gitbaby::commit::types::CommitInfo;
use session_layer::Session;
use crate::errors::{ApiError, GitApiError};
use crate::handler::resolve_reader;
use crate::service::GitService;
#[derive(Debug, Clone, serde::Deserialize, utoipa::IntoParams)]
pub struct CommitPath {
pub space_name: String,
pub repo_name: String,
pub revision: String,
}
#[utoipa::path(
get,
path = "/repos/{space_name}/{repo_name}/commits/{revision}",
tag = "commits",
description = "读取任意修订表达式对应的单个提交详情。",
params(CommitPath),
responses(
(status = 200, description = "get commit")
)
)]
pub async fn get_commit(
State(service): State<GitService>,
session: Session,
Path(path): Path<CommitPath>,
) -> Result<AppResponseData<CommitInfo>, ApiError> {
let _ = resolve_reader(
&service,
&session,
path.space_name.clone(),
path.repo_name.clone(),
)
.await?;
let out = service
.get_commit(path.space_name, path.repo_name, path.revision)
.await
.map_err(GitApiError::from)?;
Ok(AppResponseData::ok(out))
}