2ae9196
ZhenYi
feat(lib/git): add HTTP handler tree with routes and errors across analysis, archives, blobs, branches, commits, conflicts, content, diffs, hooks, lfs, logs, maintenance, packs, patches, pipelines, refs, remotes, repos, signatures, submodules, tags, trees
2ae9196
use axum::Json;
use axum::extract::{Path, State};
use export::rest::AppResponseData;
use session::Session;
use crate::errors::{ApiError, GitApiError};
use crate::handler::{RepoPath, require_writer};
use crate::service::GitService;
use crate::service::content::{ObjectKind, SignatureDto, WriteObjectResultDto};
#[derive(Debug, Clone, serde::Deserialize)]
pub struct CommitObjectBody {
pub kind: ObjectKind,
pub parents: Vec<String>,
pub tree: String,
pub message: String,
pub author: SignatureDto,
pub committer: SignatureDto,
}
pub async fn commit_object(
State(service): State<GitService>,
session: Session,
Path(path): Path<RepoPath>,
Json(body): Json<CommitObjectBody>,
) -> Result<AppResponseData<WriteObjectResultDto>, ApiError> {
require_writer(&service, &session, path.space_name.clone(), path.repo_name.clone()).await?;
let out = service
.commit_object(
path.space_name,
path.repo_name,
body.kind,
body.parents,
body.tree,
body.message,
body.author,
body.committer,
)
.await
.map_err(GitApiError::from)?;
Ok(AppResponseData::ok(out))
}