4028f0d943
- Reordered actix-web imports to standardize import order - Reordered crate module imports to follow alphabetical ordering - Updated function calls to use multi-line formatting for better readability - Standardized blank lines around documentation comments - Applied consistent formatting to response handling methods - Normalized import organization across all repository-related API files - Improved code consistency and maintainability through standardized formatting - Applied formatting updates to all repository endpoint implementations
57 lines
1.8 KiB
Rust
57 lines
1.8 KiB
Rust
use actix_web::{HttpResponse, web};
|
|
use serde::Deserialize;
|
|
use utoipa::IntoParams;
|
|
|
|
use crate::api::response::{ApiErrorResponse, ApiResponse};
|
|
use crate::error::AppError;
|
|
use crate::service::AppService;
|
|
use crate::service::repo::protection::BranchMergeCheck;
|
|
use crate::session::Session;
|
|
|
|
#[derive(Debug, Deserialize, IntoParams)]
|
|
pub struct PathParams {
|
|
pub workspace_name: String,
|
|
pub repo_name: String,
|
|
pub target_branch: String,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, IntoParams)]
|
|
pub struct QueryParams {
|
|
pub pr_number: i64,
|
|
}
|
|
|
|
/// Check if a branch meets merge requirements
|
|
#[utoipa::path(
|
|
get,
|
|
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/branches/{target_branch}/merge-check",
|
|
tag = "Repos",
|
|
params(PathParams, QueryParams),
|
|
responses(
|
|
(status = 200, description = "Merge check completed successfully", body = ApiResponse<BranchMergeCheck>),
|
|
(status = 401, description = "Unauthorized", body = ApiErrorResponse),
|
|
(status = 403, description = "Forbidden", body = ApiErrorResponse),
|
|
(status = 404, description = "Repository or pull request not found", body = ApiErrorResponse),
|
|
(status = 500, description = "Internal server error", body = ApiErrorResponse),
|
|
),
|
|
security(("session_cookie" = []))
|
|
)]
|
|
pub async fn check_branch_merge(
|
|
service: web::Data<AppService>,
|
|
session: Session,
|
|
path: web::Path<PathParams>,
|
|
query: web::Query<QueryParams>,
|
|
) -> Result<HttpResponse, AppError> {
|
|
let check = service
|
|
.repo
|
|
.repo_check_branch_merge_allowed(
|
|
&session,
|
|
&path.workspace_name,
|
|
&path.repo_name,
|
|
&path.target_branch,
|
|
query.pr_number,
|
|
)
|
|
.await?;
|
|
|
|
Ok(HttpResponse::Ok().json(ApiResponse::new(check)))
|
|
}
|