diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-02-03 11:40:20 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-02-03 19:08:42 +0300 |
commit | ce6df597d114687aae34dce089eae181790ec69e (patch) | |
tree | b9eee2aa0b8851d89a940a82fca6fb5a6add70e1 | |
parent | 467a8db96d95848b0ba1c8c8fc1139ee5361c11b (diff) |
hook: Pull out primary-only post-receive hook logic
This commit refactors the `PostReceiveHook()` implementation and pulls
out any logic which is only executed by the primary. This is in
preparation of properly stopping transactions if this logic fails.
-rw-r--r-- | internal/gitaly/hook/postreceive.go | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/internal/gitaly/hook/postreceive.go b/internal/gitaly/hook/postreceive.go index 2d7c1cf0c..2b4d1e74c 100644 --- a/internal/gitaly/hook/postreceive.go +++ b/internal/gitaly/hook/postreceive.go @@ -126,11 +126,17 @@ func (m *GitLabHookManager) PostReceiveHook(ctx context.Context, repo *gitalypb. return helper.ErrInternalf("reading stdin from request: %w", err) } - if !isPrimary(payload) { - return nil + if isPrimary(payload) { + if err := m.postReceiveHook(ctx, payload, repo, pushOptions, env, changes, stdout, stderr); err != nil { + return err + } } - if len(changes) == 0 { + return nil +} + +func (m *GitLabHookManager) postReceiveHook(ctx context.Context, payload git.HooksPayload, repo *gitalypb.Repository, pushOptions, env []string, stdin []byte, stdout, stderr io.Writer) error { + if len(stdin) == 0 { return helper.ErrInternalf("hook got no reference updates") } @@ -147,7 +153,7 @@ func (m *GitLabHookManager) PostReceiveHook(ctx context.Context, repo *gitalypb. ok, messages, err := m.gitlabAPI.PostReceive( ctx, repo.GetGlRepository(), payload.ReceiveHooksPayload.UserID, - string(changes), + string(stdin), pushOptions..., ) if err != nil { @@ -176,7 +182,7 @@ func (m *GitLabHookManager) PostReceiveHook(ctx context.Context, repo *gitalypb. ctx, nil, customEnv, - bytes.NewReader(changes), + bytes.NewReader(stdin), stdout, stderr, ); err != nil { |