1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
package operations
import (
"context"
"fmt"
"regexp"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/rubyserver"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (s *server) UserUpdateSubmodule(ctx context.Context, req *gitalypb.UserUpdateSubmoduleRequest) (*gitalypb.UserUpdateSubmoduleResponse, error) {
if err := validateUserUpdateSubmoduleRequest(req); err != nil {
return nil, status.Errorf(codes.InvalidArgument, "UserUpdateSubmodule: %v", err)
}
client, err := s.ruby.OperationServiceClient(ctx)
if err != nil {
return nil, err
}
clientCtx, err := rubyserver.SetHeaders(ctx, s.locator, req.GetRepository())
if err != nil {
return nil, err
}
return client.UserUpdateSubmodule(clientCtx, req)
}
func validateUserUpdateSubmoduleRequest(req *gitalypb.UserUpdateSubmoduleRequest) error {
if req.GetRepository() == nil {
return fmt.Errorf("empty Repository")
}
if req.GetUser() == nil {
return fmt.Errorf("empty User")
}
if req.GetCommitSha() == "" {
return fmt.Errorf("empty CommitSha")
}
if match, err := regexp.MatchString(`\A[0-9a-f]{40}\z`, req.GetCommitSha()); !match || err != nil {
return fmt.Errorf("invalid CommitSha")
}
if len(req.GetBranch()) == 0 {
return fmt.Errorf("empty Branch")
}
if len(req.GetSubmodule()) == 0 {
return fmt.Errorf("empty Submodule")
}
if len(req.GetCommitMessage()) == 0 {
return fmt.Errorf("empty CommitMessage")
}
return nil
}
|