Incomplete repository branches request
parent: tbd commit: 6872fbf
Showing 7 changed files with 155 insertions and 9 deletions
Cargo.lock
@@ -431,6 +431,18 @@ dependencies = [ | ||
431 | 431 | ] |
432 | 432 | |
433 | 433 | [[package]] |
434 | name = "deadpool" | |
435 | version = "0.10.0" | |
436 | source = "registry+https://github.com/rust-lang/crates.io-index" | |
437 | checksum = "fb84100978c1c7b37f09ed3ce3e5f843af02c2a2c431bae5b19230dad2c1b490" | |
438 | dependencies = [ | |
439 | "async-trait", | |
440 | "deadpool-runtime", | |
441 | "num_cpus", | |
442 | "tokio", | |
443 | ] | |
444 | ||
445 | [[package]] | |
434 | 446 | name = "deadpool-runtime" |
435 | 447 | version = "0.1.2" |
436 | 448 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -739,7 +751,7 @@ dependencies = [ | ||
739 | 751 | "bincode", |
740 | 752 | "chrono", |
741 | 753 | "color-eyre", |
742 | "deadpool", | |
754 | "deadpool 0.10.0", | |
743 | 755 | "futures-util", |
744 | 756 | "giterated-models", |
745 | 757 | "jsonwebtoken", |
@@ -766,7 +778,7 @@ dependencies = [ | ||
766 | 778 | "base64 0.21.3", |
767 | 779 | "bincode", |
768 | 780 | "chrono", |
769 | "deadpool", | |
781 | "deadpool 0.9.5", | |
770 | 782 | "futures-util", |
771 | 783 | "git2", |
772 | 784 | "giterated-api", |
@@ -979,6 +991,20 @@ dependencies = [ | ||
979 | 991 | ] |
980 | 992 | |
981 | 993 | [[package]] |
994 | name = "hyper-rustls" | |
995 | version = "0.24.1" | |
996 | source = "registry+https://github.com/rust-lang/crates.io-index" | |
997 | checksum = "8d78e1e73ec14cf7375674f74d7dde185c8206fd9dea6fb6295e8a98098aaa97" | |
998 | dependencies = [ | |
999 | "futures-util", | |
1000 | "http", | |
1001 | "hyper", | |
1002 | "rustls", | |
1003 | "tokio", | |
1004 | "tokio-rustls", | |
1005 | ] | |
1006 | ||
1007 | [[package]] | |
982 | 1008 | name = "hyper-tls" |
983 | 1009 | version = "0.5.0" |
984 | 1010 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1658,6 +1684,7 @@ dependencies = [ | ||
1658 | 1684 | "http", |
1659 | 1685 | "http-body", |
1660 | 1686 | "hyper", |
1687 | "hyper-rustls", | |
1661 | 1688 | "hyper-tls", |
1662 | 1689 | "ipnet", |
1663 | 1690 | "js-sys", |
@@ -1667,16 +1694,20 @@ dependencies = [ | ||
1667 | 1694 | "once_cell", |
1668 | 1695 | "percent-encoding", |
1669 | 1696 | "pin-project-lite", |
1697 | "rustls", | |
1698 | "rustls-pemfile", | |
1670 | 1699 | "serde", |
1671 | 1700 | "serde_json", |
1672 | 1701 | "serde_urlencoded", |
1673 | 1702 | "tokio", |
1674 | 1703 | "tokio-native-tls", |
1704 | "tokio-rustls", | |
1675 | 1705 | "tower-service", |
1676 | 1706 | "url", |
1677 | 1707 | "wasm-bindgen", |
1678 | 1708 | "wasm-bindgen-futures", |
1679 | 1709 | "web-sys", |
1710 | "webpki-roots", | |
1680 | 1711 | "winreg", |
1681 | 1712 | ] |
1682 | 1713 | |
@@ -2827,6 +2858,12 @@ dependencies = [ | ||
2827 | 2858 | ] |
2828 | 2859 | |
2829 | 2860 | [[package]] |
2861 | name = "webpki-roots" | |
2862 | version = "0.25.2" | |
2863 | source = "registry+https://github.com/rust-lang/crates.io-index" | |
2864 | checksum = "14247bb57be4f377dfb94c72830b8ce8fc6beac03cf4bf7b9732eadd414123fc" | |
2865 | ||
2866 | [[package]] | |
2830 | 2867 | name = "whoami" |
2831 | 2868 | version = "1.4.1" |
2832 | 2869 | source = "registry+https://github.com/rust-lang/crates.io-index" |
giterated-daemon/src/backend/git.rs
@@ -11,7 +11,7 @@ use giterated_models::repository::{ | ||
11 | 11 | RepositoryDiffPatchRequest, RepositoryDiffRequest, RepositoryFile, RepositoryFileFromIdRequest, |
12 | 12 | RepositoryFileFromPathRequest, RepositoryFileInspectRequest, RepositoryIssue, |
13 | 13 | RepositoryIssueLabelsRequest, RepositoryIssuesCountRequest, RepositoryIssuesRequest, |
14 | RepositoryObjectType, RepositoryTreeEntry, RepositoryVisibility, Visibility, RepositoryCommitFromIdRequest, RepositoryLastCommitOfFileRequest, RepositoryStatisticsRequest, RepositoryStatistics, | |
14 | RepositoryObjectType, RepositoryTreeEntry, RepositoryVisibility, Visibility, RepositoryCommitFromIdRequest, RepositoryLastCommitOfFileRequest, RepositoryStatisticsRequest, RepositoryStatistics, RepositoryBranchesRequest, RepositoryBranch, | |
15 | 15 | }; |
16 | 16 | use giterated_models::settings::{AnySetting, Setting}; |
17 | 17 | use giterated_models::user::{User, UserParseError}; |
@@ -876,6 +876,32 @@ impl RepositoryBackend for GitBackend { | ||
876 | 876 | }) |
877 | 877 | } |
878 | 878 | |
879 | async fn repository_get_branches( | |
880 | &mut self, | |
881 | requester: &Option<AuthenticatedUser>, | |
882 | repository: &Repository, | |
883 | _request: &RepositoryBranchesRequest, | |
884 | ) -> Result<Vec<RepositoryBranch>, Error> { | |
885 | let git = self | |
886 | .open_repository_and_check_permissions(&repository.owner, &repository.name, requester) | |
887 | .await?; | |
888 | ||
889 | let mut branches = vec![]; | |
890 | ||
891 | // TODO: Add details like stale and such | |
892 | for branch in git.branches(None)? { | |
893 | let branch = branch?; | |
894 | ||
895 | let Some(name) = branch.0.name().ok().flatten() else { | |
896 | continue; | |
897 | }; | |
898 | ||
899 | branches.push(RepositoryBranch { name: name.to_string() }) | |
900 | } | |
901 | ||
902 | Ok(branches) | |
903 | } | |
904 | ||
879 | 905 | async fn repository_diff( |
880 | 906 | &mut self, |
881 | 907 | requester: &Option<AuthenticatedUser>, |
giterated-daemon/src/backend/mod.rs
@@ -21,7 +21,7 @@ use giterated_models::repository::{ | ||
21 | 21 | RepositoryDiffPatchRequest, RepositoryDiffRequest, RepositoryFile, RepositoryFileFromIdRequest, |
22 | 22 | RepositoryFileFromPathRequest, RepositoryFileInspectRequest, RepositoryIssue, |
23 | 23 | RepositoryIssueLabelsRequest, RepositoryIssuesCountRequest, RepositoryIssuesRequest, |
24 | RepositorySummary, RepositoryTreeEntry, RepositoryCommitFromIdRequest, RepositoryLastCommitOfFileRequest, RepositoryStatistics, RepositoryStatisticsRequest, | |
24 | RepositorySummary, RepositoryTreeEntry, RepositoryCommitFromIdRequest, RepositoryLastCommitOfFileRequest, RepositoryStatistics, RepositoryStatisticsRequest, RepositoryBranchesRequest, RepositoryBranch, | |
25 | 25 | }; |
26 | 26 | use giterated_models::settings::AnySetting; |
27 | 27 | use giterated_models::user::User; |
@@ -88,6 +88,12 @@ pub trait RepositoryBackend { | ||
88 | 88 | repository: &Repository, |
89 | 89 | request: &RepositoryStatisticsRequest, |
90 | 90 | ) -> Result<RepositoryStatistics, Error>; |
91 | async fn repository_get_branches( | |
92 | &mut self, | |
93 | requester: &Option<AuthenticatedUser>, | |
94 | repository: &Repository, | |
95 | request: &RepositoryBranchesRequest, | |
96 | ) -> Result<Vec<RepositoryBranch>, Error>; | |
91 | 97 | async fn get_value( |
92 | 98 | &mut self, |
93 | 99 | user: &Repository, |
giterated-daemon/src/database_backend/handler.rs
@@ -13,7 +13,7 @@ use giterated_models::{ | ||
13 | 13 | RepositoryCommitBeforeRequest, RepositoryDiff, RepositoryDiffPatchRequest, |
14 | 14 | RepositoryDiffRequest, RepositoryFile, RepositoryFileFromIdRequest, |
15 | 15 | RepositoryFileFromPathRequest, RepositoryFileInspectRequest, RepositoryInfoRequest, |
16 | RepositorySummary, RepositoryView, Visibility, RepositoryCommitFromIdRequest, RepositoryLastCommitOfFileRequest, RepositoryStatisticsRequest, RepositoryStatistics, | |
16 | RepositorySummary, RepositoryView, Visibility, RepositoryCommitFromIdRequest, RepositoryLastCommitOfFileRequest, RepositoryStatisticsRequest, RepositoryStatistics, RepositoryBranchesRequest, RepositoryBranch, | |
17 | 17 | }, |
18 | 18 | settings::{AnySetting, GetSetting, GetSettingError, SetSetting, SetSettingError}, |
19 | 19 | user::{User, UserRepositoriesRequest}, |
@@ -211,6 +211,38 @@ pub fn repository_get_statistics( | ||
211 | 211 | .boxed() |
212 | 212 | } |
213 | 213 | |
214 | pub fn repository_get_branches( | |
215 | object: &Repository, | |
216 | operation: RepositoryBranchesRequest, | |
217 | state: DatabaseBackend, | |
218 | operation_state: StackOperationState, | |
219 | backend: BackendWrapper, | |
220 | requester: Option<AuthenticatedUser>, | |
221 | ) -> BoxFuture<'static, Result<Vec<RepositoryBranch>, OperationError<RepositoryError>>> { | |
222 | let object = object.clone(); | |
223 | ||
224 | async move { | |
225 | let object = backend | |
226 | .get_object::<Repository>(&object.to_string(), &operation_state) | |
227 | .await | |
228 | .unwrap(); | |
229 | ||
230 | let mut repository_backend = state.repository_backend.lock().await; | |
231 | let branches = repository_backend | |
232 | .repository_get_branches( | |
233 | &requester, | |
234 | object.object(), | |
235 | &operation, | |
236 | ) | |
237 | .await | |
238 | .map_err(|err| OperationError::Internal(format!("{:?}", err)))?; | |
239 | drop(repository_backend); | |
240 | ||
241 | Ok(branches) | |
242 | } | |
243 | .boxed() | |
244 | } | |
245 | ||
214 | 246 | pub fn repository_file_from_id( |
215 | 247 | object: &Repository, |
216 | 248 | operation: RepositoryFileFromIdRequest, |
giterated-daemon/src/database_backend/mod.rs
@@ -21,7 +21,7 @@ use self::handler::{ | ||
21 | 21 | instance_registration_request, repository_commit_before, repository_diff, |
22 | 22 | repository_diff_patch, repository_file_from_id, repository_file_from_path, |
23 | 23 | repository_get_setting, repository_get_value, repository_info, repository_set_setting, |
24 | user_get_repositories, user_get_setting, user_get_value, user_set_setting, repository_commit_by_id, repository_last_commit_of_file, repository_get_statistics, | |
24 | user_get_repositories, user_get_setting, user_get_value, user_set_setting, repository_commit_by_id, repository_last_commit_of_file, repository_get_statistics, repository_get_branches, | |
25 | 25 | }; |
26 | 26 | |
27 | 27 | #[derive(Clone, Debug)] |
@@ -87,6 +87,7 @@ impl DatabaseBackend { | ||
87 | 87 | .insert(repository_diff) |
88 | 88 | .insert(repository_diff_patch) |
89 | 89 | .insert(repository_commit_before) |
90 | .insert(repository_get_branches) | |
90 | 91 | .insert(repository_get_value) |
91 | 92 | .insert(repository_get_setting) |
92 | 93 | .insert(repository_set_setting) |
@@ -128,7 +129,7 @@ mod test { | ||
128 | 129 | Commit, Description, Repository, RepositoryCommitBeforeRequest, RepositoryDiff, |
129 | 130 | RepositoryDiffPatchRequest, RepositoryDiffRequest, RepositoryFile, |
130 | 131 | RepositoryFileFromIdRequest, RepositoryFileFromPathRequest, RepositoryFileInspectRequest, |
131 | RepositorySummary, RepositoryTreeEntry, RepositoryCommitFromIdRequest, RepositoryLastCommitOfFileRequest, RepositoryStatisticsRequest, RepositoryStatistics, | |
132 | RepositorySummary, RepositoryTreeEntry, RepositoryCommitFromIdRequest, RepositoryLastCommitOfFileRequest, RepositoryStatisticsRequest, RepositoryStatistics, RepositoryBranch, RepositoryBranchesRequest, | |
132 | 133 | }; |
133 | 134 | use giterated_models::settings::AnySetting; |
134 | 135 | use giterated_models::user::{DisplayName, User}; |
@@ -280,6 +281,14 @@ mod test { | ||
280 | 281 | ) -> Result<RepositoryStatistics, Error> { |
281 | 282 | todo!() |
282 | 283 | } |
284 | async fn repository_get_branches( | |
285 | &mut self, | |
286 | _requester: &Option<AuthenticatedUser>, | |
287 | _repository: &Repository, | |
288 | _request: &RepositoryBranchesRequest, | |
289 | ) -> Result<Vec<RepositoryBranch>, Error> { | |
290 | todo!() | |
291 | } | |
283 | 292 | async fn get_value( |
284 | 293 | &mut self, |
285 | 294 | _repository: &Repository, |
giterated-models/src/repository/mod.rs
@@ -150,6 +150,13 @@ pub struct RepositoryStatistics { | ||
150 | 150 | pub tags: usize, |
151 | 151 | } |
152 | 152 | |
153 | /// Repository branch | |
154 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
155 | pub struct RepositoryBranch { | |
156 | /// Full reference name | |
157 | pub name: String, | |
158 | } | |
159 | ||
153 | 160 | #[derive(Clone, Debug, Serialize, Deserialize)] |
154 | 161 | pub struct RepositoryFile { |
155 | 162 | /// ID of the file |
giterated-models/src/repository/operations.rs
@@ -9,7 +9,7 @@ use crate::{ | ||
9 | 9 | |
10 | 10 | use super::{ |
11 | 11 | Commit, IssueLabel, Repository, RepositoryDiff, RepositoryFile, RepositoryIssue, |
12 | RepositoryTreeEntry, RepositoryView, RepositoryStatistics, | |
12 | RepositoryTreeEntry, RepositoryView, RepositoryStatistics, RepositoryBranch, | |
13 | 13 | }; |
14 | 14 | |
15 | 15 | /// A request to get a repository's information. |
@@ -253,6 +253,24 @@ impl GiteratedOperation<Repository> for RepositoryStatisticsRequest { | ||
253 | 253 | type Failure = RepositoryError; |
254 | 254 | } |
255 | 255 | |
256 | /// A request to get a list of branches in the repository. | |
257 | /// Skips over references with invalid UTF-8 names. | |
258 | /// | |
259 | /// # Authentication | |
260 | /// - Instance Authentication | |
261 | /// - Validate request against the `issued_for` public key | |
262 | /// - Validate User token against the user's instance's public key | |
263 | /// # Authorization | |
264 | /// - User Authorization | |
265 | /// - Potential User permissions checks | |
266 | #[derive(Clone, Debug, Serialize, Deserialize)] | |
267 | pub struct RepositoryBranchesRequest; | |
268 | ||
269 | impl GiteratedOperation<Repository> for RepositoryBranchesRequest { | |
270 | type Success = Vec<RepositoryBranch>; | |
271 | type Failure = RepositoryError; | |
272 | } | |
273 | ||
256 | 274 | impl<S: Clone + Send + Sync, B: ObjectBackend<S> + std::fmt::Debug> Object<'_, S, Repository, B> { |
257 | 275 | pub async fn info( |
258 | 276 | &mut self, |
@@ -363,7 +381,7 @@ impl<S: Clone + Send + Sync, B: ObjectBackend<S> + std::fmt::Debug> Object<'_, S | ||
363 | 381 | .await |
364 | 382 | } |
365 | 383 | |
366 | pub async fn repository_get_statistics( | |
384 | pub async fn statistics( | |
367 | 385 | &mut self, |
368 | 386 | rev: Option<String>, |
369 | 387 | operation_state: &S, |
@@ -375,6 +393,17 @@ impl<S: Clone + Send + Sync, B: ObjectBackend<S> + std::fmt::Debug> Object<'_, S | ||
375 | 393 | .await |
376 | 394 | } |
377 | 395 | |
396 | pub async fn branches( | |
397 | &mut self, | |
398 | operation_state: &S, | |
399 | ) -> Result<Vec<RepositoryBranch>, OperationError<RepositoryError>> { | |
400 | self.request::<RepositoryBranchesRequest>( | |
401 | RepositoryBranchesRequest, | |
402 | operation_state | |
403 | ) | |
404 | .await | |
405 | } | |
406 | ||
378 | 407 | // pub async fn issues_count(&mut self) -> Result<u64, OperationError<RepositoryError>> { |
379 | 408 | // self.request::<RepositoryIssuesCountRequest>(RepositoryIssuesCountRequest) |
380 | 409 | // .await |