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