Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeger-Jan van de Weg <zegerjan@gitlab.com>2018-02-08 10:32:52 +0300
committerZeger-Jan van de Weg <zegerjan@gitlab.com>2018-02-08 10:32:52 +0300
commitc5d9d30b0ce076ac79eb17e16b249d9a2ebe1298 (patch)
treed9ba026b130b91363eef347bb560efb704e7fcc7
parent23b19ee218bb33771e559da1c69060f9befef033 (diff)
parent7d5e1adea73a5d20c320216581abdd49041893e7 (diff)
Merge branch '1019-server-implementation-repositoryservice-issquashinprogress' into 'master'
Resolve "Server Implementation RepositoryService.IsSquashInProgress" Closes #1019 See merge request gitlab-org/gitaly!593
-rw-r--r--CHANGELOG.md2
-rw-r--r--internal/service/repository/squash_in_progress.go36
-rw-r--r--internal/service/repository/squash_in_progress_test.go99
-rw-r--r--ruby/lib/gitaly_server/repository_service.rb10
4 files changed, 144 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bbfcca84c..592b6ed03 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@
UNRELEASED
+- Implement RepositoryService.IsSquashInProgress RPC
+ https://gitlab.com/gitlab-org/gitaly/merge_requests/593
- Added test to prevent wiki page duplication
https://gitlab.com/gitlab-org/gitaly/merge_requests/539
- Fixed bug in wiki_find_page method
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)