feat(api): expand API endpoints for repo, PR, user, workspace management

- Add git operation endpoints: archive, compare branches, diff, tree,
  repository extras
- Add repo endpoints: contributors, delete fork, get branch/commit
  status/deploy key/invitation/member/release/tag/webhook, topics,
  release assets, webhook deliveries/retry
- Add PR endpoints: review requests, templates
- Add user endpoints: block/unblock, follow/unfollow, presence,
  personal access tokens, account restore
- Add workspace endpoints: billing history, approvals, domains,
  integrations, invitations, members, webhooks, restore
- Add internal API, notification API, IM API modules
- Update route configuration and OpenAPI spec
This commit is contained in:
zhenyi
2026-06-10 18:49:27 +08:00
parent 4586b79cb8
commit cec6dce955
161 changed files with 7522 additions and 349 deletions
+23 -36
View File
@@ -9,52 +9,29 @@ 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,
/// Branch ID (UUID)
pub branch_id: uuid::Uuid,
pub branch_name: String,
}
#[derive(Debug, Deserialize, ToSchema)]
pub struct SetBranchProtectionParams {
/// Whether to enable branch protection
pub protected: bool,
}
/// Set branch protection
///
/// Enables or disables protection for a specific branch.
/// Requires Admin role or higher in the repository.
///
/// Effects:
/// - When enabled: prevents force pushes and branch deletion
/// - When disabled: allows force pushes and branch deletion
///
/// Returns success message on completion.
#[utoipa::path(
put,
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/branches/{branch_id}/protection",
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/branches/{branch_name}/protection",
tag = "Repos",
operation_id = "repoSetBranchProtection",
params(PathParams),
request_body(
content = SetBranchProtectionParams,
description = "Branch protection parameters",
content_type = "application/json"
),
request_body(content = SetBranchProtectionParams),
responses(
(status = 200, description = "Branch protection rules set successfully.", body = ApiResponse<String>),
(status = 400, description = "Invalid parameters: negative approvals count or conflicting protection settings", body = ApiErrorResponse),
(status = 401, description = "Authentication required or session expired", body = ApiErrorResponse),
(status = 403, description = "Insufficient permissions (requires Admin role or higher)", body = ApiErrorResponse),
(status = 404, description = "Repository, workspace, or branch not found", body = ApiErrorResponse),
(status = 500, description = "Internal server error", body = ApiErrorResponse),
(status = 200, description = "Branch protection set", body = ApiResponse<String>),
(status = 401, description = "Authentication required", body = ApiErrorResponse),
(status = 404, description = "Branch not found", body = ApiErrorResponse),
),
security(
("session_cookie" = [])
)
security(("session_cookie" = []))
)]
pub async fn set_branch_protection(
service: web::Data<AppService>,
@@ -62,18 +39,28 @@ pub async fn set_branch_protection(
path: web::Path<PathParams>,
params: web::Json<SetBranchProtectionParams>,
) -> Result<HttpResponse, AppError> {
service
// Verify branch exists via gRPC
let _ = service
.repo
.repo_set_branch_protection(
.git_get_branch(
&session,
&path.workspace_name,
&path.repo_name,
path.branch_id,
&path.branch_name,
)
.await?;
// Update DB protection flag (platform metadata, no gRPC equivalent)
service
.repo
.repo_set_branch_protection_by_name(
&session,
&path.workspace_name,
&path.repo_name,
&path.branch_name,
params.protected,
)
.await?;
Ok(HttpResponse::Ok().json(ApiResponse::new(
"Branch protection rules set successfully".to_string(),
)))
Ok(HttpResponse::Ok().json(ApiResponse::new("Branch protection updated".to_string())))
}