feat(api): implement pull request assignees and check runs endpoints
- 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
This commit is contained in:
@@ -0,0 +1,156 @@
|
||||
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::PrSubscription;
|
||||
use crate::service::AppService;
|
||||
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 QP {
|
||||
pub limit: Option<i64>,
|
||||
pub offset: Option<i64>,
|
||||
}
|
||||
|
||||
/// List subscriptions on a PR
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/prs/{number}/subscriptions",
|
||||
tag = "Pull Requests",
|
||||
operation_id = "prListSubscriptions",
|
||||
params(PrPath, QP),
|
||||
responses(
|
||||
(status = 200, description = "Subscriptions listed.", body = ApiResponse<Vec<PrSubscription>>),
|
||||
(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_subscriptions(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PrPath>,
|
||||
query: web::Query<QP>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let subs = service
|
||||
.pr
|
||||
.pr_subscriptions(
|
||||
&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(subs)))
|
||||
}
|
||||
|
||||
/// Subscribe to a PR to receive notifications
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/prs/{number}/subscribe",
|
||||
tag = "Pull Requests",
|
||||
operation_id = "prSubscribe",
|
||||
params(PrPath),
|
||||
responses(
|
||||
(status = 200, description = "Subscribed.", body = ApiResponse<PrSubscription>),
|
||||
(status = 401, description = "Authentication required", body = ApiErrorResponse),
|
||||
(status = 404, description = "PR not found", body = ApiErrorResponse),
|
||||
(status = 409, description = "Already subscribed", body = ApiErrorResponse),
|
||||
(status = 500, description = "Internal server error", body = ApiErrorResponse),
|
||||
),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn subscribe(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PrPath>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let sub = service
|
||||
.pr
|
||||
.pr_subscribe(&session, &path.workspace_name, &path.repo_name, path.number)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(sub)))
|
||||
}
|
||||
|
||||
/// Unsubscribe from a PR
|
||||
#[utoipa::path(
|
||||
delete,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/prs/{number}/subscribe",
|
||||
tag = "Pull Requests",
|
||||
operation_id = "prUnsubscribe",
|
||||
params(PrPath),
|
||||
responses(
|
||||
(status = 200, description = "Unsubscribed.", body = ApiResponse<String>),
|
||||
(status = 401, description = "Authentication required", body = ApiErrorResponse),
|
||||
(status = 404, description = "Not subscribed", body = ApiErrorResponse),
|
||||
(status = 500, description = "Internal server error", body = ApiErrorResponse),
|
||||
),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn unsubscribe(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PrPath>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
service
|
||||
.pr
|
||||
.pr_unsubscribe(&session, &path.workspace_name, &path.repo_name, path.number)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new("Unsubscribed".to_string())))
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, utoipa::ToSchema)]
|
||||
pub struct MutePrParams {
|
||||
/// Whether to mute (true) or unmute (false) notifications
|
||||
pub muted: bool,
|
||||
}
|
||||
|
||||
/// Mute or unmute notifications for a PR
|
||||
#[utoipa::path(
|
||||
put,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/prs/{number}/mute",
|
||||
tag = "Pull Requests",
|
||||
operation_id = "prMute",
|
||||
params(PrPath),
|
||||
request_body(content = MutePrParams, description = "Mute/unmute parameters", content_type = "application/json"),
|
||||
responses(
|
||||
(status = 200, description = "Mute status updated.", body = ApiResponse<String>),
|
||||
(status = 401, description = "Authentication required", body = ApiErrorResponse),
|
||||
(status = 404, description = "Not subscribed", body = ApiErrorResponse),
|
||||
(status = 500, description = "Internal server error", body = ApiErrorResponse),
|
||||
),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn mute(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PrPath>,
|
||||
params: web::Json<MutePrParams>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
service
|
||||
.pr
|
||||
.pr_mute(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
path.number,
|
||||
params.muted,
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new("Mute status updated".to_string())))
|
||||
}
|
||||
Reference in New Issue
Block a user