diff --git a/giterated-daemon/src/backend/git.rs b/giterated-daemon/src/backend/git.rs index e6f18a8..35af1c9 100644 --- a/giterated-daemon/src/backend/git.rs +++ b/giterated-daemon/src/backend/git.rs @@ -779,12 +779,14 @@ impl RepositoryBackend for GitBackend { }) } + /// .0: List of branches filtering by passed requirements. + /// .1: Total amount of branches after being filtered async fn repository_get_branches( &mut self, requester: &Option, repository: &Repository, request: &RepositoryBranchesRequest, - ) -> Result, Error> { + ) -> Result<(Vec, usize), Error> { let git = self .open_repository_and_check_permissions(&repository.owner, &repository.name, requester) .await?; @@ -823,6 +825,9 @@ impl RepositoryBackend for GitBackend { }) .collect::>(); + // Get the total amount of filtered branches + let branch_count = filtered_branches.len(); + // Sort the branches by commit date filtered_branches.sort_by(|(_, _, _, c1), (_, _, _, c2)| c2.time.cmp(&c1.time)); // Go to the requested position @@ -853,7 +858,7 @@ impl RepositoryBackend for GitBackend { }) } - Ok(branches) + Ok((branches, branch_count)) } async fn repository_diff( diff --git a/giterated-daemon/src/backend/mod.rs b/giterated-daemon/src/backend/mod.rs index 5b1b836..5b2400f 100644 --- a/giterated-daemon/src/backend/mod.rs +++ b/giterated-daemon/src/backend/mod.rs @@ -94,7 +94,7 @@ pub trait RepositoryBackend { requester: &Option, repository: &Repository, request: &RepositoryBranchesRequest, - ) -> Result, Error>; + ) -> Result<(Vec, usize), Error>; async fn exists( &mut self, requester: &Option, diff --git a/giterated-daemon/src/client.rs b/giterated-daemon/src/client.rs index dccb2f3..9875319 100644 --- a/giterated-daemon/src/client.rs +++ b/giterated-daemon/src/client.rs @@ -3,9 +3,10 @@ use giterated_models::{ error::{IntoInternalError, OperationError}, instance::Instance, object_backend::ObjectBackend, + user::User, }; use giterated_protocol::{AuthenticatedPayload, NetworkedObject, NetworkedOperation}; -use giterated_stack::{GiteratedStack, StackOperationState}; +use giterated_stack::{AuthenticatedUser, GiteratedStack, StackOperationState}; use tokio::net::TcpStream; use tokio_tungstenite::{tungstenite::Message, WebSocketStream}; @@ -69,7 +70,10 @@ pub async fn client_wrapper( our_instance: our_instance.clone(), runtime: runtime.clone(), instance: None, - user: None, + user: Some(AuthenticatedUser::new(User { + username: "uwu".to_string(), + instance: Instance("giterated.dev".to_string()), + })), }; let result = handle_client_message(payload, operation_state, runtime.clone()).await; diff --git a/giterated-daemon/src/database_backend/handler.rs b/giterated-daemon/src/database_backend/handler.rs index ac35403..f743e87 100644 --- a/giterated-daemon/src/database_backend/handler.rs +++ b/giterated-daemon/src/database_backend/handler.rs @@ -148,7 +148,7 @@ pub async fn repository_get_branches( OperationState(operation_state): OperationState, backend: GiteratedStack, requester: Option, -) -> Result, OperationError> { +) -> Result<(Vec, usize), OperationError> { let object = backend .get_object::(&object.to_string(), &operation_state) .await diff --git a/giterated-models/src/repository/operations.rs b/giterated-models/src/repository/operations.rs index cea036d..eee751a 100644 --- a/giterated-models/src/repository/operations.rs +++ b/giterated-models/src/repository/operations.rs @@ -254,6 +254,7 @@ impl GiteratedOperation for RepositoryStatisticsRequest { } /// A request to get a list of branches in the repository. +/// Also returns the total amount of branches after the filter is applied. /// Skips over references with invalid UTF-8 names. /// /// # Authentication @@ -270,7 +271,7 @@ pub struct RepositoryBranchesRequest { } impl GiteratedOperation for RepositoryBranchesRequest { - type Success = Vec; + type Success = (Vec, usize); type Failure = RepositoryError; } @@ -399,7 +400,7 @@ impl + std::fmt::Debug> Object<'_, S range_start: usize, range_end: usize, operation_state: &S, - ) -> Result, OperationError> { + ) -> Result<(Vec, usize), OperationError> { self.request::( RepositoryBranchesRequest { filter,