cb06060
use ::session::Session;
use export::http::{Path, Query, State};
use export::rest::AppResponseData;
use crate::errors::{ApiError, GitApiError};
use crate::handler;
use crate::service::GitService;
use crate::service::conflicts::MergeStatusDto;
#[derive(Debug, Clone, serde::Deserialize, utoipa::IntoParams)]
pub struct GetConflictsQuery {
pub base: String,
pub head: String,
#[serde(default)]
pub ancestor: Option<String>,
}
#[utoipa::path(
get,
path = "/repos/{space_name}/{repo_name}/conflicts",
tag = "conflicts",
description = "检测两个修订合并时是否冲突,并返回可快进标记。",
params(crate::handler::RepoPath, GetConflictsQuery),
responses(
(status = 200, description = "merge conflict status", body = AppResponseData<MergeStatusDto>)
)
)]
pub async fn get_conflicts(
State(service): State<GitService>,
session: Session,
Path(path): Path<crate::handler::RepoPath>,
Query(q): Query<GetConflictsQuery>,
) -> Result<AppResponseData<MergeStatusDto>, ApiError> {
let (ctx, _) = handler::resolve_reader(
&service,
&session,
path.space_name.clone(),
path.repo_name.clone(),
)
.await?;
let out = match q.ancestor {
Some(ancestor) => {
service
.conflict_check_threeway(&ctx, q.base, q.head, ancestor)
.await
}
None => service.conflict_check(&ctx, q.base, q.head).await,
}
.map_err(GitApiError::from)?;
Ok(AppResponseData::ok(out))
}