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
+19 -29
View File
@@ -4,36 +4,21 @@ use utoipa::IntoParams;
use crate::api::response::{ApiErrorResponse, ApiResponse};
use crate::error::AppError;
use crate::models::repos::RepoBranch;
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 {
/// Maximum number of branches to return (default: 50, max: 100)
pub limit: Option<i64>,
/// Number of branches to skip for pagination (default: 0)
pub offset: Option<i64>,
}
/// List branches in a repository
///
/// Returns a paginated list of all branches in the repository, sorted by name alphabetically.
/// Includes branch metadata such as:
/// - Branch name and commit SHA
/// - Protected status
/// - Default branch flag
/// - Last push information
///
/// Requires read access to the repository.
#[utoipa::path(
get,
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/branches",
@@ -41,15 +26,11 @@ pub struct QueryParams {
operation_id = "repoListBranches",
params(PathParams, QueryParams),
responses(
(status = 200, description = "Branches listed successfully. Returns an array of branch objects with metadata.", body = ApiResponse<Vec<RepoBranch>>),
(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),
(status = 200, description = "Branches listed successfully", body = ApiResponse<crate::pb::repo::ListBranchesResponse>),
(status = 401, description = "Authentication required", body = ApiErrorResponse),
(status = 404, description = "Repository not found", body = ApiErrorResponse),
),
security(
("session_cookie" = [])
)
security(("session_cookie" = []))
)]
pub async fn list_branches(
service: web::Data<AppService>,
@@ -57,16 +38,25 @@ pub async fn list_branches(
path: web::Path<PathParams>,
query: web::Query<QueryParams>,
) -> Result<HttpResponse, AppError> {
let branches = service
let limit = query.limit.unwrap_or(50).clamp(1, 100);
let offset = query.offset.unwrap_or(0).max(0);
let page_size = limit as u32;
let page_token = if offset > 0 {
format!("{offset}")
} else {
String::new()
};
let result = service
.repo
.repo_branches(
.git_list_branches(
&session,
&path.workspace_name,
&path.repo_name,
query.limit.unwrap_or(50),
query.offset.unwrap_or(0),
None,
page_size,
Some(page_token),
)
.await?;
Ok(HttpResponse::Ok().json(ApiResponse::new(branches)))
Ok(HttpResponse::Ok().json(ApiResponse::new(result)))
}