diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-10-12 14:54:23 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-10-12 14:59:17 +0300 |
commit | 59c2ea9caccb0ac8fd149f5a3559f91eb4c1096e (patch) | |
tree | 75baaf1648319448825c61ed7d8bd3278cd0965d /ruby | |
parent | e17f73ebc22d792ea9c8d8f4eb1ee674c211c393 (diff) |
ruby: Drop OperationsService implementation
The last RPC implemented by the OperationsService, UserApplyPatch, isn't
receiving any traffic anymore since v14.3.0. Drop the implmentation of
the service in the Ruby sidecar.
Diffstat (limited to 'ruby')
-rw-r--r-- | ruby/lib/gitaly_server.rb | 2 | ||||
-rw-r--r-- | ruby/lib/gitaly_server/operations_service.rb | 37 | ||||
-rw-r--r-- | ruby/lib/gitlab/git/commit_patches.rb | 33 | ||||
-rw-r--r-- | ruby/spec/lib/gitaly_server/exception_sanitizer_interceptor_spec.rb | 2 | ||||
-rw-r--r-- | ruby/spec/lib/gitaly_server/rugged_interceptor_spec.rb | 2 | ||||
-rw-r--r-- | ruby/spec/lib/gitaly_server/sentry/url_sanitizer_spec.rb | 2 | ||||
-rw-r--r-- | ruby/spec/lib/gitaly_server/sentry_interceptor_spec.rb | 6 | ||||
-rw-r--r-- | ruby/spec/lib/gitlab/git/commit_patches_spec.rb | 64 |
8 files changed, 6 insertions, 142 deletions
diff --git a/ruby/lib/gitaly_server.rb b/ruby/lib/gitaly_server.rb index 112cc635d..2e4b49805 100644 --- a/ruby/lib/gitaly_server.rb +++ b/ruby/lib/gitaly_server.rb @@ -5,7 +5,6 @@ require_relative 'gitlab/git.rb' require_relative 'gitaly_server/client.rb' require_relative 'gitaly_server/utils.rb' -require_relative 'gitaly_server/operations_service.rb' require_relative 'gitaly_server/repository_service.rb' require_relative 'gitaly_server/wiki_service.rb' require_relative 'gitaly_server/health_service.rb' @@ -45,7 +44,6 @@ module GitalyServer end def self.register_handlers(server) - server.handle(OperationsService.new) server.handle(RepositoryService.new) server.handle(WikiService.new) server.handle(HealthService.new) diff --git a/ruby/lib/gitaly_server/operations_service.rb b/ruby/lib/gitaly_server/operations_service.rb deleted file mode 100644 index a643eb4b6..000000000 --- a/ruby/lib/gitaly_server/operations_service.rb +++ /dev/null @@ -1,37 +0,0 @@ -module GitalyServer - class OperationsService < Gitaly::OperationService::Service - include Utils - - def user_apply_patch(call) - stream = call.each_remote_read - first_request = stream.next - - header = first_request.header - user = Gitlab::Git::User.from_gitaly(header.user) - target_branch = header.target_branch - patches = stream.lazy.map(&:patches) - - branch_update = Gitlab::Git::Repository.from_gitaly_with_block(header.repository, call) do |repo| - begin - Gitlab::Git::CommitPatches.new(user, repo, target_branch, patches, header.timestamp).commit - rescue Gitlab::Git::PatchError => e - raise GRPC::FailedPrecondition.new(e.message) - end - end - - Gitaly::UserApplyPatchResponse.new(branch_update: branch_update_result(branch_update)) - end - - private - - def branch_update_result(gitlab_update_result) - return if gitlab_update_result.nil? - - Gitaly::OperationBranchUpdate.new( - commit_id: gitlab_update_result.newrev, - repo_created: gitlab_update_result.repo_created, - branch_created: gitlab_update_result.branch_created - ) - end - end -end diff --git a/ruby/lib/gitlab/git/commit_patches.rb b/ruby/lib/gitlab/git/commit_patches.rb deleted file mode 100644 index 1b878d3d4..000000000 --- a/ruby/lib/gitlab/git/commit_patches.rb +++ /dev/null @@ -1,33 +0,0 @@ -module Gitlab - module Git - class CommitPatches - attr_reader :user, :repository, :branch_name, :patches - - def initialize(user, repository, branch_name, patches, timestamp = nil) - @user = user - @branch_name = branch_name - @patches = patches - @repository = repository - @timestamp = timestamp - end - - def commit - start_point = repository.find_branch(branch_name)&.target || repository.root_ref - - OperationService.new(user, repository).with_branch(branch_name) do - env = user.git_env - if @timestamp - env = env.merge( - { - 'GIT_AUTHOR_DATE' => "#{@timestamp.seconds} +0000", - 'GIT_COMMITTER_DATE' => "#{@timestamp.seconds} +0000" - } - ) - end - - repository.commit_patches(start_point, patches, extra_env: env) - end - end - end - end -end diff --git a/ruby/spec/lib/gitaly_server/exception_sanitizer_interceptor_spec.rb b/ruby/spec/lib/gitaly_server/exception_sanitizer_interceptor_spec.rb index 7e3bc328d..a148e5ca0 100644 --- a/ruby/spec/lib/gitaly_server/exception_sanitizer_interceptor_spec.rb +++ b/ruby/spec/lib/gitaly_server/exception_sanitizer_interceptor_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' require_relative '../../../lib/gitaly_server/exception_sanitizer_interceptor.rb' describe GitalyServer::ExceptionSanitizerInterceptor do - let(:meth) { GitalyServer::OperationsService.instance_method(:user_create_branch) } + let(:meth) { GitalyServer::WikiService.instance_method(:wiki_write_page) } let(:ex) { StandardError.new("error: failed to push some refs to 'https://fO0BA7:HunTer!@github.com/ruby/ruby.git'") } let(:ex_sanitized_message) { "error: failed to push some refs to 'https://[FILTERED]@github.com/ruby/ruby.git'" } let(:call) { double(metadata: {}) } diff --git a/ruby/spec/lib/gitaly_server/rugged_interceptor_spec.rb b/ruby/spec/lib/gitaly_server/rugged_interceptor_spec.rb index d6df2f407..d99e786cf 100644 --- a/ruby/spec/lib/gitaly_server/rugged_interceptor_spec.rb +++ b/ruby/spec/lib/gitaly_server/rugged_interceptor_spec.rb @@ -5,7 +5,7 @@ require_relative '../../../lib/gitaly_server/rugged_interceptor.rb' describe GitalyServer::RuggedInterceptor do include TestRepo - let(:meth) { GitalyServer::OperationsService.instance_method(:user_create_branch) } + let(:meth) { GitalyServer::WikiService.instance_method(:wiki_write_page) } let(:call) { double(metadata: {}) } subject do diff --git a/ruby/spec/lib/gitaly_server/sentry/url_sanitizer_spec.rb b/ruby/spec/lib/gitaly_server/sentry/url_sanitizer_spec.rb index d7a49410b..72d9443a6 100644 --- a/ruby/spec/lib/gitaly_server/sentry/url_sanitizer_spec.rb +++ b/ruby/spec/lib/gitaly_server/sentry/url_sanitizer_spec.rb @@ -4,7 +4,7 @@ require 'raven/base' require 'raven/transports/dummy' require_relative '../../../../lib/gitaly_server/sentry.rb' describe GitalyServer::Sentry::URLSanitizer do - let(:meth) { GitalyServer::OperationsService.instance_method(:user_create_branch) } + let(:meth) { GitalyServer::WikiService.instance_method(:wiki_write_page) } let(:ex) { StandardError.new("error: failed to push some refs to 'https://fO0BA7:HunTer!@github.com/ruby/ruby.git'") } let(:ex_sanitized_message) { "error: failed to push some refs to 'https://[FILTERED]@github.com/ruby/ruby.git'" } let(:call) { double(metadata: {}) } diff --git a/ruby/spec/lib/gitaly_server/sentry_interceptor_spec.rb b/ruby/spec/lib/gitaly_server/sentry_interceptor_spec.rb index 3711a616c..83c3c6119 100644 --- a/ruby/spec/lib/gitaly_server/sentry_interceptor_spec.rb +++ b/ruby/spec/lib/gitaly_server/sentry_interceptor_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require_relative '../../../lib/gitaly_server/sentry_interceptor.rb' describe GitalyServer::SentryInterceptor do describe 'handling exceptions' do - let(:meth) { GitalyServer::OperationsService.instance_method(:user_update_branch) } + let(:meth) { GitalyServer::WikiService.instance_method(:wiki_write_page) } let(:ex) { ArgumentError.new("unknown encoding") } let(:call) { nil } @@ -45,7 +45,7 @@ describe GitalyServer::SentryInterceptor do let(:expected_tags) do call_metadata.merge( 'system' => 'gitaly-ruby', - 'gitaly-ruby.method' => 'Gitaly::OperationService::Service#user_update_branch', + 'gitaly-ruby.method' => 'GitalyServer::WikiService#wiki_write_page', Labkit::Correlation::CorrelationId::LOG_KEY => anything ) end @@ -68,7 +68,7 @@ describe GitalyServer::SentryInterceptor do it 'sends the exception to Sentry' do expect(Raven).to receive(:capture_exception).with( ex, - fingerprint: ['gitaly-ruby', 'Gitaly::OperationService::Service#user_update_branch', 'unknown encoding'] + fingerprint: ['gitaly-ruby', 'GitalyServer::WikiService#wiki_write_page', 'unknown encoding'] ) begin diff --git a/ruby/spec/lib/gitlab/git/commit_patches_spec.rb b/ruby/spec/lib/gitlab/git/commit_patches_spec.rb deleted file mode 100644 index 7703c7127..000000000 --- a/ruby/spec/lib/gitlab/git/commit_patches_spec.rb +++ /dev/null @@ -1,64 +0,0 @@ -require 'spec_helper' - -describe Gitlab::Git::CommitPatches do - include TestRepo - - describe "#commit" do - let(:repository) { gitlab_git_from_gitaly(new_mutable_test_repo) } - let(:testdata_dir) { File.join(File.dirname(__FILE__), '../../../../../internal/gitaly/service/operations/testdata') } - let(:patches) { File.foreach(File.join(testdata_dir, patch_file_name)) } - let(:user) { Gitlab::Git::User.new('jane', 'Jane Doe', 'jane@doe.org', '123') } - - def apply_patches(branch_name) - described_class.new(user, repository, branch_name, patches).commit - end - - context 'when the patch applies' do - let(:patch_file_name) { '0001-A-commit-from-a-patch.patch' } - - it 'creates the branch and applies the patch' do - branch_update = apply_patches('patched_branch') - commit = repository.commit(branch_update.newrev) - - expect(commit.message).to eq("A commit from a patch\n") - expect(branch_update).to be_branch_created - end - - it 'updates the branch if it already existed' do - branch_update = apply_patches('feature') - commit = repository.commit(branch_update.newrev) - - expect(commit.message).to eq("A commit from a patch\n") - expect(branch_update).not_to be_branch_created - end - end - - context 'when the patch does not apply' do - let(:patch_file_name) { '0001-This-does-not-apply-to-the-feature-branch.patch' } - - it 'raises a PatchError' do - expect { apply_patches('feature') }.to raise_error Gitlab::Git::PatchError - end - - it 'does not update the branch' do - expect do - begin - apply_patches('feature') - rescue Gitlab::Git::PatchError => e - e - end - end.not_to(change { repository.find_branch('feature').target }) - end - - it 'does not leave branches dangling' do - expect do - begin - apply_patches('feature') - rescue Gitlab::Git::PatchError => e - e - end - end.not_to(change { repository.branches.size }) - end - end - end -end |