diff options
author | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2020-09-17 19:26:49 +0300 |
---|---|---|
committer | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2020-09-30 11:11:44 +0300 |
commit | 538e5d075acdbb46307d293251ae68fe0dd41b42 (patch) | |
tree | 5cb328c640ca02d7046c8e35e972dd040b7ab898 | |
parent | 892ab6e3d7689a74dfc7849ec62f55122a59335b (diff) |
hooks: Custom PostReceive hooks get Git options
Before this change the Ruby hooks expose Git options to the custom
hooks, while to Go hooks didn't. This change updates the PostReceiveHook
handler to expose the GIT_OPTION* env variables to the custom hooks.
-rw-r--r-- | internal/gitaly/hook/postreceive.go | 5 | ||||
-rw-r--r-- | internal/gitaly/service/hook/post_receive.go | 12 |
2 files changed, 8 insertions, 9 deletions
diff --git a/internal/gitaly/hook/postreceive.go b/internal/gitaly/hook/postreceive.go index fcd6def80..2c77f612c 100644 --- a/internal/gitaly/hook/postreceive.go +++ b/internal/gitaly/hook/postreceive.go @@ -10,6 +10,7 @@ import ( "math" "strings" + "gitlab.com/gitlab-org/gitaly/internal/git/hooks" "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" ) @@ -129,8 +130,6 @@ func (m *GitLabHookManager) PostReceiveHook(ctx context.Context, repo *gitalypb. return nil } - env = append(env, pushOptions...) - glID, glRepo := getEnvVar("GL_ID", env), getEnvVar("GL_REPOSITORY", env) ok, messages, err := m.gitlabAPI.PostReceive(ctx, glRepo, glID, string(changes), pushOptions...) @@ -154,7 +153,7 @@ func (m *GitLabHookManager) PostReceiveHook(ctx context.Context, repo *gitalypb. if err = executor( ctx, nil, - env, + append(env, hooks.GitPushOptions(pushOptions)...), bytes.NewReader(changes), stdout, stderr, diff --git a/internal/gitaly/service/hook/post_receive.go b/internal/gitaly/service/hook/post_receive.go index e12c91fa5..84fb27058 100644 --- a/internal/gitaly/service/hook/post_receive.go +++ b/internal/gitaly/service/hook/post_receive.go @@ -43,11 +43,6 @@ func (s *server) PostReceiveHook(stream gitalypb.HookService_PostReceiveHookServ return postReceiveHookRuby(firstRequest, stream) } - hookEnv, err := hookRequestEnv(firstRequest) - if err != nil { - return helper.ErrInternal(err) - } - stdin := streamio.NewReader(func() ([]byte, error) { req, err := stream.Recv() return req.GetStdin(), err @@ -55,11 +50,16 @@ 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}) }) + env, err := hookRequestEnv(firstRequest) + if err != nil { + return err + } + if err := s.manager.PostReceiveHook( stream.Context(), firstRequest.Repository, firstRequest.GetGitPushOptions(), - hookEnv, + env, stdin, stdout, stderr, |