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,343 @@
|
||||
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::{PrReview, PrReviewComment};
|
||||
use crate::service::AppService;
|
||||
use crate::service::pr::reviews::{
|
||||
AddReplyParams, CreateReviewParams, DismissReviewParams, SubmitReviewParams,
|
||||
};
|
||||
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 ReviewPath {
|
||||
/// 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,
|
||||
/// Review ID (UUID)
|
||||
pub review_id: uuid::Uuid,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct CommentPath {
|
||||
/// 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,
|
||||
/// Comment ID (UUID)
|
||||
pub comment_id: uuid::Uuid,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct QP {
|
||||
pub limit: Option<i64>,
|
||||
pub offset: Option<i64>,
|
||||
}
|
||||
|
||||
/// List reviews on a PR
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/prs/{number}/reviews",
|
||||
tag = "Pull Requests",
|
||||
operation_id = "prListReviews",
|
||||
params(PrPath, QP),
|
||||
responses(
|
||||
(status = 200, description = "Reviews listed.", body = ApiResponse<Vec<PrReview>>),
|
||||
(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_reviews(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PrPath>,
|
||||
query: web::Query<QP>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let reviews = service
|
||||
.pr
|
||||
.pr_list_reviews(
|
||||
&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(reviews)))
|
||||
}
|
||||
|
||||
/// Create a review. States: pending, approved, changes_requested, commented. Authors cannot approve their own PRs.
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/prs/{number}/reviews",
|
||||
tag = "Pull Requests",
|
||||
operation_id = "prCreateReview",
|
||||
params(PrPath),
|
||||
request_body(content = CreateReviewParams, description = "Review parameters", content_type = "application/json"),
|
||||
responses(
|
||||
(status = 201, description = "Review created.", body = ApiResponse<PrReview>),
|
||||
(status = 400, description = "Invalid state or self-approval", 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_review(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PrPath>,
|
||||
params: web::Json<CreateReviewParams>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let review = service
|
||||
.pr
|
||||
.pr_create_review(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
path.number,
|
||||
params.into_inner(),
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Created().json(ApiResponse::new(review)))
|
||||
}
|
||||
|
||||
/// Submit a pending review. Changes its state to approved, changes_requested, or commented.
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/prs/{number}/reviews/{review_id}/submit",
|
||||
tag = "Pull Requests",
|
||||
operation_id = "prSubmitReview",
|
||||
params(ReviewPath),
|
||||
request_body(content = SubmitReviewParams, description = "Submit parameters", content_type = "application/json"),
|
||||
responses(
|
||||
(status = 200, description = "Review submitted.", body = ApiResponse<PrReview>),
|
||||
(status = 400, description = "Invalid state or self-approval", body = ApiErrorResponse),
|
||||
(status = 401, description = "Authentication required", body = ApiErrorResponse),
|
||||
(status = 403, description = "Insufficient permissions", body = ApiErrorResponse),
|
||||
(status = 404, description = "Review not found or already submitted", body = ApiErrorResponse),
|
||||
(status = 500, description = "Internal server error", body = ApiErrorResponse),
|
||||
),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn submit_review(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<ReviewPath>,
|
||||
params: web::Json<SubmitReviewParams>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let review = service
|
||||
.pr
|
||||
.pr_submit_review(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
path.number,
|
||||
path.review_id,
|
||||
params.into_inner(),
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(review)))
|
||||
}
|
||||
|
||||
/// Dismiss a submitted review. Requires Admin role.
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/prs/{number}/reviews/{review_id}/dismiss",
|
||||
tag = "Pull Requests",
|
||||
operation_id = "prDismissReview",
|
||||
params(ReviewPath),
|
||||
request_body(content = DismissReviewParams, description = "Dismiss parameters", content_type = "application/json"),
|
||||
responses(
|
||||
(status = 200, description = "Review dismissed.", body = ApiResponse<PrReview>),
|
||||
(status = 401, description = "Authentication required", body = ApiErrorResponse),
|
||||
(status = 403, description = "Insufficient permissions (Admin required)", body = ApiErrorResponse),
|
||||
(status = 404, description = "Review not found or not submitted", body = ApiErrorResponse),
|
||||
(status = 500, description = "Internal server error", body = ApiErrorResponse),
|
||||
),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn dismiss_review(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<ReviewPath>,
|
||||
params: web::Json<DismissReviewParams>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let review = service
|
||||
.pr
|
||||
.pr_dismiss_review(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
path.number,
|
||||
path.review_id,
|
||||
params.into_inner(),
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(review)))
|
||||
}
|
||||
|
||||
/// List comments for a specific review
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/prs/{number}/reviews/{review_id}/comments",
|
||||
tag = "Pull Requests",
|
||||
operation_id = "prListReviewComments",
|
||||
params(ReviewPath, QP),
|
||||
responses(
|
||||
(status = 200, description = "Review comments listed.", body = ApiResponse<Vec<PrReviewComment>>),
|
||||
(status = 401, description = "Authentication required", body = ApiErrorResponse),
|
||||
(status = 404, description = "Review not found", body = ApiErrorResponse),
|
||||
(status = 500, description = "Internal server error", body = ApiErrorResponse),
|
||||
),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn list_review_comments(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<ReviewPath>,
|
||||
query: web::Query<QP>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let comments = service
|
||||
.pr
|
||||
.pr_review_comments(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
path.number,
|
||||
path.review_id,
|
||||
query.limit.unwrap_or(50),
|
||||
query.offset.unwrap_or(0),
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(comments)))
|
||||
}
|
||||
|
||||
/// Reply to a review comment
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/prs/{number}/comments/{comment_id}/reply",
|
||||
tag = "Pull Requests",
|
||||
operation_id = "prAddReviewReply",
|
||||
params(CommentPath),
|
||||
request_body(content = AddReplyParams, description = "Reply parameters", content_type = "application/json"),
|
||||
responses(
|
||||
(status = 201, description = "Reply added.", body = ApiResponse<PrReviewComment>),
|
||||
(status = 400, description = "Empty body", body = ApiErrorResponse),
|
||||
(status = 401, description = "Authentication required", body = ApiErrorResponse),
|
||||
(status = 404, description = "Comment not found", body = ApiErrorResponse),
|
||||
(status = 500, description = "Internal server error", body = ApiErrorResponse),
|
||||
),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn add_review_reply(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<CommentPath>,
|
||||
params: web::Json<AddReplyParams>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let comment = service
|
||||
.pr
|
||||
.pr_add_review_reply(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
path.number,
|
||||
path.comment_id,
|
||||
params.into_inner(),
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Created().json(ApiResponse::new(comment)))
|
||||
}
|
||||
|
||||
/// Update a review comment (own comments only)
|
||||
#[utoipa::path(
|
||||
put,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/prs/{number}/comments/{comment_id}",
|
||||
tag = "Pull Requests",
|
||||
operation_id = "prUpdateReviewComment",
|
||||
params(CommentPath),
|
||||
request_body(content = AddReplyParams, description = "Update parameters", content_type = "application/json"),
|
||||
responses(
|
||||
(status = 200, description = "Comment updated.", body = ApiResponse<PrReviewComment>),
|
||||
(status = 401, description = "Authentication required", body = ApiErrorResponse),
|
||||
(status = 403, description = "Cannot edit other users' comments", body = ApiErrorResponse),
|
||||
(status = 404, description = "Comment not found", body = ApiErrorResponse),
|
||||
(status = 500, description = "Internal server error", body = ApiErrorResponse),
|
||||
),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn update_review_comment(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<CommentPath>,
|
||||
params: web::Json<AddReplyParams>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let comment = service
|
||||
.pr
|
||||
.pr_update_review_comment(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
path.number,
|
||||
path.comment_id,
|
||||
params.into_inner(),
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(comment)))
|
||||
}
|
||||
|
||||
/// Delete a review comment. Own comments or Admin role.
|
||||
#[utoipa::path(
|
||||
delete,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/prs/{number}/comments/{comment_id}",
|
||||
tag = "Pull Requests",
|
||||
operation_id = "prDeleteReviewComment",
|
||||
params(CommentPath),
|
||||
responses(
|
||||
(status = 200, description = "Comment deleted.", body = ApiResponse<String>),
|
||||
(status = 401, description = "Authentication required", body = ApiErrorResponse),
|
||||
(status = 403, description = "Cannot delete other users' comments (Admin required)", body = ApiErrorResponse),
|
||||
(status = 404, description = "Comment not found", body = ApiErrorResponse),
|
||||
(status = 500, description = "Internal server error", body = ApiErrorResponse),
|
||||
),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn delete_review_comment(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<CommentPath>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
service
|
||||
.pr
|
||||
.pr_delete_review_comment(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
path.number,
|
||||
path.comment_id,
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new("Comment deleted".to_string())))
|
||||
}
|
||||
Reference in New Issue
Block a user