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:
zhenyi
2026-06-07 23:01:05 +08:00
parent 3a22c4265d
commit d98e4d59e3
38 changed files with 40821 additions and 53 deletions
+79
View File
@@ -0,0 +1,79 @@
use actix_web::{HttpResponse, web};
use serde::{Deserialize, Serialize};
use utoipa::{IntoParams, ToSchema};
use crate::api::response::{ApiErrorResponse, ApiResponse};
use crate::error::AppError;
use crate::models::wiki::WikiPageRevision;
use crate::service::AppService;
use crate::session::Session;
#[derive(Debug, Deserialize, IntoParams)]
pub struct PathParams {
/// Workspace name (unique identifier)
pub workspace_name: String,
/// Repository name (unique within the workspace)
pub repo_name: String,
/// Wiki page slug (URL-friendly identifier)
pub slug: String,
}
#[derive(Debug, Deserialize, IntoParams)]
pub struct QueryParams {
/// Older version number to compare from
pub old_version: i32,
/// Newer version number to compare to
pub new_version: i32,
}
/// Result of comparing two wiki page revisions
#[derive(Debug, Serialize, Deserialize, ToSchema)]
pub struct WikiCompareResult {
/// The older revision being compared
pub old: WikiPageRevision,
/// The newer revision being compared
pub new: WikiPageRevision,
}
/// Compare two wiki page revisions
///
/// Compares two versions of a wiki page and returns both revisions.
/// Requires read access to the repository.
///
/// Returns the old and new revisions for client-side diff computation.
/// The client can compute the diff between the two content snapshots.
#[utoipa::path(
get,
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/wiki/{slug}/compare",
tag = "Wiki",
operation_id = "wikiCompareRevisions",
params(PathParams, QueryParams),
responses(
(status = 200, description = "Revisions compared successfully. Returns old and new revision objects.", body = ApiResponse<WikiCompareResult>),
(status = 400, description = "Invalid version numbers", body = ApiErrorResponse),
(status = 401, description = "Authentication required or session expired", body = ApiErrorResponse),
(status = 403, description = "Insufficient permissions to access this repository", body = ApiErrorResponse),
(status = 404, description = "Wiki page, revisions, repository, or workspace not found", body = ApiErrorResponse),
(status = 500, description = "Internal server error", body = ApiErrorResponse),
),
security(("session_cookie" = []))
)]
pub async fn compare_revisions(
service: web::Data<AppService>,
session: Session,
path: web::Path<PathParams>,
query: web::Query<QueryParams>,
) -> Result<HttpResponse, AppError> {
let (old, new) = service
.repo
.wiki_compare_revisions(
&session,
&path.workspace_name,
&path.repo_name,
&path.slug,
query.old_version,
query.new_version,
)
.await?;
Ok(HttpResponse::Ok().json(ApiResponse::new(WikiCompareResult { old, new })))
}
+66
View File
@@ -0,0 +1,66 @@
use actix_web::{HttpResponse, web};
use serde::Deserialize;
use utoipa::IntoParams;
use crate::api::response::{ApiErrorResponse, ApiResponse};
use crate::error::AppError;
use crate::models::wiki::WikiPage;
use crate::service::AppService;
use crate::service::wiki::core::CreateWikiPageParams;
use crate::session::Session;
#[derive(Debug, Deserialize, IntoParams)]
pub struct PathParams {
/// Workspace name (unique identifier)
pub workspace_name: String,
/// Repository name (unique within the workspace)
pub repo_name: String,
}
/// Create a wiki page
///
/// Creates a new wiki page in the repository.
/// Requires at least Member role in the repository.
///
/// The title is automatically converted to a URL-friendly slug.
/// An initial revision is created with the page.
///
/// Returns the created wiki page with full metadata.
#[utoipa::path(
post,
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/wiki",
tag = "Wiki",
operation_id = "wikiCreatePage",
params(PathParams),
request_body(
content = CreateWikiPageParams,
description = "Wiki page creation parameters",
content_type = "application/json"
),
responses(
(status = 201, description = "Wiki page created successfully.", body = ApiResponse<WikiPage>),
(status = 400, description = "Invalid parameters: empty title or content", body = ApiErrorResponse),
(status = 401, description = "Authentication required or session expired", body = ApiErrorResponse),
(status = 403, description = "Insufficient permissions (requires Member role or higher)", body = ApiErrorResponse),
(status = 404, description = "Repository or workspace not found", body = ApiErrorResponse),
(status = 500, description = "Internal server error", body = ApiErrorResponse),
),
security(("session_cookie" = []))
)]
pub async fn create_page(
service: web::Data<AppService>,
session: Session,
path: web::Path<PathParams>,
params: web::Json<CreateWikiPageParams>,
) -> Result<HttpResponse, AppError> {
let page = service
.repo
.wiki_create_page(
&session,
&path.workspace_name,
&path.repo_name,
params.into_inner(),
)
.await?;
Ok(HttpResponse::Created().json(ApiResponse::new(page)))
}
+54
View File
@@ -0,0 +1,54 @@
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::session::Session;
#[derive(Debug, Deserialize, IntoParams)]
pub struct PathParams {
/// Workspace name (unique identifier)
pub workspace_name: String,
/// Repository name (unique within the workspace)
pub repo_name: String,
/// Wiki page slug (URL-friendly identifier)
pub slug: String,
}
/// Delete a wiki page
///
/// Soft-deletes a wiki page. The page is marked as deleted but remains in the database.
/// Requires Admin role in the repository.
///
/// The page and its revision history are preserved but no longer accessible via the API.
/// Returns success message on completion.
#[utoipa::path(
delete,
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/wiki/{slug}",
tag = "Wiki",
operation_id = "wikiDeletePage",
params(PathParams),
responses(
(status = 200, description = "Wiki page deleted successfully.", body = ApiResponse<String>),
(status = 401, description = "Authentication required or session expired", body = ApiErrorResponse),
(status = 403, description = "Insufficient permissions (requires Admin role)", body = ApiErrorResponse),
(status = 404, description = "Wiki page, repository, or workspace not found", body = ApiErrorResponse),
(status = 500, description = "Internal server error", body = ApiErrorResponse),
),
security(("session_cookie" = []))
)]
pub async fn delete_page(
service: web::Data<AppService>,
session: Session,
path: web::Path<PathParams>,
) -> Result<HttpResponse, AppError> {
service
.repo
.wiki_delete_page(&session, &path.workspace_name, &path.repo_name, &path.slug)
.await?;
Ok(HttpResponse::Ok().json(ApiResponse::new(
"Wiki page deleted successfully".to_string(),
)))
}
+50
View File
@@ -0,0 +1,50 @@
use actix_web::{HttpResponse, web};
use serde::Deserialize;
use utoipa::IntoParams;
use crate::api::response::{ApiErrorResponse, ApiResponse};
use crate::error::AppError;
use crate::models::wiki::WikiPage;
use crate::service::AppService;
use crate::session::Session;
#[derive(Debug, Deserialize, IntoParams)]
pub struct PathParams {
/// Workspace name (unique identifier)
pub workspace_name: String,
/// Repository name (unique within the workspace)
pub repo_name: String,
/// Wiki page slug (URL-friendly identifier)
pub slug: String,
}
/// Get a wiki page
///
/// Retrieves a single wiki page by its slug.
/// Requires read access to the repository.
#[utoipa::path(
get,
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/wiki/{slug}",
tag = "Wiki",
operation_id = "wikiGetPage",
params(PathParams),
responses(
(status = 200, description = "Wiki page retrieved successfully.", body = ApiResponse<WikiPage>),
(status = 401, description = "Authentication required or session expired", body = ApiErrorResponse),
(status = 403, description = "Insufficient permissions to access this repository", body = ApiErrorResponse),
(status = 404, description = "Wiki page, repository, or workspace not found", body = ApiErrorResponse),
(status = 500, description = "Internal server error", body = ApiErrorResponse),
),
security(("session_cookie" = []))
)]
pub async fn get_page(
service: web::Data<AppService>,
session: Session,
path: web::Path<PathParams>,
) -> Result<HttpResponse, AppError> {
let page = service
.repo
.wiki_get_page(&session, &path.workspace_name, &path.repo_name, &path.slug)
.await?;
Ok(HttpResponse::Ok().json(ApiResponse::new(page)))
}
+60
View File
@@ -0,0 +1,60 @@
use actix_web::{HttpResponse, web};
use serde::Deserialize;
use utoipa::IntoParams;
use crate::api::response::{ApiErrorResponse, ApiResponse};
use crate::error::AppError;
use crate::models::wiki::WikiPageRevision;
use crate::service::AppService;
use crate::session::Session;
#[derive(Debug, Deserialize, IntoParams)]
pub struct PathParams {
/// Workspace name (unique identifier)
pub workspace_name: String,
/// Repository name (unique within the workspace)
pub repo_name: String,
/// Wiki page slug (URL-friendly identifier)
pub slug: String,
/// Revision version number
pub version: i32,
}
/// Get a specific wiki page revision
///
/// Retrieves a specific revision of a wiki page by version number.
/// Requires read access to the repository.
///
/// Returns the full revision with content snapshot, editor, and commit message.
#[utoipa::path(
get,
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/wiki/{slug}/revisions/{version}",
tag = "Wiki",
operation_id = "wikiGetRevision",
params(PathParams),
responses(
(status = 200, description = "Revision retrieved successfully.", body = ApiResponse<WikiPageRevision>),
(status = 401, description = "Authentication required or session expired", body = ApiErrorResponse),
(status = 403, description = "Insufficient permissions to access this repository", body = ApiErrorResponse),
(status = 404, description = "Wiki page, revision, repository, or workspace not found", body = ApiErrorResponse),
(status = 500, description = "Internal server error", body = ApiErrorResponse),
),
security(("session_cookie" = []))
)]
pub async fn get_revision(
service: web::Data<AppService>,
session: Session,
path: web::Path<PathParams>,
) -> Result<HttpResponse, AppError> {
let revision = service
.repo
.wiki_get_revision(
&session,
&path.workspace_name,
&path.repo_name,
&path.slug,
path.version,
)
.await?;
Ok(HttpResponse::Ok().json(ApiResponse::new(revision)))
}
+67
View File
@@ -0,0 +1,67 @@
use actix_web::{HttpResponse, web};
use serde::Deserialize;
use utoipa::IntoParams;
use crate::api::response::{ApiErrorResponse, ApiResponse};
use crate::error::AppError;
use crate::models::wiki::WikiPage;
use crate::service::AppService;
use crate::session::Session;
#[derive(Debug, Deserialize, IntoParams)]
pub struct PathParams {
/// Workspace name (unique identifier)
pub workspace_name: String,
/// Repository name (unique within the workspace)
pub repo_name: String,
}
#[derive(Debug, Deserialize, IntoParams)]
pub struct QueryParams {
/// Search query to filter pages by title or content
pub search: Option<String>,
/// Maximum number of pages to return (default: 50, max: 100)
pub limit: Option<i64>,
/// Number of pages to skip for pagination (default: 0)
pub offset: Option<i64>,
}
/// List wiki pages in a repository
///
/// Returns a paginated list of all wiki pages in the repository.
/// Supports searching by title or content.
/// Requires read access to the repository.
#[utoipa::path(
get,
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/wiki",
tag = "Wiki",
operation_id = "wikiListPages",
params(PathParams, QueryParams),
responses(
(status = 200, description = "Wiki pages listed successfully.", body = ApiResponse<Vec<WikiPage>>),
(status = 401, description = "Authentication required or session expired", body = ApiErrorResponse),
(status = 403, description = "Insufficient permissions to access this repository", body = ApiErrorResponse),
(status = 404, description = "Repository or workspace not found", body = ApiErrorResponse),
(status = 500, description = "Internal server error", body = ApiErrorResponse),
),
security(("session_cookie" = []))
)]
pub async fn list_pages(
service: web::Data<AppService>,
session: Session,
path: web::Path<PathParams>,
query: web::Query<QueryParams>,
) -> Result<HttpResponse, AppError> {
let pages = service
.repo
.wiki_list_pages(
&session,
&path.workspace_name,
&path.repo_name,
query.search.clone(),
query.limit.unwrap_or(50),
query.offset.unwrap_or(0),
)
.await?;
Ok(HttpResponse::Ok().json(ApiResponse::new(pages)))
}
+69
View File
@@ -0,0 +1,69 @@
use actix_web::{HttpResponse, web};
use serde::Deserialize;
use utoipa::IntoParams;
use crate::api::response::{ApiErrorResponse, ApiResponse};
use crate::error::AppError;
use crate::models::wiki::WikiPageRevision;
use crate::service::AppService;
use crate::session::Session;
#[derive(Debug, Deserialize, IntoParams)]
pub struct PathParams {
/// Workspace name (unique identifier)
pub workspace_name: String,
/// Repository name (unique within the workspace)
pub repo_name: String,
/// Wiki page slug (URL-friendly identifier)
pub slug: String,
}
#[derive(Debug, Deserialize, IntoParams)]
pub struct QueryParams {
/// Maximum number of revisions to return (default: 50, max: 100)
pub limit: Option<i64>,
/// Number of revisions to skip for pagination (default: 0)
pub offset: Option<i64>,
}
/// List wiki page revisions
///
/// Returns a paginated list of all revisions for a wiki page, sorted by version (newest first).
/// Requires read access to the repository.
///
/// Each revision includes the full content snapshot at that version,
/// the editor who made the change, and an optional commit message.
#[utoipa::path(
get,
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/wiki/{slug}/revisions",
tag = "Wiki",
operation_id = "wikiListRevisions",
params(PathParams, QueryParams),
responses(
(status = 200, description = "Revisions listed successfully.", body = ApiResponse<Vec<WikiPageRevision>>),
(status = 401, description = "Authentication required or session expired", body = ApiErrorResponse),
(status = 403, description = "Insufficient permissions to access this repository", body = ApiErrorResponse),
(status = 404, description = "Wiki page, repository, or workspace not found", body = ApiErrorResponse),
(status = 500, description = "Internal server error", body = ApiErrorResponse),
),
security(("session_cookie" = []))
)]
pub async fn list_revisions(
service: web::Data<AppService>,
session: Session,
path: web::Path<PathParams>,
query: web::Query<QueryParams>,
) -> Result<HttpResponse, AppError> {
let revisions = service
.repo
.wiki_get_revisions(
&session,
&path.workspace_name,
&path.repo_name,
&path.slug,
query.limit.unwrap_or(50),
query.offset.unwrap_or(0),
)
.await?;
Ok(HttpResponse::Ok().json(ApiResponse::new(revisions)))
}
+38
View File
@@ -0,0 +1,38 @@
pub mod compare_revisions;
pub mod create_page;
pub mod delete_page;
pub mod get_page;
pub mod get_revision;
pub mod list_pages;
pub mod list_revisions;
pub mod revert_page;
pub mod update_page;
use actix_web::web;
/// Configure wiki routes under `/workspaces/{workspace_name}/repos/{repo_name}/wiki`
pub fn configure(cfg: &mut web::ServiceConfig) {
cfg.service(
web::scope("/wiki")
// Pages
.route("", web::get().to(list_pages::list_pages))
.route("", web::post().to(create_page::create_page))
.route("/{slug}", web::get().to(get_page::get_page))
.route("/{slug}", web::put().to(update_page::update_page))
.route("/{slug}", web::delete().to(delete_page::delete_page))
.route("/{slug}/revert", web::post().to(revert_page::revert_page))
// Revisions
.route(
"/{slug}/revisions",
web::get().to(list_revisions::list_revisions),
)
.route(
"/{slug}/revisions/{version}",
web::get().to(get_revision::get_revision),
)
.route(
"/{slug}/compare",
web::get().to(compare_revisions::compare_revisions),
),
);
}
+72
View File
@@ -0,0 +1,72 @@
use actix_web::{HttpResponse, web};
use serde::Deserialize;
use utoipa::IntoParams;
use crate::api::response::{ApiErrorResponse, ApiResponse};
use crate::error::AppError;
use crate::models::wiki::WikiPage;
use crate::service::AppService;
use crate::session::Session;
#[derive(Debug, Deserialize, IntoParams)]
pub struct PathParams {
/// Workspace name (unique identifier)
pub workspace_name: String,
/// Repository name (unique within the workspace)
pub repo_name: String,
/// Wiki page slug (URL-friendly identifier)
pub slug: String,
}
#[derive(Debug, Deserialize, IntoParams)]
pub struct QueryParams {
/// Target version number to revert to
pub version: i32,
/// Optional commit message describing the revert
pub commit_message: Option<String>,
}
/// Revert a wiki page to a historical version
///
/// Reverts the wiki page to a specified historical version.
/// Requires at least Member role in the repository.
///
/// This creates a new revision with the content from the target version.
/// The current content is not lost; it remains in the revision history.
///
/// Returns the updated wiki page with the reverted content.
#[utoipa::path(
post,
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/wiki/{slug}/revert",
tag = "Wiki",
operation_id = "wikiRevertPage",
params(PathParams, QueryParams),
responses(
(status = 200, description = "Wiki page reverted successfully.", body = ApiResponse<WikiPage>),
(status = 400, description = "Invalid version number", body = ApiErrorResponse),
(status = 401, description = "Authentication required or session expired", body = ApiErrorResponse),
(status = 403, description = "Insufficient permissions (requires Member role or higher)", body = ApiErrorResponse),
(status = 404, description = "Wiki page, revision, repository, or workspace not found", body = ApiErrorResponse),
(status = 500, description = "Internal server error", body = ApiErrorResponse),
),
security(("session_cookie" = []))
)]
pub async fn revert_page(
service: web::Data<AppService>,
session: Session,
path: web::Path<PathParams>,
query: web::Query<QueryParams>,
) -> Result<HttpResponse, AppError> {
let page = service
.repo
.wiki_revert_to_version(
&session,
&path.workspace_name,
&path.repo_name,
&path.slug,
query.version,
query.commit_message.clone(),
)
.await?;
Ok(HttpResponse::Ok().json(ApiResponse::new(page)))
}
+70
View File
@@ -0,0 +1,70 @@
use actix_web::{HttpResponse, web};
use serde::Deserialize;
use utoipa::IntoParams;
use crate::api::response::{ApiErrorResponse, ApiResponse};
use crate::error::AppError;
use crate::models::wiki::WikiPage;
use crate::service::AppService;
use crate::service::wiki::core::UpdateWikiPageParams;
use crate::session::Session;
#[derive(Debug, Deserialize, IntoParams)]
pub struct PathParams {
/// Workspace name (unique identifier)
pub workspace_name: String,
/// Repository name (unique within the workspace)
pub repo_name: String,
/// Wiki page slug (URL-friendly identifier)
pub slug: String,
}
/// Update a wiki page
///
/// Updates an existing wiki page's title, content, or both.
/// Requires at least Member role in the repository.
///
/// A new revision is automatically created with the changes.
/// Optionally include a commit message to describe the changes.
///
/// All fields are optional; only provided fields are updated.
/// Returns the updated wiki page.
#[utoipa::path(
put,
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/wiki/{slug}",
tag = "Wiki",
operation_id = "wikiUpdatePage",
params(PathParams),
request_body(
content = UpdateWikiPageParams,
description = "Wiki page update parameters (all fields optional)",
content_type = "application/json"
),
responses(
(status = 200, description = "Wiki page updated successfully.", body = ApiResponse<WikiPage>),
(status = 400, description = "Invalid parameters", body = ApiErrorResponse),
(status = 401, description = "Authentication required or session expired", body = ApiErrorResponse),
(status = 403, description = "Insufficient permissions (requires Member role or higher)", body = ApiErrorResponse),
(status = 404, description = "Wiki page, repository, or workspace not found", body = ApiErrorResponse),
(status = 500, description = "Internal server error", body = ApiErrorResponse),
),
security(("session_cookie" = []))
)]
pub async fn update_page(
service: web::Data<AppService>,
session: Session,
path: web::Path<PathParams>,
params: web::Json<UpdateWikiPageParams>,
) -> Result<HttpResponse, AppError> {
let page = service
.repo
.wiki_update_page(
&session,
&path.workspace_name,
&path.repo_name,
&path.slug,
params.into_inner(),
)
.await?;
Ok(HttpResponse::Ok().json(ApiResponse::new(page)))
}