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

ambee/giterated

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

Basic tag search and range

Emilia - ⁨1⁩ year ago

parent: tbd commit: ⁨112ca96

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