refactor(git): use DEFAULT_REVISION constant across git operations
- Replace 15 occurrences of unwrap_or("HEAD") with
unwrap_or(DEFAULT_REVISION) across 10 files
- All git API handlers and service methods now reference the shared
constant from models::common
This commit is contained in:
+20
-35
@@ -1,71 +1,56 @@
|
||||
use crate::models::common::DEFAULT_REVISION;
|
||||
use actix_web::{HttpResponse, web};
|
||||
use serde::Deserialize;
|
||||
use utoipa::IntoParams;
|
||||
|
||||
use crate::api::response::{ApiErrorResponse, ApiResponse};
|
||||
use crate::error::AppError;
|
||||
use crate::models::repos::RepoBranch;
|
||||
use crate::service::AppService;
|
||||
use crate::service::repo::branches::CreateBranchParams;
|
||||
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 new branch
|
||||
///
|
||||
/// Creates a new branch in the repository based on an existing commit or branch.
|
||||
/// Requires Write role or higher in the repository.
|
||||
///
|
||||
/// Parameters:
|
||||
/// - name: Branch name (1-100 characters, alphanumeric, hyphens, underscores, dots, slashes allowed)
|
||||
/// - from: Source branch name or commit SHA to branch from (defaults to default branch)
|
||||
///
|
||||
/// Returns the created branch with metadata including the initial commit SHA.
|
||||
#[derive(Debug, Deserialize, utoipa::ToSchema)]
|
||||
pub struct CreateBranchBody {
|
||||
pub name: String,
|
||||
pub start_point: Option<String>,
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/branches",
|
||||
tag = "Repos",
|
||||
operation_id = "repoCreateBranch",
|
||||
params(PathParams),
|
||||
request_body(
|
||||
content = CreateBranchParams,
|
||||
description = "Branch creation parameters",
|
||||
content_type = "application/json"
|
||||
),
|
||||
request_body(content = CreateBranchBody),
|
||||
responses(
|
||||
(status = 201, description = "Branch created successfully. Returns the newly created branch with metadata.", body = ApiResponse<RepoBranch>),
|
||||
(status = 400, description = "Invalid parameters: name too long, invalid characters, or source branch/commit doesn't exist", body = ApiErrorResponse),
|
||||
(status = 401, description = "Authentication required or session expired", body = ApiErrorResponse),
|
||||
(status = 403, description = "Insufficient permissions (requires Write role or higher)", body = ApiErrorResponse),
|
||||
(status = 404, description = "Repository, workspace, or source branch/commit not found", body = ApiErrorResponse),
|
||||
(status = 409, description = "Branch with this name already exists", body = ApiErrorResponse),
|
||||
(status = 500, description = "Internal server error or Git operation failed", body = ApiErrorResponse),
|
||||
(status = 201, description = "Branch created", body = ApiResponse<crate::pb::repo::Branch>),
|
||||
(status = 400, description = "Invalid parameters", body = ApiErrorResponse),
|
||||
(status = 401, description = "Authentication required", body = ApiErrorResponse),
|
||||
(status = 404, description = "Repository not found", body = ApiErrorResponse),
|
||||
),
|
||||
security(
|
||||
("session_cookie" = [])
|
||||
)
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn create_branch(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PathParams>,
|
||||
params: web::Json<CreateBranchParams>,
|
||||
body: web::Json<CreateBranchBody>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let branch = service
|
||||
let start_point = body.start_point.as_deref().unwrap_or(DEFAULT_REVISION);
|
||||
let result = service
|
||||
.repo
|
||||
.repo_create_branch(
|
||||
.git_create_branch(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
params.into_inner(),
|
||||
&body.name,
|
||||
start_point,
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(HttpResponse::Created().json(ApiResponse::new(branch)))
|
||||
Ok(HttpResponse::Created().json(ApiResponse::new(result)))
|
||||
}
|
||||
|
||||
+23
-36
@@ -1,72 +1,59 @@
|
||||
use crate::models::common::DEFAULT_REVISION;
|
||||
use actix_web::{HttpResponse, web};
|
||||
use serde::Deserialize;
|
||||
use utoipa::IntoParams;
|
||||
|
||||
use crate::api::response::{ApiErrorResponse, ApiResponse};
|
||||
use crate::error::AppError;
|
||||
use crate::models::repos::RepoTag;
|
||||
use crate::service::AppService;
|
||||
use crate::service::repo::tags::CreateTagParams;
|
||||
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 new tag
|
||||
///
|
||||
/// Creates a new tag in the repository pointing to a specific commit or branch.
|
||||
/// Requires Write role or higher in the repository.
|
||||
///
|
||||
/// Parameters:
|
||||
/// - name: Tag name (1-100 characters, typically follows semantic versioning like v1.0.0)
|
||||
/// - target: Commit SHA or branch name to tag (defaults to HEAD of default branch)
|
||||
/// - message: Optional tag message for annotated tags
|
||||
///
|
||||
/// Returns the created tag with metadata including the commit SHA.
|
||||
#[derive(Debug, Deserialize, utoipa::ToSchema)]
|
||||
pub struct CreateTagBody {
|
||||
pub name: String,
|
||||
pub target: Option<String>,
|
||||
pub message: Option<String>,
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/tags",
|
||||
tag = "Repos",
|
||||
operation_id = "repoCreateTag",
|
||||
params(PathParams),
|
||||
request_body(
|
||||
content = CreateTagParams,
|
||||
description = "Tag creation parameters",
|
||||
content_type = "application/json"
|
||||
),
|
||||
request_body(content = CreateTagBody),
|
||||
responses(
|
||||
(status = 201, description = "Tag created successfully. Returns the newly created tag with metadata.", body = ApiResponse<RepoTag>),
|
||||
(status = 400, description = "Invalid parameters: name too long, invalid characters, or target commit/branch doesn't exist", body = ApiErrorResponse),
|
||||
(status = 401, description = "Authentication required or session expired", body = ApiErrorResponse),
|
||||
(status = 403, description = "Insufficient permissions (requires Write role or higher)", body = ApiErrorResponse),
|
||||
(status = 404, description = "Repository, workspace, or target commit/branch not found", body = ApiErrorResponse),
|
||||
(status = 409, description = "Tag with this name already exists", body = ApiErrorResponse),
|
||||
(status = 500, description = "Internal server error or Git operation failed", body = ApiErrorResponse),
|
||||
(status = 201, description = "Tag created", body = ApiResponse<crate::pb::repo::Tag>),
|
||||
(status = 400, description = "Invalid parameters", body = ApiErrorResponse),
|
||||
(status = 401, description = "Authentication required", body = ApiErrorResponse),
|
||||
(status = 404, description = "Repository not found", body = ApiErrorResponse),
|
||||
),
|
||||
security(
|
||||
("session_cookie" = [])
|
||||
)
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn create_tag(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PathParams>,
|
||||
params: web::Json<CreateTagParams>,
|
||||
body: web::Json<CreateTagBody>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let tag = service
|
||||
let target = body.target.as_deref().unwrap_or(DEFAULT_REVISION);
|
||||
let result = service
|
||||
.repo
|
||||
.repo_create_tag(
|
||||
.git_create_tag(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
params.into_inner(),
|
||||
&body.name,
|
||||
target,
|
||||
body.message.clone(),
|
||||
body.message.is_some(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(HttpResponse::Created().json(ApiResponse::new(tag)))
|
||||
Ok(HttpResponse::Created().json(ApiResponse::new(result)))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
use crate::models::common::DEFAULT_REVISION;
|
||||
use actix_web::{HttpResponse, web};
|
||||
use serde::Deserialize;
|
||||
use utoipa::IntoParams;
|
||||
|
||||
use crate::api::response::ApiErrorResponse;
|
||||
use crate::error::AppError;
|
||||
use crate::service::AppService;
|
||||
use crate::session::Session;
|
||||
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct PathParams {
|
||||
pub workspace_name: String,
|
||||
pub repo_name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct QueryParams {
|
||||
pub format: Option<String>,
|
||||
pub treeish: Option<String>,
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/archive",
|
||||
tag = "Git",
|
||||
operation_id = "gitArchive",
|
||||
params(PathParams, QueryParams),
|
||||
responses(
|
||||
(status = 200, description = "Archive download", content_type = "application/octet-stream"),
|
||||
(status = 401, description = "Unauthorized", body = ApiErrorResponse),
|
||||
(status = 404, description = "Not found", body = ApiErrorResponse),
|
||||
),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn git_archive(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PathParams>,
|
||||
query: web::Query<QueryParams>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
use futures_util::StreamExt;
|
||||
|
||||
let fmt = match query.format.as_deref().unwrap_or("tar.gz") {
|
||||
"tar" => 1i32,
|
||||
"tar.gz" => 2i32,
|
||||
"tar.bz2" => 3i32,
|
||||
"tar.xz" => 4i32,
|
||||
"zip" => 5i32,
|
||||
_ => return Err(AppError::BadRequest("unsupported archive format".into())),
|
||||
};
|
||||
let treeish = query.treeish.as_deref().unwrap_or(DEFAULT_REVISION);
|
||||
|
||||
let mut stream = service
|
||||
.repo
|
||||
.git_archive(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
fmt,
|
||||
treeish,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let (tx, rx) = tokio::sync::mpsc::channel::<Result<web::Bytes, AppError>>(16);
|
||||
|
||||
tokio::spawn(async move {
|
||||
while let Some(Ok(chunk)) = stream.next().await {
|
||||
if tx.send(Ok(web::Bytes::from(chunk.data))).await.is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Ok(HttpResponse::Ok()
|
||||
.content_type("application/octet-stream")
|
||||
.streaming(
|
||||
tokio_stream::wrappers::ReceiverStream::new(rx)
|
||||
.map(|r| r.map_err(|e| actix_web::error::ErrorInternalServerError(e.to_string()))),
|
||||
))
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
use crate::models::common::DEFAULT_REVISION;
|
||||
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 {
|
||||
pub workspace_name: String,
|
||||
pub repo_name: String,
|
||||
pub branch_name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct QueryParams {
|
||||
pub base: Option<String>,
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/branches/{branch_name}/compare",
|
||||
tag = "Git",
|
||||
operation_id = "gitCompareBranch",
|
||||
params(PathParams, QueryParams),
|
||||
responses(
|
||||
(status = 200, description = "Branch comparison", body = ApiResponse<crate::pb::repo::CompareBranchResponse>),
|
||||
(status = 401, description = "Unauthorized", body = ApiErrorResponse),
|
||||
(status = 404, description = "Not found", body = ApiErrorResponse),
|
||||
),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn git_compare_branch(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PathParams>,
|
||||
query: web::Query<QueryParams>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let base = query.base.as_deref().unwrap_or(DEFAULT_REVISION);
|
||||
let result = service
|
||||
.repo
|
||||
.git_compare_branches(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
&path.branch_name,
|
||||
base,
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(result)))
|
||||
}
|
||||
@@ -0,0 +1,238 @@
|
||||
use crate::models::common::DEFAULT_REVISION;
|
||||
use actix_web::{HttpResponse, web};
|
||||
use futures_util::StreamExt;
|
||||
use serde::Deserialize;
|
||||
use utoipa::IntoParams;
|
||||
|
||||
use crate::api::response::ApiResponse;
|
||||
use crate::error::AppError;
|
||||
use crate::service::AppService;
|
||||
use crate::session::Session;
|
||||
|
||||
#[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,
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/commit-diff/{revision}",
|
||||
tag = "Git",
|
||||
operation_id = "gitCommitDiff",
|
||||
params(RevisionPathParams),
|
||||
responses((
|
||||
status = 200,
|
||||
body = ApiResponse<crate::pb::repo::GetDiffResponse>
|
||||
)),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn git_commit_diff(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<RevisionPathParams>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let r = service
|
||||
.repo
|
||||
.git_get_commit_diff(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
&path.revision,
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(r)))
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct PatchQuery {
|
||||
pub old: String,
|
||||
pub new: String,
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/patch",
|
||||
tag = "Git",
|
||||
operation_id = "gitPatch",
|
||||
params(PathParams, PatchQuery),
|
||||
responses((status = 200, content_type = "text/plain")),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn git_patch(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PathParams>,
|
||||
q: web::Query<PatchQuery>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let r = service
|
||||
.repo
|
||||
.git_get_patch(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
&q.old,
|
||||
&q.new,
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().content_type("text/plain").body(r))
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct DiffQuery {
|
||||
pub old: String,
|
||||
pub new: String,
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/raw-diff",
|
||||
tag = "Git",
|
||||
operation_id = "gitRawDiff",
|
||||
params(PathParams, DiffQuery),
|
||||
responses((status = 200, content_type = "text/plain")),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn git_raw_diff(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PathParams>,
|
||||
q: web::Query<DiffQuery>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let r = service
|
||||
.repo
|
||||
.git_raw_diff(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
&q.old,
|
||||
&q.new,
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().content_type("text/plain").body(r))
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct ChangedPathsQuery {
|
||||
pub old: String,
|
||||
pub new: String,
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/changed-paths",
|
||||
tag = "Git",
|
||||
operation_id = "gitChangedPaths",
|
||||
params(PathParams, ChangedPathsQuery),
|
||||
responses((
|
||||
status = 200,
|
||||
body = ApiResponse<crate::pb::repo::FindChangedPathsResponse>
|
||||
)),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn git_changed_paths(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PathParams>,
|
||||
q: web::Query<ChangedPathsQuery>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let r = service
|
||||
.repo
|
||||
.git_find_changed_paths(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
&q.old,
|
||||
&q.new,
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(r)))
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct StreamBlameQuery {
|
||||
pub path: String,
|
||||
pub revision: Option<String>,
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/stream-blame",
|
||||
tag = "Git",
|
||||
operation_id = "gitStreamBlame",
|
||||
params(PathParams, StreamBlameQuery),
|
||||
responses((
|
||||
status = 200,
|
||||
body = ApiResponse<Vec<crate::pb::repo::BlameHunk>>
|
||||
)),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn git_stream_blame(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PathParams>,
|
||||
q: web::Query<StreamBlameQuery>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let mut stream = service
|
||||
.repo
|
||||
.git_stream_blame(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
&q.path,
|
||||
q.revision.as_deref().unwrap_or(DEFAULT_REVISION),
|
||||
)
|
||||
.await?;
|
||||
let mut hunks = Vec::new();
|
||||
while let Some(Ok(hunk)) = stream.next().await {
|
||||
hunks.push(hunk);
|
||||
}
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(hunks)))
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, utoipa::ToSchema)]
|
||||
pub struct ResolveConflictsBody {
|
||||
pub target_branch: String,
|
||||
pub source_revision: String,
|
||||
pub message: Option<String>,
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/resolve-conflicts",
|
||||
tag = "Git",
|
||||
operation_id = "gitResolveConflicts",
|
||||
params(PathParams),
|
||||
request_body(content = ResolveConflictsBody),
|
||||
responses((
|
||||
status = 200,
|
||||
body = ApiResponse<crate::pb::repo::MergeResult>
|
||||
)),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn git_resolve_conflicts(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PathParams>,
|
||||
body: web::Json<ResolveConflictsBody>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let r = service
|
||||
.repo
|
||||
.git_resolve_merge_conflicts(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
&body.target_branch,
|
||||
&body.source_revision,
|
||||
body.message.as_deref().unwrap_or(""),
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(r)))
|
||||
}
|
||||
@@ -0,0 +1,268 @@
|
||||
use crate::models::common::DEFAULT_REVISION;
|
||||
use actix_web::{HttpResponse, web};
|
||||
use serde::Deserialize;
|
||||
use utoipa::IntoParams;
|
||||
|
||||
use crate::api::response::ApiResponse;
|
||||
use crate::error::AppError;
|
||||
use crate::service::AppService;
|
||||
use crate::session::Session;
|
||||
|
||||
#[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,
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/default-branch",
|
||||
tag = "Git",
|
||||
operation_id = "gitDefaultBranch",
|
||||
params(PathParams),
|
||||
responses((status = 200, body = ApiResponse<String>)),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn git_default_branch(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PathParams>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let r = service
|
||||
.repo
|
||||
.git_get_default_branch(&session, &path.workspace_name, &path.repo_name)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(r)))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/object-format",
|
||||
tag = "Git",
|
||||
operation_id = "gitObjectFormat",
|
||||
params(PathParams),
|
||||
responses((status = 200, body = ApiResponse<i32>)),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn git_object_format(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PathParams>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let r = service
|
||||
.repo
|
||||
.git_get_object_format(&session, &path.workspace_name, &path.repo_name)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(r)))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/size",
|
||||
tag = "Git",
|
||||
operation_id = "gitRepositorySize",
|
||||
params(PathParams),
|
||||
responses((
|
||||
status = 200,
|
||||
body = ApiResponse<crate::pb::repo::RepositorySizeResponse>
|
||||
)),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn git_repository_size(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PathParams>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let r = service
|
||||
.repo
|
||||
.git_repository_size(&session, &path.workspace_name, &path.repo_name)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(r)))
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, utoipa::ToSchema)]
|
||||
pub struct ObjectsSizeBody {
|
||||
pub oids: Vec<String>,
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/objects-size",
|
||||
tag = "Git",
|
||||
operation_id = "gitObjectsSize",
|
||||
params(PathParams),
|
||||
request_body(content = ObjectsSizeBody),
|
||||
responses((
|
||||
status = 200,
|
||||
body = ApiResponse<crate::pb::repo::ObjectsSizeResponse>
|
||||
)),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn git_objects_size(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PathParams>,
|
||||
body: web::Json<ObjectsSizeBody>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let r = service
|
||||
.repo
|
||||
.git_objects_size(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
body.oids.clone(),
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(r)))
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct MergeBaseQuery {
|
||||
pub revisions: Vec<String>,
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/merge-base",
|
||||
tag = "Git",
|
||||
operation_id = "gitMergeBase",
|
||||
params(PathParams, MergeBaseQuery),
|
||||
responses((
|
||||
status = 200,
|
||||
body = ApiResponse<crate::pb::repo::FindMergeBaseResponse>
|
||||
)),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn git_merge_base(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PathParams>,
|
||||
q: web::Query<MergeBaseQuery>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let r = service
|
||||
.repo
|
||||
.git_find_merge_base(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
q.revisions.clone(),
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(r)))
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct ArchiveEntriesQuery {
|
||||
pub treeish: Option<String>,
|
||||
pub limit: Option<i64>,
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/archive/entries",
|
||||
tag = "Git",
|
||||
operation_id = "gitArchiveEntries",
|
||||
params(PathParams, ArchiveEntriesQuery),
|
||||
responses((
|
||||
status = 200,
|
||||
body = ApiResponse<crate::pb::repo::ListArchiveEntriesResponse>
|
||||
)),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn git_archive_entries(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PathParams>,
|
||||
q: web::Query<ArchiveEntriesQuery>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let r = service
|
||||
.repo
|
||||
.git_list_archive_entries(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
q.treeish.as_deref().unwrap_or(DEFAULT_REVISION),
|
||||
q.limit.unwrap_or(50).clamp(1, 100) as u32,
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(r)))
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct CommitAncestorsQuery {
|
||||
pub max_count: Option<u32>,
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/commits/{revision}/ancestors",
|
||||
tag = "Git",
|
||||
operation_id = "gitCommitAncestors",
|
||||
params(RevisionPathParams, CommitAncestorsQuery),
|
||||
responses((
|
||||
status = 200,
|
||||
body = ApiResponse<crate::pb::repo::GetCommitAncestorsResponse>
|
||||
)),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn git_commit_ancestors(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<RevisionPathParams>,
|
||||
q: web::Query<CommitAncestorsQuery>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let r = service
|
||||
.repo
|
||||
.git_get_commit_ancestors(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
&path.revision,
|
||||
q.max_count.unwrap_or(100),
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(r)))
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, utoipa::ToSchema)]
|
||||
pub struct CheckObjectsBody {
|
||||
pub revisions: Vec<String>,
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/check-objects",
|
||||
tag = "Git",
|
||||
operation_id = "gitCheckObjects",
|
||||
params(PathParams),
|
||||
request_body(content = CheckObjectsBody),
|
||||
responses((
|
||||
status = 200,
|
||||
body = ApiResponse<crate::pb::repo::CheckObjectsExistResponse>
|
||||
)),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn git_check_objects(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PathParams>,
|
||||
body: web::Json<CheckObjectsBody>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let r = service
|
||||
.repo
|
||||
.git_check_objects_exist(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
body.revisions.clone(),
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(r)))
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
use crate::models::common::DEFAULT_REVISION;
|
||||
use actix_web::{HttpResponse, web};
|
||||
use serde::Deserialize;
|
||||
use utoipa::IntoParams;
|
||||
|
||||
use crate::api::response::ApiResponse;
|
||||
use crate::error::AppError;
|
||||
use crate::service::AppService;
|
||||
use crate::session::Session;
|
||||
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct PathParams {
|
||||
pub workspace_name: String,
|
||||
pub repo_name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct RawBlobQuery {
|
||||
pub revision: Option<String>,
|
||||
pub path: String,
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/raw-blob",
|
||||
tag = "Git",
|
||||
operation_id = "gitRawBlob",
|
||||
params(PathParams, RawBlobQuery),
|
||||
responses((status = 200, content_type = "application/octet-stream")),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn git_raw_blob(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PathParams>,
|
||||
q: web::Query<RawBlobQuery>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let r = service
|
||||
.repo
|
||||
.git_get_raw_blob(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
q.revision.as_deref().unwrap_or(DEFAULT_REVISION),
|
||||
&q.path,
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok()
|
||||
.content_type("application/octet-stream")
|
||||
.body(r))
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct FileMetaQuery {
|
||||
pub revision: Option<String>,
|
||||
pub path: String,
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/file-metadata",
|
||||
tag = "Git",
|
||||
operation_id = "gitFileMetadata",
|
||||
params(PathParams, FileMetaQuery),
|
||||
responses((
|
||||
status = 200,
|
||||
body = ApiResponse<crate::pb::repo::FileMetadata>
|
||||
)),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn git_file_metadata(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PathParams>,
|
||||
q: web::Query<FileMetaQuery>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let r = service
|
||||
.repo
|
||||
.git_get_file_metadata(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
q.revision.as_deref().unwrap_or(DEFAULT_REVISION),
|
||||
&q.path,
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(r)))
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct FindFilesQuery {
|
||||
pub revision: Option<String>,
|
||||
pub pattern: String,
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/find-files",
|
||||
tag = "Git",
|
||||
operation_id = "gitFindFiles",
|
||||
params(PathParams, FindFilesQuery),
|
||||
responses((
|
||||
status = 200,
|
||||
body = ApiResponse<crate::pb::repo::FindFilesResponse>
|
||||
)),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn git_find_files(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PathParams>,
|
||||
q: web::Query<FindFilesQuery>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let r = service
|
||||
.repo
|
||||
.git_find_files(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
q.revision.as_deref().unwrap_or(DEFAULT_REVISION),
|
||||
&q.pattern,
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(r)))
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, IntoParams)]
|
||||
pub struct GetTreeQuery {
|
||||
pub revision: Option<String>,
|
||||
pub path: Option<String>,
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/workspaces/{workspace_name}/repos/{repo_name}/git/get-tree",
|
||||
tag = "Git",
|
||||
operation_id = "gitGetTree",
|
||||
params(PathParams, GetTreeQuery),
|
||||
responses((status = 200, body = ApiResponse<crate::pb::repo::Tree>)),
|
||||
security(("session_cookie" = []))
|
||||
)]
|
||||
pub async fn git_get_tree(
|
||||
service: web::Data<AppService>,
|
||||
session: Session,
|
||||
path: web::Path<PathParams>,
|
||||
q: web::Query<GetTreeQuery>,
|
||||
) -> Result<HttpResponse, AppError> {
|
||||
let r = service
|
||||
.repo
|
||||
.git_get_tree(
|
||||
&session,
|
||||
&path.workspace_name,
|
||||
&path.repo_name,
|
||||
q.revision.as_deref().unwrap_or(DEFAULT_REVISION),
|
||||
q.path.as_deref().unwrap_or(""),
|
||||
)
|
||||
.await?;
|
||||
Ok(HttpResponse::Ok().json(ApiResponse::new(r)))
|
||||
}
|
||||
Reference in New Issue
Block a user