diff --git a/giterated-daemon/src/backend/git.rs b/giterated-daemon/src/backend/git.rs index 9ee5fdf..7ad1a83 100644 --- a/giterated-daemon/src/backend/git.rs +++ b/giterated-daemon/src/backend/git.rs @@ -6,10 +6,12 @@ use giterated_models::instance::{Instance, RepositoryCreateRequest}; use giterated_models::repository::{ Commit, DefaultBranch, Description, IssueLabel, LatestCommit, Repository, - RepositoryCommitBeforeRequest, RepositoryDiff, RepositoryDiffRequest, RepositoryFile, - RepositoryFileFromIdRequest, RepositoryFileInspectRequest, RepositoryIssue, - RepositoryIssueLabelsRequest, RepositoryIssuesCountRequest, RepositoryIssuesRequest, - RepositoryObjectType, RepositoryTreeEntry, RepositoryVisibility, Visibility, RepositoryDiffFile, RepositoryDiffFileInfo, RepositoryDiffFileStatus, RepositoryDiffFileChunk, RepositoryDiffPatchRequest, + RepositoryCommitBeforeRequest, RepositoryDiff, RepositoryDiffFile, RepositoryDiffFileChunk, + RepositoryDiffFileInfo, RepositoryDiffFileStatus, RepositoryDiffPatchRequest, + RepositoryDiffRequest, RepositoryFile, RepositoryFileFromIdRequest, + RepositoryFileInspectRequest, RepositoryIssue, RepositoryIssueLabelsRequest, + RepositoryIssuesCountRequest, RepositoryIssuesRequest, RepositoryObjectType, + RepositoryTreeEntry, RepositoryVisibility, Visibility, }; use giterated_models::settings::{AnySetting, Setting}; use giterated_models::user::{User, UserParseError}; @@ -321,11 +323,50 @@ impl RepositoryBackend for GitBackend { "Created new repository with the name {}/{}/{}", request.owner.instance.url, request.owner.username, request.name ); - Ok(Repository { + + let repository = Repository { owner: request.owner.clone(), name: request.name.clone(), instance: request.instance.as_ref().unwrap_or(&self.instance).clone(), - }) + }; + + let mut settings_backend = self.settings_provider.lock().await; + settings_backend + .repository_write( + &repository, + Description::name(), + AnySetting( + serde_json::to_value(Description( + request.description.clone().unwrap_or_default(), + )) + .unwrap(), + ), + ) + .await + .unwrap(); + settings_backend + .repository_write( + &repository, + Visibility::name(), + AnySetting( + serde_json::to_value(Visibility(request.visibility.clone())).unwrap(), + ), + ) + .await + .unwrap(); + settings_backend + .repository_write( + &repository, + DefaultBranch::name(), + AnySetting( + serde_json::to_value(DefaultBranch(request.default_branch.clone())) + .unwrap(), + ), + ) + .await + .unwrap(); + + Ok(repository) } Err(err) => { let err = GitBackendError::FailedCreatingRepository(err); @@ -747,9 +788,15 @@ impl RepositoryBackend for GitBackend { let old_file_info = match delta.old_file().exists() { true => Some(RepositoryDiffFileInfo { id: delta.old_file().id().to_string(), - path: delta.old_file().path().unwrap().to_str().unwrap().to_string(), + path: delta + .old_file() + .path() + .unwrap() + .to_str() + .unwrap() + .to_string(), size: delta.old_file().size(), - binary: delta.old_file().is_binary() + binary: delta.old_file().is_binary(), }), false => None, }; @@ -757,9 +804,15 @@ impl RepositoryBackend for GitBackend { let new_file_info = match delta.new_file().exists() { true => Some(RepositoryDiffFileInfo { id: delta.new_file().id().to_string(), - path: delta.new_file().path().unwrap().to_str().unwrap().to_string(), + path: delta + .new_file() + .path() + .unwrap() + .to_str() + .unwrap() + .to_string(), size: delta.new_file().size(), - binary: delta.new_file().is_binary() + binary: delta.new_file().is_binary(), }), false => None, }; @@ -795,9 +848,9 @@ impl RepositoryBackend for GitBackend { }; let file = RepositoryDiffFile { - status: RepositoryDiffFileStatus::from(delta.status()), - old_file_info, - new_file_info, + status: RepositoryDiffFileStatus::from(delta.status()), + old_file_info, + new_file_info, chunks, }; diff --git a/giterated-daemon/src/backend/mod.rs b/giterated-daemon/src/backend/mod.rs index fba1812..5b66fbc 100644 --- a/giterated-daemon/src/backend/mod.rs +++ b/giterated-daemon/src/backend/mod.rs @@ -17,9 +17,9 @@ use giterated_models::instance::{ use giterated_models::repository::{ Commit, IssueLabel, Repository, RepositoryCommitBeforeRequest, RepositoryDiff, - RepositoryDiffRequest, RepositoryFile, RepositoryFileFromIdRequest, + RepositoryDiffPatchRequest, RepositoryDiffRequest, RepositoryFile, RepositoryFileFromIdRequest, RepositoryFileInspectRequest, RepositoryIssue, RepositoryIssueLabelsRequest, - RepositoryIssuesCountRequest, RepositoryIssuesRequest, RepositorySummary, RepositoryTreeEntry, RepositoryDiffPatchRequest, + RepositoryIssuesCountRequest, RepositoryIssuesRequest, RepositorySummary, RepositoryTreeEntry, }; use giterated_models::settings::AnySetting; use giterated_models::user::User; diff --git a/giterated-daemon/src/database_backend/handler.rs b/giterated-daemon/src/database_backend/handler.rs index 42df9cc..bf02baa 100644 --- a/giterated-daemon/src/database_backend/handler.rs +++ b/giterated-daemon/src/database_backend/handler.rs @@ -4,13 +4,16 @@ use futures_util::{future::BoxFuture, FutureExt}; use giterated_models::{ authenticated::UserAuthenticationToken, error::{GetValueError, InstanceError, OperationError, RepositoryError, UserError}, - instance::{AuthenticationTokenRequest, Instance, RegisterAccountRequest, RepositoryCreateRequest}, + instance::{ + AuthenticationTokenRequest, Instance, RegisterAccountRequest, RepositoryCreateRequest, + }, object_backend::ObjectBackend, repository::{ Commit, DefaultBranch, Description, LatestCommit, Repository, - RepositoryCommitBeforeRequest, RepositoryDiff, RepositoryDiffRequest, RepositoryFile, - RepositoryFileFromIdRequest, RepositoryFileInspectRequest, RepositoryInfoRequest, - RepositorySummary, RepositoryView, Visibility, RepositoryDiffPatchRequest, + RepositoryCommitBeforeRequest, RepositoryDiff, RepositoryDiffPatchRequest, + RepositoryDiffRequest, RepositoryFile, RepositoryFileFromIdRequest, + RepositoryFileInspectRequest, RepositoryInfoRequest, RepositorySummary, RepositoryView, + Visibility, }, settings::{AnySetting, GetSetting, GetSettingError, SetSetting, SetSettingError}, user::{User, UserRepositoriesRequest}, @@ -356,7 +359,7 @@ pub fn instance_registration_request( pub fn instance_create_repository_request( _object: &Instance, operation: RepositoryCreateRequest, - state: DatabaseBackend + state: DatabaseBackend, ) -> BoxFuture<'static, Result>> { async move { let mut backend = state.repository_backend.lock().await; @@ -367,4 +370,4 @@ pub fn instance_create_repository_request( .map_err(|e| OperationError::Internal(e.to_string())) } .boxed() -} \ No newline at end of file +} diff --git a/giterated-daemon/src/database_backend/mod.rs b/giterated-daemon/src/database_backend/mod.rs index 74ae05f..b5e9f0c 100644 --- a/giterated-daemon/src/database_backend/mod.rs +++ b/giterated-daemon/src/database_backend/mod.rs @@ -17,9 +17,11 @@ use tokio::sync::Mutex; use crate::backend::{RepositoryBackend, UserBackend}; use self::handler::{ - instance_authentication_request, instance_registration_request, repository_commit_before, repository_diff, repository_file_from_id, repository_get_setting, - repository_get_value, repository_info, repository_set_setting, user_get_repositories, - user_get_setting, user_get_value, user_set_setting, repository_diff_patch, instance_create_repository_request, + instance_authentication_request, instance_create_repository_request, + instance_registration_request, repository_commit_before, repository_diff, + repository_diff_patch, repository_file_from_id, repository_get_setting, repository_get_value, + repository_info, repository_set_setting, user_get_repositories, user_get_setting, + user_get_value, user_set_setting, }; #[derive(Clone, Debug)] @@ -120,8 +122,9 @@ mod test { use giterated_models::repository::{ Commit, Description, Repository, RepositoryCommitBeforeRequest, RepositoryDiff, - RepositoryDiffRequest, RepositoryFile, RepositoryFileFromIdRequest, - RepositoryFileInspectRequest, RepositorySummary, RepositoryTreeEntry, RepositoryDiffPatchRequest, + RepositoryDiffPatchRequest, RepositoryDiffRequest, RepositoryFile, + RepositoryFileFromIdRequest, RepositoryFileInspectRequest, RepositorySummary, + RepositoryTreeEntry, }; use giterated_models::settings::AnySetting; use giterated_models::user::{DisplayName, User}; diff --git a/giterated-models/src/repository/settings.rs b/giterated-models/src/repository/settings.rs index f34b877..f23fe3c 100644 --- a/giterated-models/src/repository/settings.rs +++ b/giterated-models/src/repository/settings.rs @@ -1,6 +1,6 @@ use crate::settings::Setting; -use super::DefaultBranch; +use super::{DefaultBranch, RepositoryVisibility}; impl Setting for DefaultBranch { fn name() -> &'static str {