d98e4d59e3
- Add PR assignees API with list, assign, and unassign operations - Add PR check runs API with create, update, list, and delete operations - Implement workspace finding by ID method in core service - Update .gitignore to include .env* files while preserving .env.example - Reorder imports in multiple API files for consistency - Format function calls with proper line breaks across PR-related APIs - Add wiki revision comparison endpoint with proper schema definitions - Integrate new API modules into main application setup - Add health check, readiness probe, and OpenAPI endpoints to main server - Configure session management and dependency injection in main application
183 lines
6.4 KiB
Rust
183 lines
6.4 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::models::prs::PrCheckRun;
|
|
use crate::service::AppService;
|
|
use crate::service::pr::check_runs::{CreateCheckRunParams, UpdateCheckRunParams};
|
|
use crate::session::Session;
|
|
|
|
#[derive(Debug, Deserialize, IntoParams)]
|
|
pub struct PrPath {
|
|
/// Workspace name (unique identifier)
|
|
pub workspace_name: String,
|
|
/// Repository name (unique within the workspace)
|
|
pub repo_name: String,
|
|
/// PR number (unique within the repository)
|
|
pub number: i64,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, IntoParams)]
|
|
pub struct CheckRunPath {
|
|
/// Workspace name (unique identifier)
|
|
pub workspace_name: String,
|
|
/// Repository name (unique within the workspace)
|
|
pub repo_name: String,
|
|
/// PR number (unique within the repository)
|
|
pub number: i64,
|
|
/// Check run ID (UUID)
|
|
pub check_run_id: uuid::Uuid,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, IntoParams)]
|
|
pub struct QP {
|
|
pub limit: Option<i64>,
|
|
pub offset: Option<i64>,
|
|
}
|
|
|
|
/// List check runs for a PR
|
|
#[utoipa::path(
|
|
get,
|
|
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/prs/{number}/check-runs",
|
|
tag = "Pull Requests",
|
|
operation_id = "prListCheckRuns",
|
|
params(PrPath, QP),
|
|
responses(
|
|
(status = 200, description = "Check runs listed.", body = ApiResponse<Vec<PrCheckRun>>),
|
|
(status = 401, description = "Authentication required", body = ApiErrorResponse),
|
|
(status = 404, description = "PR not found", body = ApiErrorResponse),
|
|
(status = 500, description = "Internal server error", body = ApiErrorResponse),
|
|
),
|
|
security(("session_cookie" = []))
|
|
)]
|
|
pub async fn list_check_runs(
|
|
service: web::Data<AppService>,
|
|
session: Session,
|
|
path: web::Path<PrPath>,
|
|
query: web::Query<QP>,
|
|
) -> Result<HttpResponse, AppError> {
|
|
let runs = service
|
|
.pr
|
|
.pr_check_runs(
|
|
&session,
|
|
&path.workspace_name,
|
|
&path.repo_name,
|
|
path.number,
|
|
query.limit.unwrap_or(50),
|
|
query.offset.unwrap_or(0),
|
|
)
|
|
.await?;
|
|
Ok(HttpResponse::Ok().json(ApiResponse::new(runs)))
|
|
}
|
|
|
|
/// Create a check run. Requires Member role.
|
|
#[utoipa::path(
|
|
post,
|
|
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/prs/{number}/check-runs",
|
|
tag = "Pull Requests",
|
|
operation_id = "prCreateCheckRun",
|
|
params(PrPath),
|
|
request_body(content = CreateCheckRunParams, description = "Check run parameters", content_type = "application/json"),
|
|
responses(
|
|
(status = 201, description = "Check run created.", body = ApiResponse<PrCheckRun>),
|
|
(status = 400, description = "Invalid status", body = ApiErrorResponse),
|
|
(status = 401, description = "Authentication required", body = ApiErrorResponse),
|
|
(status = 403, description = "Insufficient permissions", body = ApiErrorResponse),
|
|
(status = 404, description = "PR not found", body = ApiErrorResponse),
|
|
(status = 500, description = "Internal server error", body = ApiErrorResponse),
|
|
),
|
|
security(("session_cookie" = []))
|
|
)]
|
|
pub async fn create_check_run(
|
|
service: web::Data<AppService>,
|
|
session: Session,
|
|
path: web::Path<PrPath>,
|
|
params: web::Json<CreateCheckRunParams>,
|
|
) -> Result<HttpResponse, AppError> {
|
|
let run = service
|
|
.pr
|
|
.pr_create_check_run(
|
|
&session,
|
|
&path.workspace_name,
|
|
&path.repo_name,
|
|
path.number,
|
|
params.into_inner(),
|
|
)
|
|
.await?;
|
|
Ok(HttpResponse::Created().json(ApiResponse::new(run)))
|
|
}
|
|
|
|
/// Update a check run. Requires Member role.
|
|
#[utoipa::path(
|
|
put,
|
|
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/prs/{number}/check-runs/{check_run_id}",
|
|
tag = "Pull Requests",
|
|
operation_id = "prUpdateCheckRun",
|
|
params(CheckRunPath),
|
|
request_body(content = UpdateCheckRunParams, description = "Check run update parameters", content_type = "application/json"),
|
|
responses(
|
|
(status = 200, description = "Check run updated.", body = ApiResponse<PrCheckRun>),
|
|
(status = 400, description = "Invalid status", body = ApiErrorResponse),
|
|
(status = 401, description = "Authentication required", body = ApiErrorResponse),
|
|
(status = 403, description = "Insufficient permissions", body = ApiErrorResponse),
|
|
(status = 404, description = "Check run not found", body = ApiErrorResponse),
|
|
(status = 500, description = "Internal server error", body = ApiErrorResponse),
|
|
),
|
|
security(("session_cookie" = []))
|
|
)]
|
|
pub async fn update_check_run(
|
|
service: web::Data<AppService>,
|
|
session: Session,
|
|
path: web::Path<CheckRunPath>,
|
|
params: web::Json<UpdateCheckRunParams>,
|
|
) -> Result<HttpResponse, AppError> {
|
|
let run = service
|
|
.pr
|
|
.pr_update_check_run(
|
|
&session,
|
|
&path.workspace_name,
|
|
&path.repo_name,
|
|
path.number,
|
|
path.check_run_id,
|
|
params.into_inner(),
|
|
)
|
|
.await?;
|
|
Ok(HttpResponse::Ok().json(ApiResponse::new(run)))
|
|
}
|
|
|
|
/// Delete a check run. Requires Admin role.
|
|
#[utoipa::path(
|
|
delete,
|
|
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/prs/{number}/check-runs/{check_run_id}",
|
|
tag = "Pull Requests",
|
|
operation_id = "prDeleteCheckRun",
|
|
params(CheckRunPath),
|
|
responses(
|
|
(status = 200, description = "Check run deleted.", body = ApiResponse<String>),
|
|
(status = 401, description = "Authentication required", body = ApiErrorResponse),
|
|
(status = 403, description = "Insufficient permissions (Admin required)", body = ApiErrorResponse),
|
|
(status = 404, description = "Check run not found", body = ApiErrorResponse),
|
|
(status = 500, description = "Internal server error", body = ApiErrorResponse),
|
|
),
|
|
security(("session_cookie" = []))
|
|
)]
|
|
pub async fn delete_check_run(
|
|
service: web::Data<AppService>,
|
|
session: Session,
|
|
path: web::Path<CheckRunPath>,
|
|
) -> Result<HttpResponse, AppError> {
|
|
service
|
|
.pr
|
|
.pr_delete_check_run(
|
|
&session,
|
|
&path.workspace_name,
|
|
&path.repo_name,
|
|
path.number,
|
|
path.check_run_id,
|
|
)
|
|
.await?;
|
|
Ok(HttpResponse::Ok().json(ApiResponse::new("Check run deleted".to_string())))
|
|
}
|