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

ambee/giterated

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

Simple branch staleness implementation

Emilia - ⁨1⁩ year ago

parent: tbd commit: ⁨efc3f02

⁨giterated-daemon/src/backend/mod.rs⁩ - ⁨5636⁩ 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, RepositoryBranchesRequest,
22 RepositoryCommitBeforeRequest, RepositoryCommitFromIdRequest, RepositoryDiff,
23 RepositoryDiffPatchRequest, RepositoryDiffRequest, RepositoryFile, RepositoryFileFromIdRequest,
24 RepositoryFileFromPathRequest, RepositoryFileInspectRequest, RepositoryIssue,
25 RepositoryIssueLabelsRequest, RepositoryIssuesCountRequest, RepositoryIssuesRequest,
26 RepositoryLastCommitOfFileRequest, RepositoryStatistics, RepositoryStatisticsRequest,
27 RepositorySummary, RepositoryTreeEntry,
28 };
29
30 use giterated_models::user::User;
31
32 #[async_trait(?Send)]
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_object: &mut Object<'_, StackOperationState, Repository, GiteratedStack>,
97 OperationState(operation_state): OperationState<StackOperationState>,
98 request: &RepositoryBranchesRequest,
99 ) -> Result<(Vec<RepositoryBranch>, usize), Error>;
100 async fn exists(
101 &mut self,
102 requester: &Option<AuthenticatedUser>,
103 repository: &Repository,
104 ) -> Result<bool, Error>;
105 }
106
107 pub trait IssuesBackend {
108 fn issues_count(
109 &mut self,
110 requester: &Option<AuthenticatedUser>,
111 request: &RepositoryIssuesCountRequest,
112 ) -> Result<u64, Error>;
113 fn issue_labels(
114 &mut self,
115 requester: &Option<AuthenticatedUser>,
116 request: &RepositoryIssueLabelsRequest,
117 ) -> Result<Vec<IssueLabel>, Error>;
118 fn issues(
119 &mut self,
120 requester: &Option<AuthenticatedUser>,
121 request: &RepositoryIssuesRequest,
122 ) -> Result<Vec<RepositoryIssue>, Error>;
123 }
124
125 #[async_trait::async_trait]
126 pub trait AuthBackend {
127 async fn register(
128 &mut self,
129 request: RegisterAccountRequest,
130 ) -> Result<UserAuthenticationToken, Error>;
131
132 async fn login(
133 &mut self,
134 source: &Instance,
135 request: AuthenticationTokenRequest,
136 ) -> Result<UserAuthenticationToken, Error>;
137 }
138
139 #[async_trait::async_trait]
140 pub trait UserBackend: AuthBackend {
141 async fn exists(&mut self, user: &User) -> Result<bool, Error>;
142 async fn repositories_for_user(
143 &mut self,
144 requester: &Option<AuthenticatedUser>,
145 user: &User,
146 ) -> Result<Vec<RepositorySummary>, Error>;
147 }
148
149 #[async_trait::async_trait]
150 pub trait MetadataBackend {
151 async fn user_get(&mut self, user: &User, name: &str) -> Result<Value, Error>;
152 async fn user_write(&mut self, user: &User, name: &str, setting: Value) -> Result<(), Error>;
153 async fn repository_get(&mut self, repository: &Repository, name: &str)
154 -> Result<Value, Error>;
155 async fn repository_write(
156 &mut self,
157 repository: &Repository,
158 name: &str,
159 setting: Value,
160 ) -> Result<(), Error>;
161 }
162