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:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2020-09-08 09:37:05 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2020-09-08 09:37:05 +0300
commita7aa80ed0d8cdc3a4abe94b6d1e7984ef8a26281 (patch)
tree0b00e14b4ba3a3e6876350c57732afdad58c881d
parent30c7a0c38a18ab269b5e81bb13bddd5018ad453b (diff)
hook: Move postreceive hook into `internal/hook`
Move business logic of the postreceive hook into the new `internal/hook` manager. This commit is part of the refactoring splitting business logic from the hook service into the hook manager in order to allow execution of hooks from Gitaly's own context.
-rw-r--r--cmd/gitaly-hooks/hooks_test.go2
-rw-r--r--internal/gitaly/hook/manager.go16
-rw-r--r--internal/gitaly/hook/postreceive.go171
-rw-r--r--internal/gitaly/hook/postreceive_test.go50
-rw-r--r--internal/gitaly/hook/transactions.go21
-rw-r--r--internal/gitaly/service/hook/post_receive.go143
-rw-r--r--internal/gitaly/service/hook/post_receive_test.go41
-rw-r--r--internal/gitaly/service/hook/testhelper_test.go2
-rw-r--r--internal/gitaly/service/operations/branches_test.go2
-rw-r--r--internal/gitaly/service/operations/testhelper_test.go2
-rw-r--r--internal/gitaly/service/register.go2
-rw-r--r--internal/gitaly/service/smarthttp/receive_pack_test.go6
12 files changed, 268 insertions, 190 deletions
diff --git a/cmd/gitaly-hooks/hooks_test.go b/cmd/gitaly-hooks/hooks_test.go
index d49efc6a6..8d26e053e 100644
--- a/cmd/gitaly-hooks/hooks_test.go
+++ b/cmd/gitaly-hooks/hooks_test.go
@@ -712,7 +712,7 @@ func runHookServiceServer(t *testing.T, token string) (string, func()) {
func runHookServiceServerWithAPI(t *testing.T, token string, gitlabAPI gitalyhook.GitlabAPI) (string, func()) {
server := testhelper.NewServerWithAuth(t, nil, nil, token)
- gitalypb.RegisterHookServiceServer(server.GrpcServer(), hook.NewServer(gitalyhook.NewManager(), gitlabAPI, config.Config.Hooks))
+ gitalypb.RegisterHookServiceServer(server.GrpcServer(), hook.NewServer(gitalyhook.NewManager(gitlabAPI, config.Config.Hooks), gitlabAPI, config.Config.Hooks))
reflection.Register(server.GrpcServer())
require.NoError(t, server.Start())
diff --git a/internal/gitaly/hook/manager.go b/internal/gitaly/hook/manager.go
index 64faa67d5..d9711eb0f 100644
--- a/internal/gitaly/hook/manager.go
+++ b/internal/gitaly/hook/manager.go
@@ -1,9 +1,19 @@
package hook
+import (
+ "gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
+)
+
// Manager is a hook manager containing Git hook business logic.
-type Manager struct{}
+type Manager struct {
+ gitlabAPI GitlabAPI
+ hooksConfig config.Hooks
+}
// NewManager returns a new hook manager
-func NewManager() *Manager {
- return &Manager{}
+func NewManager(gitlabAPI GitlabAPI, hooksConfig config.Hooks) *Manager {
+ return &Manager{
+ gitlabAPI: gitlabAPI,
+ hooksConfig: hooksConfig,
+ }
}
diff --git a/internal/gitaly/hook/postreceive.go b/internal/gitaly/hook/postreceive.go
new file mode 100644
index 000000000..8834756a7
--- /dev/null
+++ b/internal/gitaly/hook/postreceive.go
@@ -0,0 +1,171 @@
+package hook
+
+import (
+ "bytes"
+ "context"
+ "errors"
+ "fmt"
+ "io"
+ "io/ioutil"
+ "math"
+ "strings"
+
+ "gitlab.com/gitlab-org/gitaly/internal/helper"
+ "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
+)
+
+const (
+ // A standard terminal window is (at least) 80 characters wide.
+ terminalWidth = 80
+ gitRemoteMessagePrefixLength = len("remote: ")
+ terminalMessagePadding = 2
+
+ // Git prefixes remote messages with "remote: ", so this width is subtracted
+ // from the width available to us.
+ maxMessageWidth = terminalWidth - gitRemoteMessagePrefixLength
+
+ // Our centered text shouldn't start or end right at the edge of the window,
+ // so we add some horizontal padding: 2 chars on either side.
+ maxMessageTextWidth = maxMessageWidth - 2*terminalMessagePadding
+)
+
+func getEnvVar(key string, vars []string) string {
+ for _, varPair := range vars {
+ kv := strings.SplitN(varPair, "=", 2)
+ if kv[0] == key {
+ return kv[1]
+ }
+ }
+
+ return ""
+}
+
+func printMessages(messages []PostReceiveMessage, w io.Writer) error {
+ for _, message := range messages {
+ if _, err := w.Write([]byte("\n")); err != nil {
+ return err
+ }
+
+ switch message.Type {
+ case "basic":
+ if _, err := w.Write([]byte(message.Message)); err != nil {
+ return err
+ }
+ case "alert":
+ if err := printAlert(message, w); err != nil {
+ return err
+ }
+ default:
+ return fmt.Errorf("invalid message type: %v", message.Type)
+ }
+
+ if _, err := w.Write([]byte("\n\n")); err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
+func centerLine(b []byte) []byte {
+ b = bytes.TrimSpace(b)
+ linePadding := int(math.Max((float64(maxMessageWidth)-float64(len(b)))/2, 0))
+ return append(bytes.Repeat([]byte(" "), linePadding), b...)
+}
+
+func printAlert(m PostReceiveMessage, w io.Writer) error {
+ if _, err := w.Write(bytes.Repeat([]byte("="), maxMessageWidth)); err != nil {
+ return err
+ }
+
+ if _, err := w.Write([]byte("\n\n")); err != nil {
+ return err
+ }
+
+ words := strings.Fields(m.Message)
+
+ line := bytes.NewBufferString("")
+
+ for _, word := range words {
+ if line.Len()+1+len(word) > maxMessageTextWidth {
+ if _, err := w.Write(append(centerLine(line.Bytes()), '\n')); err != nil {
+ return err
+ }
+ line.Reset()
+ }
+
+ if _, err := line.WriteString(word + " "); err != nil {
+ return err
+ }
+ }
+
+ if _, err := w.Write(centerLine(line.Bytes())); err != nil {
+ return err
+ }
+
+ if _, err := w.Write([]byte("\n\n")); err != nil {
+ return err
+ }
+
+ if _, err := w.Write(bytes.Repeat([]byte("="), maxMessageWidth)); err != nil {
+ return err
+ }
+
+ return nil
+}
+
+func (m *Manager) PostReceiveHook(ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error {
+ changes, err := ioutil.ReadAll(stdin)
+ if err != nil {
+ return helper.ErrInternalf("reading stdin from request: %w", err)
+ }
+
+ primary, err := isPrimary(env)
+ if err != nil {
+ return helper.ErrInternalf("could not check role: %w", err)
+ }
+
+ if !primary {
+ return nil
+ }
+
+ env = append(env, pushOptions...)
+
+ glID, glRepo := getEnvVar("GL_ID", env), getEnvVar("GL_REPOSITORY", env)
+
+ ok, messages, err := m.gitlabAPI.PostReceive(glRepo, glID, string(changes), pushOptions...)
+ if err != nil {
+ return fmt.Errorf("GitLab: %v", err)
+ }
+
+ if err := printMessages(messages, stdout); err != nil {
+ return fmt.Errorf("error writing messages to stream: %v", err)
+ }
+
+ if !ok {
+ return errors.New("")
+ }
+
+ // custom hooks execution
+ repoPath, err := helper.GetRepoPath(repo)
+ if err != nil {
+ return err
+ }
+ executor, err := m.NewCustomHooksExecutor(repoPath, m.hooksConfig.CustomHooksDir, "post-receive")
+ if err != nil {
+ return helper.ErrInternalf("creating custom hooks executor: %v", err)
+ }
+
+ if err = executor(
+ ctx,
+ nil,
+ env,
+ bytes.NewReader(changes),
+ stdout,
+ stderr,
+ ); err != nil {
+ return err
+ }
+
+ return nil
+}
diff --git a/internal/gitaly/hook/postreceive_test.go b/internal/gitaly/hook/postreceive_test.go
new file mode 100644
index 000000000..7ac260cab
--- /dev/null
+++ b/internal/gitaly/hook/postreceive_test.go
@@ -0,0 +1,50 @@
+package hook
+
+import (
+ "bytes"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+func TestPrintAlert(t *testing.T) {
+ testCases := []struct {
+ message string
+ expected string
+ }{
+ {
+ message: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur nec mi lectus. Fusce eu ligula in odio hendrerit posuere. Ut semper neque vitae maximus accumsan. In malesuada justo nec leo congue egestas. Vivamus interdum nec libero ac convallis. Praesent euismod et nunc vitae vulputate. Mauris tincidunt ligula urna, bibendum vestibulum sapien luctus eu. Donec sed justo in erat dictum semper. Ut porttitor augue in felis gravida scelerisque. Morbi dolor justo, accumsan et nulla vitae, luctus consectetur est. Donec aliquet erat pellentesque suscipit elementum. Cras posuere eros ipsum, a tincidunt tortor laoreet quis. Mauris varius nulla vitae placerat imperdiet. Vivamus ut ligula odio. Cras nec euismod ligula.",
+ expected: `========================================================================
+
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur
+ nec mi lectus. Fusce eu ligula in odio hendrerit posuere. Ut semper
+ neque vitae maximus accumsan. In malesuada justo nec leo congue
+ egestas. Vivamus interdum nec libero ac convallis. Praesent euismod
+ et nunc vitae vulputate. Mauris tincidunt ligula urna, bibendum
+ vestibulum sapien luctus eu. Donec sed justo in erat dictum semper.
+ Ut porttitor augue in felis gravida scelerisque. Morbi dolor justo,
+ accumsan et nulla vitae, luctus consectetur est. Donec aliquet erat
+ pellentesque suscipit elementum. Cras posuere eros ipsum, a
+ tincidunt tortor laoreet quis. Mauris varius nulla vitae placerat
+ imperdiet. Vivamus ut ligula odio. Cras nec euismod ligula.
+
+========================================================================`,
+ },
+ {
+ message: "Lorem ipsum dolor sit amet, consectetur",
+ expected: `========================================================================
+
+ Lorem ipsum dolor sit amet, consectetur
+
+========================================================================`,
+ },
+ }
+
+ for _, tc := range testCases {
+ var result bytes.Buffer
+
+ require.NoError(t, printAlert(PostReceiveMessage{Message: tc.message}, &result))
+ assert.Equal(t, tc.expected, result.String())
+ }
+}
diff --git a/internal/gitaly/hook/transactions.go b/internal/gitaly/hook/transactions.go
new file mode 100644
index 000000000..eae270528
--- /dev/null
+++ b/internal/gitaly/hook/transactions.go
@@ -0,0 +1,21 @@
+package hook
+
+import (
+ "errors"
+
+ "gitlab.com/gitlab-org/gitaly/internal/praefect/metadata"
+)
+
+func isPrimary(env []string) (bool, error) {
+ tx, err := metadata.TransactionFromEnv(env)
+ if err != nil {
+ if errors.Is(err, metadata.ErrTransactionNotFound) {
+ // If there is no transaction, then we only ever write
+ // to the primary. Thus, we return true.
+ return true, nil
+ }
+ return false, err
+ }
+
+ return tx.Primary, nil
+}
diff --git a/internal/gitaly/service/hook/post_receive.go b/internal/gitaly/service/hook/post_receive.go
index b79225b17..836c57f08 100644
--- a/internal/gitaly/service/hook/post_receive.go
+++ b/internal/gitaly/service/hook/post_receive.go
@@ -1,17 +1,13 @@
package hook
import (
- "bytes"
"errors"
"fmt"
"io"
"io/ioutil"
- "math"
"os/exec"
- "strings"
"gitlab.com/gitlab-org/gitaly/internal/git/hooks"
- gitalyhook "gitlab.com/gitlab-org/gitaly/internal/gitaly/hook"
"gitlab.com/gitlab-org/gitaly/internal/helper"
"gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
@@ -33,95 +29,6 @@ func postReceiveHookResponse(stream gitalypb.HookService_PostReceiveHookServer,
return nil
}
-const (
- // A standard terminal window is (at least) 80 characters wide.
- terminalWidth = 80
- gitRemoteMessagePrefixLength = len("remote: ")
- terminalMessagePadding = 2
-
- // Git prefixes remote messages with "remote: ", so this width is subtracted
- // from the width available to us.
- maxMessageWidth = terminalWidth - gitRemoteMessagePrefixLength
-
- // Our centered text shouldn't start or end right at the edge of the window,
- // so we add some horizontal padding: 2 chars on either side.
- maxMessageTextWidth = maxMessageWidth - 2*terminalMessagePadding
-)
-
-func printMessages(messages []gitalyhook.PostReceiveMessage, w io.Writer) error {
- for _, message := range messages {
- if _, err := w.Write([]byte("\n")); err != nil {
- return err
- }
-
- switch message.Type {
- case "basic":
- if _, err := w.Write([]byte(message.Message)); err != nil {
- return err
- }
- case "alert":
- if err := printAlert(message, w); err != nil {
- return err
- }
- default:
- return fmt.Errorf("invalid message type: %v", message.Type)
- }
-
- if _, err := w.Write([]byte("\n\n")); err != nil {
- return err
- }
- }
-
- return nil
-}
-
-func centerLine(b []byte) []byte {
- b = bytes.TrimSpace(b)
- linePadding := int(math.Max((float64(maxMessageWidth)-float64(len(b)))/2, 0))
- return append(bytes.Repeat([]byte(" "), linePadding), b...)
-}
-
-func printAlert(m gitalyhook.PostReceiveMessage, w io.Writer) error {
- if _, err := w.Write(bytes.Repeat([]byte("="), maxMessageWidth)); err != nil {
- return err
- }
-
- if _, err := w.Write([]byte("\n\n")); err != nil {
- return err
- }
-
- words := strings.Fields(m.Message)
-
- line := bytes.NewBufferString("")
-
- for _, word := range words {
- if line.Len()+1+len(word) > maxMessageTextWidth {
- if _, err := w.Write(append(centerLine(line.Bytes()), '\n')); err != nil {
- return err
- }
- line.Reset()
- }
-
- if _, err := line.WriteString(word + " "); err != nil {
- return err
- }
- }
-
- if _, err := w.Write(centerLine(line.Bytes())); err != nil {
- return err
- }
-
- if _, err := w.Write([]byte("\n\n")); err != nil {
- return err
- }
-
- if _, err := w.Write(bytes.Repeat([]byte("="), maxMessageWidth)); err != nil {
- return err
- }
-
- return nil
-}
-
func (s *server) PostReceiveHook(stream gitalypb.HookService_PostReceiveHookServer) error {
firstRequest, err := stream.Recv()
if err != nil {
@@ -141,8 +48,6 @@ func (s *server) PostReceiveHook(stream gitalypb.HookService_PostReceiveHookServ
return helper.ErrInternal(err)
}
- hookEnv = append(hookEnv, hooks.GitPushOptions(firstRequest.GetGitPushOptions())...)
-
stdin := streamio.NewReader(func() ([]byte, error) {
req, err := stream.Recv()
return req.GetStdin(), err
@@ -150,50 +55,12 @@ func (s *server) PostReceiveHook(stream gitalypb.HookService_PostReceiveHookServ
stdout := streamio.NewWriter(func(p []byte) error { return stream.Send(&gitalypb.PostReceiveHookResponse{Stdout: p}) })
stderr := streamio.NewWriter(func(p []byte) error { return stream.Send(&gitalypb.PostReceiveHookResponse{Stderr: p}) })
- changes, err := ioutil.ReadAll(stdin)
- if err != nil {
- return helper.ErrInternalf("reading stdin from request: %w", err)
- }
-
- primary, err := isPrimary(hookEnv)
- if err != nil {
- return helper.ErrInternalf("could not check role: %w", err)
- }
-
- if !primary {
- return postReceiveHookResponse(stream, 0, "")
- }
-
- glID, glRepo := getEnvVar("GL_ID", hookEnv), getEnvVar("GL_REPOSITORY", hookEnv)
-
- ok, messages, err := s.gitlabAPI.PostReceive(glRepo, glID, string(changes), firstRequest.GetGitPushOptions()...)
- if err != nil {
- return postReceiveHookResponse(stream, 1, fmt.Sprintf("GitLab: %v", err))
- }
-
- if err := printMessages(messages, stdout); err != nil {
- return helper.ErrInternalf("error writing messages to stream: %v", err)
- }
-
- if !ok {
- return postReceiveHookResponse(stream, 1, "")
- }
-
- // custom hooks execution
- repoPath, err := helper.GetRepoPath(firstRequest.GetRepository())
- if err != nil {
- return err
- }
- executor, err := s.manager.NewCustomHooksExecutor(repoPath, s.hooksConfig.CustomHooksDir, "post-receive")
- if err != nil {
- return helper.ErrInternalf("creating custom hooks executor: %v", err)
- }
-
- if err = executor(
+ if err := s.manager.PostReceiveHook(
stream.Context(),
- nil,
+ firstRequest.Repository,
+ hooks.GitPushOptions(firstRequest.GetGitPushOptions()),
hookEnv,
- bytes.NewReader(changes),
+ stdin,
stdout,
stderr,
); err != nil {
@@ -202,7 +69,7 @@ func (s *server) PostReceiveHook(stream gitalypb.HookService_PostReceiveHookServ
return postReceiveHookResponse(stream, int32(exitError.ExitCode()), "")
}
- return helper.ErrInternalf("executing custom hooks: %v", err)
+ return postReceiveHookResponse(stream, 1, fmt.Sprintf("%s", err))
}
return postReceiveHookResponse(stream, 0, "")
diff --git a/internal/gitaly/service/hook/post_receive_test.go b/internal/gitaly/service/hook/post_receive_test.go
index ce74b2926..cf86e9a22 100644
--- a/internal/gitaly/service/hook/post_receive_test.go
+++ b/internal/gitaly/service/hook/post_receive_test.go
@@ -389,44 +389,3 @@ To create a merge request for okay, visit:
}
}
}
-
-func TestPrintAlert(t *testing.T) {
- testCases := []struct {
- message string
- expected string
- }{
- {
- message: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur nec mi lectus. Fusce eu ligula in odio hendrerit posuere. Ut semper neque vitae maximus accumsan. In malesuada justo nec leo congue egestas. Vivamus interdum nec libero ac convallis. Praesent euismod et nunc vitae vulputate. Mauris tincidunt ligula urna, bibendum vestibulum sapien luctus eu. Donec sed justo in erat dictum semper. Ut porttitor augue in felis gravida scelerisque. Morbi dolor justo, accumsan et nulla vitae, luctus consectetur est. Donec aliquet erat pellentesque suscipit elementum. Cras posuere eros ipsum, a tincidunt tortor laoreet quis. Mauris varius nulla vitae placerat imperdiet. Vivamus ut ligula odio. Cras nec euismod ligula.",
- expected: `========================================================================
-
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur
- nec mi lectus. Fusce eu ligula in odio hendrerit posuere. Ut semper
- neque vitae maximus accumsan. In malesuada justo nec leo congue
- egestas. Vivamus interdum nec libero ac convallis. Praesent euismod
- et nunc vitae vulputate. Mauris tincidunt ligula urna, bibendum
- vestibulum sapien luctus eu. Donec sed justo in erat dictum semper.
- Ut porttitor augue in felis gravida scelerisque. Morbi dolor justo,
- accumsan et nulla vitae, luctus consectetur est. Donec aliquet erat
- pellentesque suscipit elementum. Cras posuere eros ipsum, a
- tincidunt tortor laoreet quis. Mauris varius nulla vitae placerat
- imperdiet. Vivamus ut ligula odio. Cras nec euismod ligula.
-
-========================================================================`,
- },
- {
- message: "Lorem ipsum dolor sit amet, consectetur",
- expected: `========================================================================
-
- Lorem ipsum dolor sit amet, consectetur
-
-========================================================================`,
- },
- }
-
- for _, tc := range testCases {
- var result bytes.Buffer
-
- require.NoError(t, printAlert(gitalyhook.PostReceiveMessage{Message: tc.message}, &result))
- assert.Equal(t, tc.expected, result.String())
- }
-}
diff --git a/internal/gitaly/service/hook/testhelper_test.go b/internal/gitaly/service/hook/testhelper_test.go
index bbe9b7fab..0a9a86b06 100644
--- a/internal/gitaly/service/hook/testhelper_test.go
+++ b/internal/gitaly/service/hook/testhelper_test.go
@@ -39,7 +39,7 @@ func runHooksServer(t *testing.T, hooksCfg config.Hooks) (string, func()) {
func runHooksServerWithAPI(t *testing.T, gitlabAPI gitalyhook.GitlabAPI, hooksCfg config.Hooks) (string, func()) {
srv := testhelper.NewServer(t, nil, nil)
- gitalypb.RegisterHookServiceServer(srv.GrpcServer(), NewServer(gitalyhook.NewManager(), gitlabAPI, hooksCfg))
+ gitalypb.RegisterHookServiceServer(srv.GrpcServer(), NewServer(gitalyhook.NewManager(gitlabAPI, hooksCfg), gitlabAPI, hooksCfg))
reflection.Register(srv.GrpcServer())
require.NoError(t, srv.Start())
diff --git a/internal/gitaly/service/operations/branches_test.go b/internal/gitaly/service/operations/branches_test.go
index 874740cb9..c82aa774e 100644
--- a/internal/gitaly/service/operations/branches_test.go
+++ b/internal/gitaly/service/operations/branches_test.go
@@ -122,7 +122,7 @@ func TestUserCreateBranchWithTransaction(t *testing.T) {
transactionServer := &testTransactionServer{}
srv := testhelper.NewServerWithAuth(t, nil, nil, config.Config.Auth.Token)
gitalypb.RegisterOperationServiceServer(srv.GrpcServer(), &server{ruby: RubyServer})
- gitalypb.RegisterHookServiceServer(srv.GrpcServer(), hook.NewServer(gitalyhook.NewManager(), gitalyhook.GitlabAPIStub, config.Config.Hooks))
+ gitalypb.RegisterHookServiceServer(srv.GrpcServer(), hook.NewServer(gitalyhook.NewManager(gitalyhook.GitlabAPIStub, config.Config.Hooks), gitalyhook.GitlabAPIStub, config.Config.Hooks))
gitalypb.RegisterRefTransactionServer(srv.GrpcServer(), transactionServer)
require.NoError(t, srv.Start())
diff --git a/internal/gitaly/service/operations/testhelper_test.go b/internal/gitaly/service/operations/testhelper_test.go
index 96dba6c95..b12d865a3 100644
--- a/internal/gitaly/service/operations/testhelper_test.go
+++ b/internal/gitaly/service/operations/testhelper_test.go
@@ -89,7 +89,7 @@ func runOperationServiceServerWithRubyServer(t *testing.T, ruby *rubyserver.Serv
locator := config.NewLocator(config.Config)
gitalypb.RegisterOperationServiceServer(srv.GrpcServer(), &server{ruby: ruby})
- gitalypb.RegisterHookServiceServer(srv.GrpcServer(), hook.NewServer(gitalyhook.NewManager(), gitalyhook.GitlabAPIStub, config.Config.Hooks))
+ gitalypb.RegisterHookServiceServer(srv.GrpcServer(), hook.NewServer(gitalyhook.NewManager(gitalyhook.GitlabAPIStub, config.Config.Hooks), gitalyhook.GitlabAPIStub, config.Config.Hooks))
gitalypb.RegisterRepositoryServiceServer(srv.GrpcServer(), repository.NewServer(ruby, locator, internalSocket))
gitalypb.RegisterRefServiceServer(srv.GrpcServer(), ref.NewServer())
gitalypb.RegisterCommitServiceServer(srv.GrpcServer(), commit.NewServer(locator))
diff --git a/internal/gitaly/service/register.go b/internal/gitaly/service/register.go
index f30731475..c12dc0d82 100644
--- a/internal/gitaly/service/register.go
+++ b/internal/gitaly/service/register.go
@@ -97,7 +97,7 @@ func RegisterAll(grpcServer *grpc.Server, cfg config.Cfg, rubyServer *rubyserver
gitalypb.RegisterServerServiceServer(grpcServer, server.NewServer(cfg.Storages))
gitalypb.RegisterObjectPoolServiceServer(grpcServer, objectpool.NewServer(locator))
gitalypb.RegisterHookServiceServer(grpcServer, hook.NewServer(
- gitalyhook.NewManager(),
+ gitalyhook.NewManager(gitlabAPI, cfg.Hooks),
gitlabAPI,
cfg.Hooks,
hook.WithVotingDelayMetric(votingDelayMetric),
diff --git a/internal/gitaly/service/smarthttp/receive_pack_test.go b/internal/gitaly/service/smarthttp/receive_pack_test.go
index 67c9a2e7e..4a7115b85 100644
--- a/internal/gitaly/service/smarthttp/receive_pack_test.go
+++ b/internal/gitaly/service/smarthttp/receive_pack_test.go
@@ -462,7 +462,7 @@ func runSmartHTTPHookServiceServer(t *testing.T) (*grpc.Server, string) {
}
gitalypb.RegisterSmartHTTPServiceServer(server, NewServer())
- gitalypb.RegisterHookServiceServer(server, hook.NewServer(gitalyhook.NewManager(), gitalyhook.GitlabAPIStub, config.Config.Hooks))
+ gitalypb.RegisterHookServiceServer(server, hook.NewServer(gitalyhook.NewManager(gitalyhook.GitlabAPIStub, config.Config.Hooks), gitalyhook.GitlabAPIStub, config.Config.Hooks))
reflection.Register(server)
go server.Serve(listener)
@@ -529,7 +529,7 @@ func TestPostReceiveWithTransactionsViaPraefect(t *testing.T) {
gitalyServer := testhelper.NewServerWithAuth(t, nil, nil, config.Config.Auth.Token)
gitalypb.RegisterSmartHTTPServiceServer(gitalyServer.GrpcServer(), NewServer())
- gitalypb.RegisterHookServiceServer(gitalyServer.GrpcServer(), hook.NewServer(gitalyhook.NewManager(), gitalyhook.GitlabAPIStub, config.Config.Hooks))
+ gitalypb.RegisterHookServiceServer(gitalyServer.GrpcServer(), hook.NewServer(gitalyhook.NewManager(gitalyhook.GitlabAPIStub, config.Config.Hooks), gitalyhook.GitlabAPIStub, config.Config.Hooks))
reflection.Register(gitalyServer.GrpcServer())
require.NoError(t, gitalyServer.Start())
defer gitalyServer.Stop()
@@ -578,7 +578,7 @@ func TestPostReceiveWithReferenceTransactionHook(t *testing.T) {
gitalyServer := testhelper.NewTestGrpcServer(t, nil, nil)
gitalypb.RegisterSmartHTTPServiceServer(gitalyServer, NewServer())
- gitalypb.RegisterHookServiceServer(gitalyServer, hook.NewServer(gitalyhook.NewManager(), gitalyhook.GitlabAPIStub, config.Config.Hooks))
+ gitalypb.RegisterHookServiceServer(gitalyServer, hook.NewServer(gitalyhook.NewManager(gitalyhook.GitlabAPIStub, config.Config.Hooks), gitalyhook.GitlabAPIStub, config.Config.Hooks))
gitalypb.RegisterRefTransactionServer(gitalyServer, refTransactionServer)
reflection.Register(gitalyServer)