Skip to content
Clone
bcbe85c
40 lines 1.2 KB Rust
use ::session::Session;
use export::http::{Json, Path, State};
use export::rest::AppResponseData;
use git::facade::RepoPath;
use crate::errors::ApiError;
use crate::services::pulls::{CreatePullCmd, PullDto};
use crate::services::service::PullService;
use crate::share::lookup;
#[utoipa::path(
post,
path = "/repos/{space_name}/{repo_name}/pulls",
tag = "pulls",
description = "在同一仓库的 head 与 base 分支之间创建合并请求。",
params(RepoPath),
request_body = CreatePullCmd,
responses(
(status = 200, description = "created pull request", body = AppResponseData<PullDto>)
)
)]
pub async fn create_pull(
State(service): State<PullService>,
session: Session,
Path(path): Path<RepoPath>,
Json(cmd): Json<CreatePullCmd>,
) -> Result<AppResponseData<PullDto>, ApiError> {
let (ctx, caller) = lookup::repo_write(
&service,
&session,
path.space_name.clone(),
path.repo_name.clone(),
)
.await?;
let pull = service
.create_pull(path.space_name, path.repo_name, &ctx, caller, cmd)
.await?;
let users = service.pull_users(std::slice::from_ref(&pull)).await?;
Ok(AppResponseData::ok(PullService::dto(&pull, &users)))
}