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

ambee/giterated

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

Incomplete repository branches request

erremilia - ⁨2⁩ years ago

parent: tbd commit: ⁨6872fbf

⁨giterated-daemon/src/backend/mod.rs⁩ - ⁨6264⁩ 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 giterated_stack::AuthenticatedUser;
10 use serde_json::Value;
11
12 use crate::backend::git::GitBackendError;
13 use giterated_models::authenticated::UserAuthenticationToken;
14
15 use giterated_models::instance::{
16 AuthenticationTokenRequest, Instance, RegisterAccountRequest, RepositoryCreateRequest,
17 };
18
19 use giterated_models::repository::{
20 Commit, IssueLabel, Repository, RepositoryBranch, RepositoryBranchesRequest,
21 RepositoryCommitBeforeRequest, RepositoryCommitFromIdRequest, RepositoryDiff,
22 RepositoryDiffPatchRequest, RepositoryDiffRequest, RepositoryFile, RepositoryFileFromIdRequest,
23 RepositoryFileFromPathRequest, RepositoryFileInspectRequest, RepositoryIssue,
24 RepositoryIssueLabelsRequest, RepositoryIssuesCountRequest, RepositoryIssuesRequest,
25 RepositoryLastCommitOfFileRequest, RepositoryStatistics, RepositoryStatisticsRequest,
26 RepositorySummary, RepositoryTreeEntry,
27 };
28 use giterated_models::settings::AnySetting;
29 use giterated_models::user::User;
30 use giterated_models::value::AnyValue;
31
32 #[async_trait]
33 pub trait RepositoryBackend {
34 async fn create_repository(
35 &mut self,
36 user: &AuthenticatedUser,
37 request: &RepositoryCreateRequest,
38 ) -> Result<Repository, GitBackendError>;
39 async fn repository_file_inspect(
40 &mut self,
41 requester: &Option<AuthenticatedUser>,
42 repository: &Repository,
43 request: &RepositoryFileInspectRequest,
44 ) -> Result<Vec<RepositoryTreeEntry>, Error>;
45 async fn repository_file_from_id(
46 &mut self,
47 requester: &Option<AuthenticatedUser>,
48 repository: &Repository,
49 request: &RepositoryFileFromIdRequest,
50 ) -> Result<RepositoryFile, Error>;
51 async fn repository_file_from_path(
52 &mut self,
53 requester: &Option<AuthenticatedUser>,
54 repository: &Repository,
55 request: &RepositoryFileFromPathRequest,
56 ) -> Result<(RepositoryFile, String), Error>;
57 async fn repository_commit_from_id(
58 &mut self,
59 requester: &Option<AuthenticatedUser>,
60 repository: &Repository,
61 request: &RepositoryCommitFromIdRequest,
62 ) -> Result<Commit, Error>;
63 async fn repository_last_commit_of_file(
64 &mut self,
65 requester: &Option<AuthenticatedUser>,
66 repository: &Repository,
67 request: &RepositoryLastCommitOfFileRequest,
68 ) -> Result<Commit, Error>;
69 async fn repository_diff(
70 &mut self,
71 requester: &Option<AuthenticatedUser>,
72 repository: &Repository,
73 request: &RepositoryDiffRequest,
74 ) -> Result<RepositoryDiff, Error>;
75 async fn repository_diff_patch(
76 &mut self,
77 requester: &Option<AuthenticatedUser>,
78 repository: &Repository,
79 request: &RepositoryDiffPatchRequest,
80 ) -> Result<String, Error>;
81 async fn repository_commit_before(
82 &mut self,
83 requester: &Option<AuthenticatedUser>,
84 repository: &Repository,
85 request: &RepositoryCommitBeforeRequest,
86 ) -> Result<Commit, Error>;
87 async fn repository_get_statistics(
88 &mut self,
89 requester: &Option<AuthenticatedUser>,
90 repository: &Repository,
91 request: &RepositoryStatisticsRequest,
92 ) -> Result<RepositoryStatistics, Error>;
93 async fn repository_get_branches(
94 &mut self,
95 requester: &Option<AuthenticatedUser>,
96 repository: &Repository,
97 request: &RepositoryBranchesRequest,
98 ) -> Result<Vec<RepositoryBranch>, Error>;
99 async fn get_value(
100 &mut self,
101 user: &Repository,
102 name: &str,
103 ) -> Result<AnyValue<Repository>, Error>;
104 async fn get_setting(&mut self, user: &Repository, name: &str) -> Result<AnySetting, Error>;
105 async fn write_setting(
106 &mut self,
107 repository: &Repository,
108 name: &str,
109 setting: &Value,
110 ) -> Result<(), Error>;
111 async fn exists(
112 &mut self,
113 requester: &Option<AuthenticatedUser>,
114 repository: &Repository,
115 ) -> Result<bool, Error>;
116 }
117
118 pub trait IssuesBackend {
119 fn issues_count(
120 &mut self,
121 requester: &Option<AuthenticatedUser>,
122 request: &RepositoryIssuesCountRequest,
123 ) -> Result<u64, Error>;
124 fn issue_labels(
125 &mut self,
126 requester: &Option<AuthenticatedUser>,
127 request: &RepositoryIssueLabelsRequest,
128 ) -> Result<Vec<IssueLabel>, Error>;
129 fn issues(
130 &mut self,
131 requester: &Option<AuthenticatedUser>,
132 request: &RepositoryIssuesRequest,
133 ) -> Result<Vec<RepositoryIssue>, Error>;
134 }
135
136 #[async_trait::async_trait]
137 pub trait AuthBackend {
138 async fn register(
139 &mut self,
140 request: RegisterAccountRequest,
141 ) -> Result<UserAuthenticationToken, Error>;
142
143 async fn login(
144 &mut self,
145 source: &Instance,
146 request: AuthenticationTokenRequest,
147 ) -> Result<UserAuthenticationToken, Error>;
148 }
149
150 #[async_trait::async_trait]
151 pub trait UserBackend: AuthBackend {
152 async fn get_value(&mut self, user: &User, name: &str) -> Result<AnyValue<User>, Error>;
153 async fn get_setting(&mut self, user: &User, name: &str) -> Result<AnySetting, Error>;
154 async fn write_setting(
155 &mut self,
156 user: &User,
157 name: &str,
158 setting: &Value,
159 ) -> Result<(), Error>;
160 async fn exists(&mut self, user: &User) -> Result<bool, Error>;
161 async fn repositories_for_user(
162 &mut self,
163 requester: &Option<AuthenticatedUser>,
164 user: &User,
165 ) -> Result<Vec<RepositorySummary>, Error>;
166 }
167
168 #[async_trait::async_trait]
169 pub trait MetadataBackend {
170 async fn user_get(&mut self, user: &User, name: &str) -> Result<AnySetting, Error>;
171 async fn user_write(
172 &mut self,
173 user: &User,
174 name: &str,
175 setting: AnySetting,
176 ) -> Result<(), Error>;
177 async fn repository_get(
178 &mut self,
179 repository: &Repository,
180 name: &str,
181 ) -> Result<AnySetting, Error>;
182 async fn repository_write(
183 &mut self,
184 repository: &Repository,
185 name: &str,
186 setting: AnySetting,
187 ) -> Result<(), Error>;
188 }
189