diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-07-13 09:30:58 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-07-13 10:44:59 +0300 |
commit | e99647c6dd9bb081c84f2c0212adae724f354d58 (patch) | |
tree | 62c3e463c51c418fbc63635acb8524bbcc7a369c | |
parent | 3d824572463e70b93cf46c0b659aea5f5990c86c (diff) |
operations: Let UserDeleteBranch hook into transactions
This commit adjusts the `UserDeleteBranch` RPC to hook into transactions
in case the corresponding feature flag is set.
-rw-r--r-- | internal/praefect/coordinator.go | 1 | ||||
-rw-r--r-- | internal/service/operations/branches_test.go | 49 | ||||
-rw-r--r-- | ruby/lib/gitaly_server/operations_service.rb | 3 | ||||
-rw-r--r-- | ruby/lib/gitlab/git/operation_service.rb | 4 | ||||
-rw-r--r-- | ruby/lib/gitlab/git/repository.rb | 4 |
5 files changed, 36 insertions, 25 deletions
diff --git a/internal/praefect/coordinator.go b/internal/praefect/coordinator.go index 9ce300417..a32d096cf 100644 --- a/internal/praefect/coordinator.go +++ b/internal/praefect/coordinator.go @@ -159,6 +159,7 @@ func (c *Coordinator) accessorStreamParameters(ctx context.Context, call grpcCal var transactionRPCs = map[string]featureflag.FeatureFlag{ "/gitaly.OperationService/UserCreateBranch": featureflag.ReferenceTransactionsOperationService, + "/gitaly.OperationService/UserDeleteBranch": featureflag.ReferenceTransactionsOperationService, "/gitaly.OperationService/UserUpdateBranch": featureflag.ReferenceTransactionsOperationService, "/gitaly.SSHService/SSHReceivePack": featureflag.ReferenceTransactionsSSHService, "/gitaly.SmartHTTPService/PostReceivePack": featureflag.ReferenceTransactionsSmartHTTPService, diff --git a/internal/service/operations/branches_test.go b/internal/service/operations/branches_test.go index cbc90472d..8720693dd 100644 --- a/internal/service/operations/branches_test.go +++ b/internal/service/operations/branches_test.go @@ -225,35 +225,44 @@ func TestFailedUserCreateBranchRequest(t *testing.T) { } func TestSuccessfulUserDeleteBranchRequest(t *testing.T) { - ctx, cancel := testhelper.Context() - defer cancel() + featureSets, err := testhelper.NewFeatureSets([]featureflag.FeatureFlag{featureflag.ReferenceTransactions}) + require.NoError(t, err) - testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t) - defer cleanupFn() + for _, featureSet := range featureSets { + t.Run(featureSet.String(), func(t *testing.T) { + ctx, cancel := testhelper.Context() + defer cancel() - serverSocketPath, stop := runOperationServiceServer(t) - defer stop() + ctx = featureSet.WithParent(ctx) - client, conn := newOperationClient(t, serverSocketPath) - defer conn.Close() + testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t) + defer cleanupFn() - branchNameInput := "to-be-deleted-soon-branch" + serverSocketPath, stop := runOperationServiceServer(t) + defer stop() - defer exec.Command("git", "-C", testRepoPath, "branch", "-d", branchNameInput).Run() + client, conn := newOperationClient(t, serverSocketPath) + defer conn.Close() - testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", branchNameInput) + branchNameInput := "to-be-deleted-soon-branch" - request := &gitalypb.UserDeleteBranchRequest{ - Repository: testRepo, - BranchName: []byte(branchNameInput), - User: testhelper.TestUser, - } + defer exec.Command("git", "-C", testRepoPath, "branch", "-d", branchNameInput).Run() - _, err := client.UserDeleteBranch(ctx, request) - require.NoError(t, err) + testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", branchNameInput) + + request := &gitalypb.UserDeleteBranchRequest{ + Repository: testRepo, + BranchName: []byte(branchNameInput), + User: testhelper.TestUser, + } + + _, err := client.UserDeleteBranch(ctx, request) + require.NoError(t, err) - branches := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch") - require.NotContains(t, string(branches), branchNameInput, "branch name still exists in branches list") + branches := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch") + require.NotContains(t, string(branches), branchNameInput, "branch name still exists in branches list") + }) + } } func TestSuccessfulGitHooksForUserDeleteBranchRequest(t *testing.T) { diff --git a/ruby/lib/gitaly_server/operations_service.rb b/ruby/lib/gitaly_server/operations_service.rb index 5d63ef1e1..f13cb369b 100644 --- a/ruby/lib/gitaly_server/operations_service.rb +++ b/ruby/lib/gitaly_server/operations_service.rb @@ -87,8 +87,9 @@ module GitalyServer def user_delete_branch(request, call) repo = Gitlab::Git::Repository.from_gitaly(request.repository, call) user = Gitlab::Git::User.from_gitaly(request.user) + transaction = Praefect::Transaction.from_metadata(call.metadata) - repo.rm_branch(request.branch_name, user: user) + repo.rm_branch(request.branch_name, user: user, transaction: transaction) Gitaly::UserDeleteBranchResponse.new rescue Gitlab::Git::PreReceiveError => e diff --git a/ruby/lib/gitlab/git/operation_service.rb b/ruby/lib/gitlab/git/operation_service.rb index abc489384..a3578c779 100644 --- a/ruby/lib/gitlab/git/operation_service.rb +++ b/ruby/lib/gitlab/git/operation_service.rb @@ -32,12 +32,12 @@ module Gitlab update_ref_in_hooks(ref, newrev, oldrev, transaction: transaction) end - def rm_branch(branch) + def rm_branch(branch, transaction: nil) ref = Gitlab::Git::BRANCH_REF_PREFIX + branch.name oldrev = branch.target newrev = Gitlab::Git::BLANK_SHA - update_ref_in_hooks(ref, newrev, oldrev) + update_ref_in_hooks(ref, newrev, oldrev, transaction: transaction) end def add_lightweight_tag(tag_name, tag_target) diff --git a/ruby/lib/gitlab/git/repository.rb b/ruby/lib/gitlab/git/repository.rb index d9d337a23..ac632b49b 100644 --- a/ruby/lib/gitlab/git/repository.rb +++ b/ruby/lib/gitlab/git/repository.rb @@ -255,12 +255,12 @@ module Gitlab OperationService.new(user, self).update_branch(branch_name, newrev, oldrev, push_options: push_options, transaction: transaction) end - def rm_branch(branch_name, user:) + def rm_branch(branch_name, user:, transaction: nil) branch = find_branch(branch_name) raise InvalidRef, "branch not found: #{branch_name}" unless branch - OperationService.new(user, self).rm_branch(branch) + OperationService.new(user, self).rm_branch(branch, transaction: transaction) end def rm_tag(tag_name, user:) |