JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

Repository diff request and handler

Type: Feature

erremilia - ⁨2⁩ years ago

parent: tbd commit: ⁨502a11c

⁨giterated-daemon/src/backend/mod.rs⁩ - ⁨4188⁩ bytes
Raw
1 pub mod discovery;
2 pub mod git;
3 pub mod github;
4 pub mod settings;
5 pub mod user;
6
7 use anyhow::Error;
8 use async_trait::async_trait;
9 use serde_json::Value;
10
11 use crate::backend::git::GitBackendError;
12 use giterated_models::authenticated::UserAuthenticationToken;
13
14 use giterated_models::instance::{
15 AuthenticationTokenRequest, Instance, RegisterAccountRequest, RepositoryCreateRequest,
16 };
17
18 use giterated_models::repository::{
19 IssueLabel, Repository, RepositoryFileInspectRequest, RepositoryIssue,
20 RepositoryIssueLabelsRequest, RepositoryIssuesCountRequest, RepositoryIssuesRequest,
21 RepositorySummary, RepositoryTreeEntry, RepositoryFileFromIdRequest, RepositoryFile, RepositoryDiffRequest, RepositoryDiff,
22 };
23 use giterated_models::settings::AnySetting;
24 use giterated_models::user::User;
25 use giterated_models::value::AnyValue;
26
27 #[async_trait]
28 pub trait RepositoryBackend {
29 async fn create_repository(
30 &mut self,
31 user: &User,
32 request: &RepositoryCreateRequest,
33 ) -> Result<Repository, GitBackendError>;
34 async fn repository_file_inspect(
35 &mut self,
36 requester: Option<&User>,
37 repository: &Repository,
38 request: &RepositoryFileInspectRequest,
39 ) -> Result<Vec<RepositoryTreeEntry>, Error>;
40 async fn repository_file_from_id(
41 &mut self,
42 requester: Option<&User>,
43 repository: &Repository,
44 request: &RepositoryFileFromIdRequest,
45 ) -> Result<RepositoryFile, Error>;
46 async fn repository_diff(
47 &mut self,
48 requester: Option<&User>,
49 repository: &Repository,
50 request: &RepositoryDiffRequest,
51 ) -> Result<RepositoryDiff, Error>;
52 async fn get_value(
53 &mut self,
54 user: &Repository,
55 name: &str,
56 ) -> Result<AnyValue<Repository>, Error>;
57 async fn get_setting(&mut self, user: &Repository, name: &str) -> Result<AnySetting, Error>;
58 async fn write_setting(
59 &mut self,
60 user: &Repository,
61 name: &str,
62 setting: &Value,
63 ) -> Result<(), Error>;
64 async fn exists(&mut self, repository: &Repository) -> Result<bool, Error>;
65 }
66
67 pub trait IssuesBackend {
68 fn issues_count(
69 &mut self,
70 requester: Option<&User>,
71 request: &RepositoryIssuesCountRequest,
72 ) -> Result<u64, Error>;
73 fn issue_labels(
74 &mut self,
75 requester: Option<&User>,
76 request: &RepositoryIssueLabelsRequest,
77 ) -> Result<Vec<IssueLabel>, Error>;
78 fn issues(
79 &mut self,
80 requester: Option<&User>,
81 request: &RepositoryIssuesRequest,
82 ) -> Result<Vec<RepositoryIssue>, Error>;
83 }
84
85 #[async_trait::async_trait]
86 pub trait AuthBackend {
87 async fn register(
88 &mut self,
89 request: RegisterAccountRequest,
90 ) -> Result<UserAuthenticationToken, Error>;
91
92 async fn login(
93 &mut self,
94 source: &Instance,
95 request: AuthenticationTokenRequest,
96 ) -> Result<UserAuthenticationToken, Error>;
97 }
98
99 #[async_trait::async_trait]
100 pub trait UserBackend: AuthBackend {
101 async fn get_value(&mut self, user: &User, name: &str) -> Result<AnyValue<User>, Error>;
102 async fn get_setting(&mut self, user: &User, name: &str) -> Result<AnySetting, Error>;
103 async fn write_setting(
104 &mut self,
105 user: &User,
106 name: &str,
107 setting: &Value,
108 ) -> Result<(), Error>;
109 async fn exists(&mut self, user: &User) -> Result<bool, Error>;
110 async fn repositories_for_user(
111 &mut self,
112 requester: Option<&User>,
113 user: &User,
114 ) -> Result<Vec<RepositorySummary>, Error>;
115 }
116
117 #[async_trait::async_trait]
118 pub trait MetadataBackend {
119 async fn user_get(&mut self, user: &User, name: &str) -> Result<AnySetting, Error>;
120 async fn user_write(
121 &mut self,
122 user: &User,
123 name: &str,
124 setting: AnySetting,
125 ) -> Result<(), Error>;
126 async fn repository_get(
127 &mut self,
128 repository: &Repository,
129 name: &str,
130 ) -> Result<AnySetting, Error>;
131 async fn repository_write(
132 &mut self,
133 repository: &Repository,
134 name: &str,
135 setting: AnySetting,
136 ) -> Result<(), Error>;
137 }
138