diff --git a/rust/rhgitaly/proto/ref.proto b/rust/rhgitaly/proto/ref.proto index b26b6e98c7a657c7326f41b3841b5b2cb72985f6_cnVzdC9yaGdpdGFseS9wcm90by9yZWYucHJvdG8=..1e5ee2a7be9f146d4636db2524bc87cf4d595759_cnVzdC9yaGdpdGFseS9wcm90by9yZWYucHJvdG8= 100644 --- a/rust/rhgitaly/proto/ref.proto +++ b/rust/rhgitaly/proto/ref.proto @@ -13,6 +13,13 @@ service RefService { // This comment is left unintentionally blank. + rpc FindDefaultBranchName(FindDefaultBranchNameRequest) returns (FindDefaultBranchNameResponse) { + option (op_type) = { + op: ACCESSOR + }; + } + + // This comment is left unintentionally blank. rpc RefExists(RefExistsRequest) returns (RefExistsResponse) { option (op_type) = { op: ACCESSOR diff --git a/rust/rhgitaly/src/service/ref.rs b/rust/rhgitaly/src/service/ref.rs index b26b6e98c7a657c7326f41b3841b5b2cb72985f6_cnVzdC9yaGdpdGFseS9zcmMvc2VydmljZS9yZWYucnM=..1e5ee2a7be9f146d4636db2524bc87cf4d595759_cnVzdC9yaGdpdGFseS9zcmMvc2VydmljZS9yZWYucnM= 100644 --- a/rust/rhgitaly/src/service/ref.rs +++ b/rust/rhgitaly/src/service/ref.rs @@ -11,5 +11,9 @@ use crate::config::Config; use crate::gitaly::ref_service_server::{RefService, RefServiceServer}; -use crate::gitaly::{RefExistsRequest, RefExistsResponse}; +use crate::gitaly::{ + FindDefaultBranchNameRequest, FindDefaultBranchNameResponse, RefExistsRequest, + RefExistsResponse, +}; +use crate::gitlab::gitlab_branch_ref; use crate::gitlab::revision::{map_full_ref, RefError}; @@ -15,4 +19,5 @@ use crate::gitlab::revision::{map_full_ref, RefError}; +use crate::gitlab::state::get_gitlab_default_branch; use crate::metadata::correlation_id; use crate::repository::{default_repo_spec_error_status, repo_store_vfs}; @@ -23,6 +28,15 @@ #[tonic::async_trait] impl RefService for RefServiceImpl { + async fn find_default_branch_name( + &self, + request: Request<FindDefaultBranchNameRequest>, + ) -> Result<Response<FindDefaultBranchNameResponse>, Status> { + let (metadata, _ext, inner) = request.into_parts(); + + self.inner_find_default_branch_name(inner, correlation_id(&metadata)) + .await + } async fn ref_exists( &self, request: Request<RefExistsRequest>, @@ -46,6 +60,29 @@ } impl RefServiceImpl { + #[instrument(name = "find_default_branch_name", skip(self))] + async fn inner_find_default_branch_name( + &self, + request: FindDefaultBranchNameRequest, + correlation_id: Option<&MetadataValue<Ascii>>, + ) -> Result<Response<FindDefaultBranchNameResponse>, Status> { + info!("Processing"); + + let store_vfs = repo_store_vfs(&self.config, &request.repository) + .await + .map_err(default_repo_spec_error_status)?; + + Ok(Response::new(FindDefaultBranchNameResponse { + name: get_gitlab_default_branch(&store_vfs) + .await + .map_err(|e| { + Status::internal(format!("Error reading GitLab default branch: {:?}", e)) + })? + .map(|ref name| gitlab_branch_ref(name)) + .unwrap_or_else(Vec::new), + })) + } + #[instrument(name="ref_exists", skip(self, request), fields(request=field::debug(RefExistsTracingRequest(&request))))] diff --git a/tests_with_gitaly/test_ref.py b/tests_with_gitaly/test_ref.py index b26b6e98c7a657c7326f41b3841b5b2cb72985f6_dGVzdHNfd2l0aF9naXRhbHkvdGVzdF9yZWYucHk=..1e5ee2a7be9f146d4636db2524bc87cf4d595759_dGVzdHNfd2l0aF9naXRhbHkvdGVzdF9yZWYucHk= 100644 --- a/tests_with_gitaly/test_ref.py +++ b/tests_with_gitaly/test_ref.py @@ -62,8 +62,10 @@ same_details=False) -def test_compare_find_default_branch_name(gitaly_comparison): - fixture = gitaly_comparison +@parametrize('hg_server', ('hgitaly', 'rhgitaly')) +def test_compare_find_default_branch_name(gitaly_rhgitaly_comparison, + hg_server): + fixture = gitaly_rhgitaly_comparison git_repo = fixture.git_repo rpc_helper = fixture.rpc_helper( @@ -67,6 +69,7 @@ git_repo = fixture.git_repo rpc_helper = fixture.rpc_helper( + hg_server=hg_server, stub_cls=RefServiceStub, method_name='FindDefaultBranchName', request_cls=FindDefaultBranchNameRequest,