Add repository setings
parent: tbd commit: 3b20354
Showing 5 changed files with 86 insertions and 27 deletions
giterated-daemon/src/backend/git.rs
@@ -6,10 +6,12 @@ use giterated_models::instance::{Instance, RepositoryCreateRequest}; | ||
6 | 6 | |
7 | 7 | use giterated_models::repository::{ |
8 | 8 | Commit, DefaultBranch, Description, IssueLabel, LatestCommit, Repository, |
9 | RepositoryCommitBeforeRequest, RepositoryDiff, RepositoryDiffRequest, RepositoryFile, | |
10 | RepositoryFileFromIdRequest, RepositoryFileInspectRequest, RepositoryIssue, | |
11 | RepositoryIssueLabelsRequest, RepositoryIssuesCountRequest, RepositoryIssuesRequest, | |
12 | RepositoryObjectType, RepositoryTreeEntry, RepositoryVisibility, Visibility, RepositoryDiffFile, RepositoryDiffFileInfo, RepositoryDiffFileStatus, RepositoryDiffFileChunk, RepositoryDiffPatchRequest, | |
9 | RepositoryCommitBeforeRequest, RepositoryDiff, RepositoryDiffFile, RepositoryDiffFileChunk, | |
10 | RepositoryDiffFileInfo, RepositoryDiffFileStatus, RepositoryDiffPatchRequest, | |
11 | RepositoryDiffRequest, RepositoryFile, RepositoryFileFromIdRequest, | |
12 | RepositoryFileInspectRequest, RepositoryIssue, RepositoryIssueLabelsRequest, | |
13 | RepositoryIssuesCountRequest, RepositoryIssuesRequest, RepositoryObjectType, | |
14 | RepositoryTreeEntry, RepositoryVisibility, Visibility, | |
13 | 15 | }; |
14 | 16 | use giterated_models::settings::{AnySetting, Setting}; |
15 | 17 | use giterated_models::user::{User, UserParseError}; |
@@ -321,11 +323,50 @@ impl RepositoryBackend for GitBackend { | ||
321 | 323 | "Created new repository with the name {}/{}/{}", |
322 | 324 | request.owner.instance.url, request.owner.username, request.name |
323 | 325 | ); |
324 | Ok(Repository { | |
326 | ||
327 | let repository = Repository { | |
325 | 328 | owner: request.owner.clone(), |
326 | 329 | name: request.name.clone(), |
327 | 330 | instance: request.instance.as_ref().unwrap_or(&self.instance).clone(), |
328 | }) | |
331 | }; | |
332 | ||
333 | let mut settings_backend = self.settings_provider.lock().await; | |
334 | settings_backend | |
335 | .repository_write( | |
336 | &repository, | |
337 | Description::name(), | |
338 | AnySetting( | |
339 | serde_json::to_value(Description( | |
340 | request.description.clone().unwrap_or_default(), | |
341 | )) | |
342 | .unwrap(), | |
343 | ), | |
344 | ) | |
345 | .await | |
346 | .unwrap(); | |
347 | settings_backend | |
348 | .repository_write( | |
349 | &repository, | |
350 | Visibility::name(), | |
351 | AnySetting( | |
352 | serde_json::to_value(Visibility(request.visibility.clone())).unwrap(), | |
353 | ), | |
354 | ) | |
355 | .await | |
356 | .unwrap(); | |
357 | settings_backend | |
358 | .repository_write( | |
359 | &repository, | |
360 | DefaultBranch::name(), | |
361 | AnySetting( | |
362 | serde_json::to_value(DefaultBranch(request.default_branch.clone())) | |
363 | .unwrap(), | |
364 | ), | |
365 | ) | |
366 | .await | |
367 | .unwrap(); | |
368 | ||
369 | Ok(repository) | |
329 | 370 | } |
330 | 371 | Err(err) => { |
331 | 372 | let err = GitBackendError::FailedCreatingRepository(err); |
@@ -747,9 +788,15 @@ impl RepositoryBackend for GitBackend { | ||
747 | 788 | let old_file_info = match delta.old_file().exists() { |
748 | 789 | true => Some(RepositoryDiffFileInfo { |
749 | 790 | id: delta.old_file().id().to_string(), |
750 | path: delta.old_file().path().unwrap().to_str().unwrap().to_string(), | |
791 | path: delta | |
792 | .old_file() | |
793 | .path() | |
794 | .unwrap() | |
795 | .to_str() | |
796 | .unwrap() | |
797 | .to_string(), | |
751 | 798 | size: delta.old_file().size(), |
752 | binary: delta.old_file().is_binary() | |
799 | binary: delta.old_file().is_binary(), | |
753 | 800 | }), |
754 | 801 | false => None, |
755 | 802 | }; |
@@ -757,9 +804,15 @@ impl RepositoryBackend for GitBackend { | ||
757 | 804 | let new_file_info = match delta.new_file().exists() { |
758 | 805 | true => Some(RepositoryDiffFileInfo { |
759 | 806 | id: delta.new_file().id().to_string(), |
760 | path: delta.new_file().path().unwrap().to_str().unwrap().to_string(), | |
807 | path: delta | |
808 | .new_file() | |
809 | .path() | |
810 | .unwrap() | |
811 | .to_str() | |
812 | .unwrap() | |
813 | .to_string(), | |
761 | 814 | size: delta.new_file().size(), |
762 | binary: delta.new_file().is_binary() | |
815 | binary: delta.new_file().is_binary(), | |
763 | 816 | }), |
764 | 817 | false => None, |
765 | 818 | }; |
@@ -795,9 +848,9 @@ impl RepositoryBackend for GitBackend { | ||
795 | 848 | }; |
796 | 849 | |
797 | 850 | let file = RepositoryDiffFile { |
798 | status: RepositoryDiffFileStatus::from(delta.status()), | |
799 | old_file_info, | |
800 | new_file_info, | |
851 | status: RepositoryDiffFileStatus::from(delta.status()), | |
852 | old_file_info, | |
853 | new_file_info, | |
801 | 854 | chunks, |
802 | 855 | }; |
803 | 856 |
giterated-daemon/src/backend/mod.rs
@@ -17,9 +17,9 @@ use giterated_models::instance::{ | ||
17 | 17 | |
18 | 18 | use giterated_models::repository::{ |
19 | 19 | Commit, IssueLabel, Repository, RepositoryCommitBeforeRequest, RepositoryDiff, |
20 | RepositoryDiffRequest, RepositoryFile, RepositoryFileFromIdRequest, | |
20 | RepositoryDiffPatchRequest, RepositoryDiffRequest, RepositoryFile, RepositoryFileFromIdRequest, | |
21 | 21 | RepositoryFileInspectRequest, RepositoryIssue, RepositoryIssueLabelsRequest, |
22 | RepositoryIssuesCountRequest, RepositoryIssuesRequest, RepositorySummary, RepositoryTreeEntry, RepositoryDiffPatchRequest, | |
22 | RepositoryIssuesCountRequest, RepositoryIssuesRequest, RepositorySummary, RepositoryTreeEntry, | |
23 | 23 | }; |
24 | 24 | use giterated_models::settings::AnySetting; |
25 | 25 | use giterated_models::user::User; |
giterated-daemon/src/database_backend/handler.rs
@@ -4,13 +4,16 @@ use futures_util::{future::BoxFuture, FutureExt}; | ||
4 | 4 | use giterated_models::{ |
5 | 5 | authenticated::UserAuthenticationToken, |
6 | 6 | error::{GetValueError, InstanceError, OperationError, RepositoryError, UserError}, |
7 | instance::{AuthenticationTokenRequest, Instance, RegisterAccountRequest, RepositoryCreateRequest}, | |
7 | instance::{ | |
8 | AuthenticationTokenRequest, Instance, RegisterAccountRequest, RepositoryCreateRequest, | |
9 | }, | |
8 | 10 | object_backend::ObjectBackend, |
9 | 11 | repository::{ |
10 | 12 | Commit, DefaultBranch, Description, LatestCommit, Repository, |
11 | RepositoryCommitBeforeRequest, RepositoryDiff, RepositoryDiffRequest, RepositoryFile, | |
12 | RepositoryFileFromIdRequest, RepositoryFileInspectRequest, RepositoryInfoRequest, | |
13 | RepositorySummary, RepositoryView, Visibility, RepositoryDiffPatchRequest, | |
13 | RepositoryCommitBeforeRequest, RepositoryDiff, RepositoryDiffPatchRequest, | |
14 | RepositoryDiffRequest, RepositoryFile, RepositoryFileFromIdRequest, | |
15 | RepositoryFileInspectRequest, RepositoryInfoRequest, RepositorySummary, RepositoryView, | |
16 | Visibility, | |
14 | 17 | }, |
15 | 18 | settings::{AnySetting, GetSetting, GetSettingError, SetSetting, SetSettingError}, |
16 | 19 | user::{User, UserRepositoriesRequest}, |
@@ -356,7 +359,7 @@ pub fn instance_registration_request( | ||
356 | 359 | pub fn instance_create_repository_request( |
357 | 360 | _object: &Instance, |
358 | 361 | operation: RepositoryCreateRequest, |
359 | state: DatabaseBackend | |
362 | state: DatabaseBackend, | |
360 | 363 | ) -> BoxFuture<'static, Result<Repository, OperationError<InstanceError>>> { |
361 | 364 | async move { |
362 | 365 | let mut backend = state.repository_backend.lock().await; |
@@ -367,4 +370,4 @@ pub fn instance_create_repository_request( | ||
367 | 370 | .map_err(|e| OperationError::Internal(e.to_string())) |
368 | 371 | } |
369 | 372 | .boxed() |
370 | } | |
370 | \ No newline at end of file | |
373 | } |
giterated-daemon/src/database_backend/mod.rs
@@ -17,9 +17,11 @@ use tokio::sync::Mutex; | ||
17 | 17 | use crate::backend::{RepositoryBackend, UserBackend}; |
18 | 18 | |
19 | 19 | use self::handler::{ |
20 | instance_authentication_request, instance_registration_request, repository_commit_before, repository_diff, repository_file_from_id, repository_get_setting, | |
21 | repository_get_value, repository_info, repository_set_setting, user_get_repositories, | |
22 | user_get_setting, user_get_value, user_set_setting, repository_diff_patch, instance_create_repository_request, | |
20 | instance_authentication_request, instance_create_repository_request, | |
21 | instance_registration_request, repository_commit_before, repository_diff, | |
22 | repository_diff_patch, repository_file_from_id, repository_get_setting, repository_get_value, | |
23 | repository_info, repository_set_setting, user_get_repositories, user_get_setting, | |
24 | user_get_value, user_set_setting, | |
23 | 25 | }; |
24 | 26 | |
25 | 27 | #[derive(Clone, Debug)] |
@@ -120,8 +122,9 @@ mod test { | ||
120 | 122 | |
121 | 123 | use giterated_models::repository::{ |
122 | 124 | Commit, Description, Repository, RepositoryCommitBeforeRequest, RepositoryDiff, |
123 | RepositoryDiffRequest, RepositoryFile, RepositoryFileFromIdRequest, | |
124 | RepositoryFileInspectRequest, RepositorySummary, RepositoryTreeEntry, RepositoryDiffPatchRequest, | |
125 | RepositoryDiffPatchRequest, RepositoryDiffRequest, RepositoryFile, | |
126 | RepositoryFileFromIdRequest, RepositoryFileInspectRequest, RepositorySummary, | |
127 | RepositoryTreeEntry, | |
125 | 128 | }; |
126 | 129 | use giterated_models::settings::AnySetting; |
127 | 130 | use giterated_models::user::{DisplayName, User}; |