f934c68
use crate::rpcgit::commit::types::CommitInfo;
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 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>,
OptionalUser(viewer): OptionalUser,
Path(path): Path<CommitPath>,
) -> Result<AppResponseData<CommitInfo>, ApiError> {
let (ctx, _) = handler::resolve_reader(
&service,
viewer,
path.space_name.clone(),
path.repo_name.clone(),
)
.await?;
let out = service
.get_commit(&ctx, path.revision)
.await
.map_err(GitApiError::from)?;
Ok(AppResponseData::ok(out))
}