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

ambee/giterated

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

Repository commit before request and handler

Type: Feature

erremilia - ⁨2⁩ years ago

parent: tbd commit: ⁨144b159

⁨giterated-daemon/src/backend/mod.rs⁩ - ⁨4433⁩ 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 serde_json::Value;
10
11 use crate::backend::git::GitBackendError;
12 use giterated_models::authenticated::UserAuthenticationToken;
13
14 use giterated_models::instance::{
15 AuthenticationTokenRequest, Instance, RegisterAccountRequest, RepositoryCreateRequest,
16 };
17
18 use giterated_models::repository::{
19 IssueLabel, Repository, RepositoryFileInspectRequest, RepositoryIssue,
20 RepositoryIssueLabelsRequest, RepositoryIssuesCountRequest, RepositoryIssuesRequest,
21 RepositorySummary, RepositoryTreeEntry, RepositoryFileFromIdRequest, RepositoryFile, RepositoryDiffRequest, RepositoryDiff, Commit, RepositoryCommitBeforeRequest,
22 };
23 use giterated_models::settings::AnySetting;
24 use giterated_models::user::User;
25 use giterated_models::value::AnyValue;
26
27 #[async_trait]
28 pub trait RepositoryBackend {
29 async fn create_repository(
30 &mut self,
31 user: &User,
32 request: &RepositoryCreateRequest,
33 ) -> Result<Repository, GitBackendError>;
34 async fn repository_file_inspect(
35 &mut self,
36 requester: Option<&User>,
37 repository: &Repository,
38 request: &RepositoryFileInspectRequest,
39 ) -> Result<Vec<RepositoryTreeEntry>, Error>;
40 async fn repository_file_from_id(
41 &mut self,
42 requester: Option<&User>,
43 repository: &Repository,
44 request: &RepositoryFileFromIdRequest,
45 ) -> Result<RepositoryFile, Error>;
46 async fn repository_diff(
47 &mut self,
48 requester: Option<&User>,
49 repository: &Repository,
50 request: &RepositoryDiffRequest,
51 ) -> Result<RepositoryDiff, Error>;
52 async fn repository_commit_before(
53 &mut self,
54 requester: Option<&User>,
55 repository: &Repository,
56 request: &RepositoryCommitBeforeRequest,
57 ) -> Result<Commit, Error>;
58 async fn get_value(
59 &mut self,
60 user: &Repository,
61 name: &str,
62 ) -> Result<AnyValue<Repository>, Error>;
63 async fn get_setting(&mut self, user: &Repository, name: &str) -> Result<AnySetting, Error>;
64 async fn write_setting(
65 &mut self,
66 user: &Repository,
67 name: &str,
68 setting: &Value,
69 ) -> Result<(), Error>;
70 async fn exists(&mut self, repository: &Repository) -> Result<bool, Error>;
71 }
72
73 pub trait IssuesBackend {
74 fn issues_count(
75 &mut self,
76 requester: Option<&User>,
77 request: &RepositoryIssuesCountRequest,
78 ) -> Result<u64, Error>;
79 fn issue_labels(
80 &mut self,
81 requester: Option<&User>,
82 request: &RepositoryIssueLabelsRequest,
83 ) -> Result<Vec<IssueLabel>, Error>;
84 fn issues(
85 &mut self,
86 requester: Option<&User>,
87 request: &RepositoryIssuesRequest,
88 ) -> Result<Vec<RepositoryIssue>, Error>;
89 }
90
91 #[async_trait::async_trait]
92 pub trait AuthBackend {
93 async fn register(
94 &mut self,
95 request: RegisterAccountRequest,
96 ) -> Result<UserAuthenticationToken, Error>;
97
98 async fn login(
99 &mut self,
100 source: &Instance,
101 request: AuthenticationTokenRequest,
102 ) -> Result<UserAuthenticationToken, Error>;
103 }
104
105 #[async_trait::async_trait]
106 pub trait UserBackend: AuthBackend {
107 async fn get_value(&mut self, user: &User, name: &str) -> Result<AnyValue<User>, Error>;
108 async fn get_setting(&mut self, user: &User, name: &str) -> Result<AnySetting, Error>;
109 async fn write_setting(
110 &mut self,
111 user: &User,
112 name: &str,
113 setting: &Value,
114 ) -> Result<(), Error>;
115 async fn exists(&mut self, user: &User) -> Result<bool, Error>;
116 async fn repositories_for_user(
117 &mut self,
118 requester: Option<&User>,
119 user: &User,
120 ) -> Result<Vec<RepositorySummary>, Error>;
121 }
122
123 #[async_trait::async_trait]
124 pub trait MetadataBackend {
125 async fn user_get(&mut self, user: &User, name: &str) -> Result<AnySetting, Error>;
126 async fn user_write(
127 &mut self,
128 user: &User,
129 name: &str,
130 setting: AnySetting,
131 ) -> Result<(), Error>;
132 async fn repository_get(
133 &mut self,
134 repository: &Repository,
135 name: &str,
136 ) -> Result<AnySetting, Error>;
137 async fn repository_write(
138 &mut self,
139 repository: &Repository,
140 name: &str,
141 setting: AnySetting,
142 ) -> Result<(), Error>;
143 }
144