Files
appks/api/repo/git/git_commit_extras2.rs
zhenyi cec6dce955 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
2026-06-10 18:49:27 +08:00

138 lines
4.9 KiB
Rust

use crate::api::response::ApiResponse;
use crate::error::AppError;
use crate::service::AppService;
use crate::session::Session;
use actix_web::{HttpResponse, web};
use serde::Deserialize;
use utoipa::IntoParams;
#[derive(Debug, Deserialize, IntoParams)]
pub struct PathParams {
pub workspace_name: String,
pub repo_name: String,
}
#[derive(Debug, Deserialize, IntoParams)]
pub struct RevisionPathParams {
pub workspace_name: String,
pub repo_name: String,
pub revision: String,
}
#[derive(Debug, Deserialize, IntoParams)]
pub struct FindCommitQuery {
pub revision: String,
}
#[utoipa::path(get, path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/find-commit", tag = "Git", operation_id = "gitFindCommit", params(PathParams, FindCommitQuery), responses((status=200,body=ApiResponse<crate::pb::repo::Commit>)), security(("session_cookie"=[])))]
pub async fn git_find_commit(
service: web::Data<AppService>,
session: Session,
path: web::Path<PathParams>,
q: web::Query<FindCommitQuery>,
) -> Result<HttpResponse, AppError> {
let r = service
.repo
.git_find_commit(&session, &path.workspace_name, &path.repo_name, &q.revision)
.await?;
Ok(HttpResponse::Ok().json(ApiResponse::new(r)))
}
#[derive(Debug, Deserialize, utoipa::ToSchema)]
pub struct ListCommitsByOidBody {
pub oids: Vec<String>,
}
#[utoipa::path(post, path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/commits/by-oid", tag = "Git", operation_id = "gitCommitsByOid", params(PathParams), request_body(content=ListCommitsByOidBody), responses((status=200,body=ApiResponse<crate::pb::repo::ListCommitsByOidResponse>)), security(("session_cookie"=[])))]
pub async fn git_commits_by_oid(
service: web::Data<AppService>,
session: Session,
path: web::Path<PathParams>,
body: web::Json<ListCommitsByOidBody>,
) -> Result<HttpResponse, AppError> {
let oids: Vec<Vec<u8>> = body
.oids
.iter()
.map(|s| hex::decode(s).unwrap_or_default())
.collect();
let r = service
.repo
.git_list_commits_by_oid(&session, &path.workspace_name, &path.repo_name, oids)
.await?;
Ok(HttpResponse::Ok().json(ApiResponse::new(r)))
}
#[derive(Debug, Deserialize, IntoParams)]
pub struct AncestorQuery {
pub ancestor: String,
pub descendant: String,
}
#[utoipa::path(get, path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/commit-is-ancestor", tag = "Git", operation_id = "gitCommitIsAncestor", params(PathParams, AncestorQuery), responses((status=200,body=ApiResponse<bool>)), security(("session_cookie"=[])))]
pub async fn git_commit_is_ancestor(
service: web::Data<AppService>,
session: Session,
path: web::Path<PathParams>,
q: web::Query<AncestorQuery>,
) -> Result<HttpResponse, AppError> {
let r = service
.repo
.git_commit_is_ancestor(
&session,
&path.workspace_name,
&path.repo_name,
&q.ancestor,
&q.descendant,
)
.await?;
Ok(HttpResponse::Ok().json(ApiResponse::new(r)))
}
#[derive(Debug, Deserialize, IntoParams)]
pub struct LastCommitQuery {
pub path: String,
pub revision: Option<String>,
}
#[utoipa::path(get, path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/last-commit", tag = "Git", operation_id = "gitLastCommitForPath", params(PathParams, LastCommitQuery), responses((status=200,body=ApiResponse<crate::pb::repo::LastCommitForPathResponse>)), security(("session_cookie"=[])))]
pub async fn git_last_commit(
service: web::Data<AppService>,
session: Session,
path: web::Path<PathParams>,
q: web::Query<LastCommitQuery>,
) -> Result<HttpResponse, AppError> {
let r = service
.repo
.git_last_commit_for_path(
&session,
&path.workspace_name,
&path.repo_name,
&q.path,
q.revision.as_deref(),
)
.await?;
Ok(HttpResponse::Ok().json(ApiResponse::new(r)))
}
#[derive(Debug, Deserialize, IntoParams)]
pub struct CommitsByMsgQuery {
pub q: String,
pub revision: Option<String>,
pub limit: Option<u32>,
}
#[utoipa::path(get, path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/commits/search", tag = "Git", operation_id = "gitCommitsByMessage", params(PathParams, CommitsByMsgQuery), responses((status=200,body=ApiResponse<crate::pb::repo::CommitsByMessageResponse>)), security(("session_cookie"=[])))]
pub async fn git_commits_by_message(
service: web::Data<AppService>,
session: Session,
path: web::Path<PathParams>,
q: web::Query<CommitsByMsgQuery>,
) -> Result<HttpResponse, AppError> {
let r = service
.repo
.git_commits_by_message(
&session,
&path.workspace_name,
&path.repo_name,
&q.q,
q.revision.as_deref(),
q.limit.unwrap_or(20),
)
.await?;
Ok(HttpResponse::Ok().json(ApiResponse::new(r)))
}