diff options
author | Alejandro Rodríguez <alejorro70@gmail.com> | 2018-02-07 23:40:31 +0300 |
---|---|---|
committer | Alejandro Rodríguez <alejorro70@gmail.com> | 2018-02-07 23:40:31 +0300 |
commit | c7d32ff8d8648197f421a2e35d350b30f9cedf76 (patch) | |
tree | 97f2b034369dd21b5feb511cdd1fbce95188de05 | |
parent | 0bfc1a7e33e224362f79cbfcd24f6087ef06c551 (diff) |
Implement RepositoryService.IsSquashInProgress RPC
-rw-r--r-- | CHANGELOG.md | 7 | ||||
-rw-r--r-- | internal/service/repository/squash_in_progress.go | 36 | ||||
-rw-r--r-- | internal/service/repository/squash_in_progress_test.go | 99 | ||||
-rw-r--r-- | ruby/lib/gitaly_server/repository_service.rb | 10 |
4 files changed, 148 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 73cf9e8f4..2861ab477 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,17 @@ # Gitaly changelog +UNRELEASED + +- Implement RepositoryService.IsSquashInProgress RPC + https://gitlab.com/gitlab-org/gitaly/merge_requests/593 + v0.81.0 - Vendor gitlab_git at 7095c2bf4064911 https://gitlab.com/gitlab-org/gitaly/merge_requests/591 - Vendor gitlab_git at 9483cbab26ad239 https://gitlab.com/gitlab-org/gitaly/merge_requests/588 -- Added test to prevent wiki page duplication +- Added test to prevent wiki page duplication https://gitlab.com/gitlab-org/gitaly/merge_requests/539 - Fixed bug in wiki_find_page method https://gitlab.com/gitlab-org/gitaly/merge_requests/590 diff --git a/internal/service/repository/squash_in_progress.go b/internal/service/repository/squash_in_progress.go index 08ead64a4..3b0217237 100644 --- a/internal/service/repository/squash_in_progress.go +++ b/internal/service/repository/squash_in_progress.go @@ -1,11 +1,41 @@ package repository import ( + "fmt" + pb "gitlab.com/gitlab-org/gitaly-proto/go" - "gitlab.com/gitlab-org/gitaly/internal/helper" + "gitlab.com/gitlab-org/gitaly/internal/rubyserver" "golang.org/x/net/context" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" ) -func (*server) IsSquashInProgress(context.Context, *pb.IsSquashInProgressRequest) (*pb.IsSquashInProgressResponse, error) { - return nil, helper.Unimplemented +func (s *server) IsSquashInProgress(ctx context.Context, req *pb.IsSquashInProgressRequest) (*pb.IsSquashInProgressResponse, error) { + if err := validateIsSquashInProgressRequest(req); err != nil { + return nil, status.Errorf(codes.InvalidArgument, "IsSquashInProgress: %v", err) + } + + client, err := s.RepositoryServiceClient(ctx) + if err != nil { + return nil, err + } + + clientCtx, err := rubyserver.SetHeaders(ctx, req.GetRepository()) + if err != nil { + return nil, err + } + + return client.IsSquashInProgress(clientCtx, req) +} + +func validateIsSquashInProgressRequest(req *pb.IsSquashInProgressRequest) error { + if req.GetRepository() == nil { + return fmt.Errorf("empty Repository") + } + + if req.GetSquashId() == "" { + return fmt.Errorf("empty SquashId") + } + + return nil } diff --git a/internal/service/repository/squash_in_progress_test.go b/internal/service/repository/squash_in_progress_test.go new file mode 100644 index 000000000..248887173 --- /dev/null +++ b/internal/service/repository/squash_in_progress_test.go @@ -0,0 +1,99 @@ +package repository + +import ( + "path" + "testing" + + "gitlab.com/gitlab-org/gitaly/internal/testhelper" + + pb "gitlab.com/gitlab-org/gitaly-proto/go" + + "github.com/stretchr/testify/require" + "google.golang.org/grpc/codes" +) + +func TestSuccessfulIsSquashInProgressRequest(t *testing.T) { + server, serverSocketPath := runRepoServer(t) + defer server.Stop() + + client, conn := newRepositoryClient(t, serverSocketPath) + defer conn.Close() + + testRepo1, testRepo1Path, cleanupFn := testhelper.NewTestRepo(t) + defer cleanupFn() + + testhelper.MustRunCommand(t, nil, "git", "-C", testRepo1Path, "worktree", "add", "--detach", path.Join(testRepo1Path, "gitlab-worktree", "squash-1"), "master") + + testRepo2, _, cleanupFn := testhelper.NewTestRepo(t) + defer cleanupFn() + + testCases := []struct { + desc string + request *pb.IsSquashInProgressRequest + inProgress bool + }{ + { + desc: "Squash in progress", + request: &pb.IsSquashInProgressRequest{ + Repository: testRepo1, + SquashId: "1", + }, + inProgress: true, + }, + { + desc: "no Squash in progress", + request: &pb.IsSquashInProgressRequest{ + Repository: testRepo2, + SquashId: "2", + }, + inProgress: false, + }, + } + + for _, testCase := range testCases { + t.Run(testCase.desc, func(t *testing.T) { + ctx, cancel := testhelper.Context() + defer cancel() + + response, err := client.IsSquashInProgress(ctx, testCase.request) + require.NoError(t, err) + + require.Equal(t, testCase.inProgress, response.InProgress) + }) + } +} + +func TestFailedIsSquashInProgressRequestDueToValidations(t *testing.T) { + server, serverSocketPath := runRepoServer(t) + defer server.Stop() + + client, conn := newRepositoryClient(t, serverSocketPath) + defer conn.Close() + + testCases := []struct { + desc string + request *pb.IsSquashInProgressRequest + code codes.Code + }{ + { + desc: "empty repository", + request: &pb.IsSquashInProgressRequest{SquashId: "1"}, + code: codes.InvalidArgument, + }, + { + desc: "empty Squash id", + request: &pb.IsSquashInProgressRequest{Repository: &pb.Repository{}}, + code: codes.InvalidArgument, + }, + } + + for _, testCase := range testCases { + t.Run(testCase.desc, func(t *testing.T) { + ctx, cancel := testhelper.Context() + defer cancel() + + _, err := client.IsSquashInProgress(ctx, testCase.request) + testhelper.AssertGrpcError(t, err, testCase.code, "") + }) + } +} diff --git a/ruby/lib/gitaly_server/repository_service.rb b/ruby/lib/gitaly_server/repository_service.rb index 4e8915ab8..0e99d10b4 100644 --- a/ruby/lib/gitaly_server/repository_service.rb +++ b/ruby/lib/gitaly_server/repository_service.rb @@ -81,6 +81,16 @@ module GitalyServer end end + def is_squash_in_progress(request, call) # rubocop:disable Naming/PredicateName + bridge_exceptions do + repo = Gitlab::Git::Repository.from_gitaly(request.repository, call) + + result = repo.squash_in_progress?(request.squash_id) + + Gitaly::IsSquashInProgressResponse.new(in_progress: result) + end + end + def write_ref(request, call) bridge_exceptions do repo = Gitlab::Git::Repository.from_gitaly(request.repository, call) |