Skip to content
Clone
a06673b
141 lines 3.5 KB Rust
use uuid::Uuid;
use crate::error::{RepoError, RepoResult};
use crate::features::RepoService;
use super::types::{
ApplyDiffPatchFileOptions, ChangeFilesOptions, ContentsListResponse, ContentsQuery,
ContentsResponse, CreateFileOption, DeleteFileOption, UpdateFileOption,
};
fn require_write(_actor: Uuid) -> RepoResult<()> {
Ok(())
}
pub async fn list_contents(
_svc: &RepoService,
actor: Uuid,
_repo_id: Uuid,
path: &str,
_q: ContentsQuery,
) -> RepoResult<ContentsListResponse> {
let _ = actor;
let _ = path;
Err(RepoError::Internal(
"contents listing requires lib/git rewire (in progress)".into(),
))
}
pub async fn get_contents(
_svc: &RepoService,
actor: Uuid,
_repo_id: Uuid,
path: &str,
_q: ContentsQuery,
) -> RepoResult<ContentsResponse> {
let _ = actor;
let _ = path;
Err(RepoError::Internal(
"contents read requires lib/git rewire (in progress)".into(),
))
}
pub async fn create_file(
_svc: &RepoService,
actor: Uuid,
_repo_id: Uuid,
path: &str,
input: CreateFileOption,
) -> RepoResult<ContentsResponse> {
require_write(actor)?;
if path.is_empty() {
return Err(RepoError::BadRequest("path is required".into()));
}
if input
.opts
.message
.as_deref()
.unwrap_or("")
.trim()
.is_empty()
{
return Err(RepoError::BadRequest("commit message is required".into()));
}
Err(RepoError::Internal(
"create_file requires lib/git rewire (in progress)".into(),
))
}
pub async fn update_file(
_svc: &RepoService,
actor: Uuid,
_repo_id: Uuid,
path: &str,
input: UpdateFileOption,
) -> RepoResult<ContentsResponse> {
require_write(actor)?;
if path.is_empty() {
return Err(RepoError::BadRequest("path is required".into()));
}
if input.sha.as_deref().unwrap_or("").is_empty() {
return Err(RepoError::BadRequest(
"expected sha of the existing file".into(),
));
}
Err(RepoError::Internal(
"update_file requires lib/git rewire (in progress)".into(),
))
}
pub async fn delete_file(
_svc: &RepoService,
actor: Uuid,
_repo_id: Uuid,
path: &str,
input: DeleteFileOption,
) -> RepoResult<()> {
require_write(actor)?;
if path.is_empty() {
return Err(RepoError::BadRequest("path is required".into()));
}
if input.sha.is_empty() {
return Err(RepoError::BadRequest(
"expected sha of the file to delete".into(),
));
}
Err(RepoError::Internal(
"delete_file requires lib/git rewire (in progress)".into(),
))
}
pub async fn change_files(
_svc: &RepoService,
actor: Uuid,
_repo_id: Uuid,
input: ChangeFilesOptions,
) -> RepoResult<ContentsListResponse> {
require_write(actor)?;
if input.files.is_empty() {
return Err(RepoError::BadRequest(
"at least one file entry required".into(),
));
}
Err(RepoError::Internal(
"change_files requires lib/git rewire (in progress)".into(),
))
}
pub async fn apply_diff_patch(
_svc: &RepoService,
actor: Uuid,
_repo_id: Uuid,
input: ApplyDiffPatchFileOptions,
) -> RepoResult<ContentsResponse> {
require_write(actor)?;
if input.content.is_empty() {
return Err(RepoError::BadRequest("patch content is required".into()));
}
Err(RepoError::Internal(
"apply_diff_patch requires lib/git rewire (in progress)".into(),
))
}