Skip to content
Clone
56417bd
37 lines 1014 B Rust
use axum::extract::{Path, State};
use export::rest::AppResponseData;
use serde::Serialize;
use session::Session;
use crate::errors::{ApiError, GitApiError};
use crate::handler::require_writer;
use crate::service::GitService;
#[derive(Debug, Clone, serde::Deserialize)]
pub struct CommitPath {
pub space_name: String,
pub repo_name: String,
pub revision: String,
}
#[derive(Debug, Clone, Serialize)]
pub struct CommitSyncResponse {
pub repo_id: String,
pub sha: String,
}
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,
}))
}