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

ambee/giterated

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

Add docs

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨51aad53

⁨src/messages/repository.rs⁩ - ⁨6078⁩ bytes
Raw
1 use serde::{Deserialize, Serialize};
2
3 use crate::model::repository::RepositoryVisibility;
4 use crate::model::{
5 repository::{Commit, Repository, RepositoryTreeEntry, RepositoryView},
6 user::User,
7 };
8
9 use super::UnvalidatedUserAuthenticated;
10
11 /// A repository message.
12 ///
13 /// View request documentation, authentication, and authorization
14 /// details in the associated type, [`RepositoryRequest`].
15 #[derive(Clone, Serialize, Deserialize)]
16 pub struct RepositoryMessage {
17 pub target: Repository,
18 pub command: RepositoryMessageKind,
19 }
20
21 #[derive(Clone, Serialize, Deserialize)]
22 pub enum RepositoryMessageKind {
23 Request(RepositoryRequest),
24 Response(RepositoryResponse),
25 }
26
27 #[derive(Clone, Serialize, Deserialize)]
28 pub enum RepositoryRequest {
29 /// A request to create a repository.
30 ///
31 /// # Authentication
32 /// - Instance Authentication
33 /// - Used to validate User token `issued_for`
34 /// - User Authentication
35 /// - Used to source owning user
36 /// - Used to authorize user token against user's instance
37 /// # Authorization
38 /// - Instance Authorization
39 /// - Used to authorize action using User token requiring a correct `issued_for` and valid issuance from user's instance
40 /// - User Authorization
41 /// - Potential User permissions checks
42 CreateRepository(UnvalidatedUserAuthenticated<CreateRepositoryRequest>),
43
44 /// A request to inspect the tree of a repository.
45 ///
46 /// # Authentication
47 /// - Instance Authentication
48 /// - Validate request against the `issued_for` public key
49 /// - Validate User token against the user's instance's public key
50 /// # Authorization
51 /// - User Authorization
52 /// - Potential User permissions checks
53 RepositoryFileInspect(UnvalidatedUserAuthenticated<RepositoryFileInspectRequest>),
54
55 /// A request to get a repository's information.
56 ///
57 /// # Authentication
58 /// - Instance Authentication
59 /// - Validate request against the `issued_for` public key
60 /// - Validate User token against the user's instance's public key
61 /// # Authorization
62 /// - User Authorization
63 /// - Potential User permissions checks
64 RepositoryInfo(UnvalidatedUserAuthenticated<RepositoryInfoRequest>),
65
66 /// A request to get a repository's issues count.
67 ///
68 /// # Authentication
69 /// - Instance Authentication
70 /// - Validate request against the `issued_for` public key
71 /// - Validate User token against the user's instance's public key
72 /// # Authorization
73 /// - User Authorization
74 /// - Potential User permissions checks
75 IssuesCount(UnvalidatedUserAuthenticated<RepositoryIssuesCountRequest>),
76
77 /// A request to get a repository's issue labels.
78 ///
79 /// # Authentication
80 /// - Instance Authentication
81 /// - Validate request against the `issued_for` public key
82 /// - Validate User token against the user's instance's public key
83 /// # Authorization
84 /// - User Authorization
85 /// - Potential User permissions checks
86 IssueLabels(UnvalidatedUserAuthenticated<RepositoryIssueLabelsRequest>),
87
88 /// A request to get a repository's issues.
89 ///
90 /// # Authentication
91 /// - Instance Authentication
92 /// - Validate request against the `issued_for` public key
93 /// - Validate User token against the user's instance's public key
94 /// # Authorization
95 /// - User Authorization
96 /// - Potential User permissions checks
97 Issues(UnvalidatedUserAuthenticated<RepositoryIssuesRequest>),
98 }
99
100 #[derive(Clone, Serialize, Deserialize)]
101 pub enum RepositoryResponse {
102 CreateRepository(CreateRepositoryResponse),
103 RepositoryFileInspection(RepositoryFileInspectionResponse),
104 RepositoryInfo(RepositoryView),
105 IssuesCount(RepositoryIssuesCountResponse),
106 IssueLabels(RepositoryIssueLabelsResponse),
107 Issues(RepositoryIssuesResponse),
108 }
109
110 /// See [`RepositoryRequest::CreateRepository`]'s documentation.
111 #[derive(Clone, Serialize, Deserialize)]
112 pub struct CreateRepositoryRequest {
113 pub name: String,
114 pub description: Option<String>,
115 pub visibility: RepositoryVisibility,
116 pub default_branch: String,
117 pub owner: User,
118 }
119
120 #[derive(Clone, Serialize, Deserialize)]
121 pub enum CreateRepositoryResponse {
122 Created,
123 Failed,
124 }
125
126 /// See [`RepositoryRequest::RepositoryFileInspect`]'s documentation.
127 #[derive(Clone, Serialize, Deserialize)]
128 pub struct RepositoryFileInspectRequest {
129 pub path: RepositoryTreeEntry,
130 }
131
132 #[derive(Clone, Serialize, Deserialize)]
133 pub enum RepositoryFileInspectionResponse {
134 File {
135 commit_metadata: Commit,
136 },
137 Folder {
138 commit_metadata: Commit,
139 members: Vec<RepositoryTreeEntry>,
140 },
141 Invalid {
142 path: RepositoryTreeEntry,
143 },
144 }
145
146 /// See [`RepositoryRequest::IssuesCount`]'s documentation.
147 #[derive(Clone, Serialize, Deserialize)]
148 pub struct RepositoryIssuesCountRequest;
149
150 #[derive(Clone, Serialize, Deserialize)]
151 pub struct RepositoryIssuesCountResponse {
152 pub count: u64,
153 }
154
155 /// See [`RepositoryRequest::IssueLabels`]'s documentation.
156 #[derive(Clone, Serialize, Deserialize)]
157 pub struct RepositoryIssueLabelsRequest;
158
159 #[derive(Clone, Serialize, Deserialize)]
160 pub struct RepositoryIssueLabelsResponse {
161 pub labels: Vec<IssueLabel>,
162 }
163
164 #[derive(Clone, Serialize, Deserialize)]
165 pub struct IssueLabel {
166 pub name: String,
167 pub color: String,
168 }
169
170 /// See [`RepositoryRequest::Issues`]'s documentation.
171 #[derive(Clone, Serialize, Deserialize)]
172 pub struct RepositoryIssuesRequest;
173
174 #[derive(Clone, Serialize, Deserialize)]
175 pub struct RepositoryIssuesResponse {
176 pub issues: Vec<RepositoryIssue>,
177 }
178
179 #[derive(Clone, Serialize, Deserialize)]
180 pub struct RepositoryIssue {
181 pub author: User,
182 pub id: u64,
183 pub title: String,
184 pub contents: String,
185 pub labels: Vec<IssueLabel>,
186 }
187
188 #[derive(Clone, Serialize, Deserialize)]
189 pub struct RepositoryInfoRequest {
190 pub repository: Repository,
191 pub extra_metadata: bool,
192 pub rev: Option<String>,
193 pub path: Option<String>,
194 }
195