Skip to content
Clone
acbf7ea
47 lines 1.4 KB Rust
use axum::extract::{Path, State};
use export::rest::AppResponseData;
use jwt::Session;
use serde::Serialize;
use crate::errors::{ApiError, GitApiError};
use crate::handler::require_writer;
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,
}
#[derive(Debug, Clone, Serialize, utoipa::ToSchema)]
pub struct CommitSyncResponse {
pub repo_id: String,
pub sha: String,
}
#[utoipa::path(
post,
path = "/repos/{space_name}/{repo_name}/commits/{revision}/sync",
tag = "commits",
description = "将指定提交同步到平台提交元数据库,并按作者邮箱解析用户。",
params(CommitPath),
responses(
(status = 200, description = "sync commit", body = AppResponseData<CommitSyncResponse>)
)
)]
pub async fn sync_commit(
State(service): State<GitService>,
session: Session,
Path(path): Path<CommitPath>,
) -> Result<AppResponseData<CommitSyncResponse>, ApiError> {
let (ctx, _uid) = require_writer(&service, &session, path.space_name, path.repo_name).await?;
let row = service
.sync_commit(&ctx, &path.revision)
.await
.map_err(GitApiError::from)?;
Ok(AppResponseData::ok(CommitSyncResponse {
repo_id: row.repo_id.to_string(),
sha: row.sha,
}))
}