From 5b0f3acdf008d97706780bf73dc03ad8b4aff2df Mon Sep 17 00:00:00 2001
From: Nick Thomas <nick@gitlab.com>
Date: Wed, 20 Sep 2017 16:55:24 +0100
Subject: [PATCH] Pass GL_USERNAME from GitLab to Gitaly

---
 gitaly_test.go                | 6 ++++--
 internal/git/receive-pack.go  | 2 +-
 internal/gitaly/smarthttp.go  | 3 ++-
 internal/testhelper/gitaly.go | 1 +
 main_test.go                  | 5 +++--
 5 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/gitaly_test.go b/gitaly_test.go
index 323c705c4cac2..13ee1711c2f91 100644
--- a/gitaly_test.go
+++ b/gitaly_test.go
@@ -31,8 +31,9 @@ func TestFailedCloneNoGitaly(t *testing.T) {
 	require.NoError(t, os.RemoveAll(scratchDir))
 
 	authBody := &api.Response{
-		GL_ID:    "user-123",
-		RepoPath: repoPath(t),
+		GL_ID:       "user-123",
+		GL_USERNAME: "username",
+		RepoPath:    repoPath(t),
 		// This will create a failure to connect to Gitaly
 		GitalyServer: gitaly.Server{Address: "unix:/nonexistent"},
 	}
@@ -132,6 +133,7 @@ func TestPostReceivePackProxiedToGitalySuccessfully(t *testing.T) {
 		apiResponse.Repository.StorageName,
 		apiResponse.Repository.RelativePath,
 		apiResponse.GL_ID,
+		apiResponse.GL_USERNAME,
 		string(testhelper.GitalyReceivePackResponseMock),
 	}, "\000")
 
diff --git a/internal/git/receive-pack.go b/internal/git/receive-pack.go
index 41957f427b5a5..aa84c76de4bff 100644
--- a/internal/git/receive-pack.go
+++ b/internal/git/receive-pack.go
@@ -52,7 +52,7 @@ func handleReceivePackWithGitaly(ctx context.Context, a *api.Response, clientReq
 		return fmt.Errorf("smarthttp.ReceivePack: %v", err)
 	}
 
-	if err := smarthttp.ReceivePack(ctx, &a.Repository, a.GL_ID, a.GL_REPOSITORY, clientRequest, clientResponse); err != nil {
+	if err := smarthttp.ReceivePack(ctx, &a.Repository, a.GL_ID, a.GL_USERNAME, a.GL_REPOSITORY, clientRequest, clientResponse); err != nil {
 		return fmt.Errorf("smarthttp.ReceivePack: %v", err)
 	}
 
diff --git a/internal/gitaly/smarthttp.go b/internal/gitaly/smarthttp.go
index dcd063fd43461..d549b2f27812f 100644
--- a/internal/gitaly/smarthttp.go
+++ b/internal/gitaly/smarthttp.go
@@ -39,7 +39,7 @@ func infoRefsReader(stream infoRefsClient) io.Reader {
 	})
 }
 
-func (client *SmartHTTPClient) ReceivePack(ctx context.Context, repo *pb.Repository, glId string, glRepository string, clientRequest io.Reader, clientResponse io.Writer) error {
+func (client *SmartHTTPClient) ReceivePack(ctx context.Context, repo *pb.Repository, glId string, glUsername string, glRepository string, clientRequest io.Reader, clientResponse io.Writer) error {
 	stream, err := client.PostReceivePack(ctx)
 	if err != nil {
 		return err
@@ -48,6 +48,7 @@ func (client *SmartHTTPClient) ReceivePack(ctx context.Context, repo *pb.Reposit
 	rpcRequest := &pb.PostReceivePackRequest{
 		Repository:   repo,
 		GlId:         glId,
+		GlUsername:   glUsername,
 		GlRepository: glRepository,
 	}
 
diff --git a/internal/testhelper/gitaly.go b/internal/testhelper/gitaly.go
index f0c2bc9136a21..1093fa0dfebb6 100644
--- a/internal/testhelper/gitaly.go
+++ b/internal/testhelper/gitaly.go
@@ -99,6 +99,7 @@ func (s *GitalyTestServer) PostReceivePack(stream pb.SmartHTTPService_PostReceiv
 		repo.GetStorageName(),
 		repo.GetRelativePath(),
 		req.GlId,
+		req.GlUsername,
 	}, "\000") + "\000")
 
 	// The body of the request starts in the second message
diff --git a/main_test.go b/main_test.go
index 53e5141ca3787..4ea648f9bd0cb 100644
--- a/main_test.go
+++ b/main_test.go
@@ -722,8 +722,9 @@ func runOrFail(t *testing.T, cmd *exec.Cmd) {
 func gitOkBody(t *testing.T) *api.Response {
 	repoPath := repoPath(t)
 	return &api.Response{
-		GL_ID:    "user-123",
-		RepoPath: repoPath,
+		GL_ID:       "user-123",
+		GL_USERNAME: "username",
+		RepoPath:    repoPath,
 		Repository: pb.Repository{
 			StorageName:  "default",
 			RelativePath: "foo/bar.git",
-- 
GitLab