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

ambee/giterated

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

Add total amount of branches after filter

Emilia - ⁨1⁩ year ago

parent: tbd commit: ⁨c29b3b8

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