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

ambee/giterated

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

Improve oid_from_reference tag id fetching and pass full Repository Object to every function

Emilia - ⁨1⁩ year ago

parent: tbd commit: ⁨6d7e35e

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