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:
authorPavlo Strokov <pstrokov@gitlab.com>2020-06-24 10:01:28 +0300
committerJohn Cai <jcai@gitlab.com>2020-06-25 18:16:46 +0300
commit49efb44cc6036b11db2aa6cd37f7dcd33dcc0a58 (patch)
treef59b3ff966e282383bba2b7ec6881e8994aff4cb
parent0fb7caf0703e3f78085054c367dcba9f640140de (diff)
Merge branch 'jc-hotfix-add-gl-project-path' into 'master'jc-add-hotfix-to-13-1-stable
Add GL_PROJECT_PATH for custom hooks Closes #2902 See merge request gitlab-org/gitaly!2313
-rw-r--r--changelogs/unreleased/jc-hotfix-add-gl-project-path.yml5
-rw-r--r--internal/git/receivepack.go1
-rw-r--r--internal/service/operations/tags_test.go4
-rw-r--r--internal/service/smarthttp/receive_pack_test.go5
-rw-r--r--internal/service/ssh/receive_pack_test.go7
-rw-r--r--ruby/lib/gitlab/git/hook.rb1
-rw-r--r--ruby/lib/gitlab/git/repository.rb3
7 files changed, 23 insertions, 3 deletions
diff --git a/changelogs/unreleased/jc-hotfix-add-gl-project-path.yml b/changelogs/unreleased/jc-hotfix-add-gl-project-path.yml
new file mode 100644
index 000000000..e43b10f31
--- /dev/null
+++ b/changelogs/unreleased/jc-hotfix-add-gl-project-path.yml
@@ -0,0 +1,5 @@
+---
+title: Add GL_PROJECT_PATH for custom hooks
+merge_request: 2313
+author:
+type: changed
diff --git a/internal/git/receivepack.go b/internal/git/receivepack.go
index 6e27a5b58..05ce8a872 100644
--- a/internal/git/receivepack.go
+++ b/internal/git/receivepack.go
@@ -43,6 +43,7 @@ func ReceivePackHookEnv(ctx context.Context, req ReceivePackRequest) ([]string,
fmt.Sprintf("GL_ID=%s", req.GetGlId()),
fmt.Sprintf("GL_USERNAME=%s", req.GetGlUsername()),
fmt.Sprintf("GL_REPOSITORY=%s", req.GetGlRepository()),
+ fmt.Sprintf("GL_PROJECT_PATH=%s", req.GetRepository().GetGlProjectPath()),
fmt.Sprintf("GITALY_SOCKET=" + config.GitalyInternalSocketPath()),
fmt.Sprintf("GITALY_REPO=%s", repo),
fmt.Sprintf("GITALY_TOKEN=%s", config.Config.Auth.Token),
diff --git a/internal/service/operations/tags_test.go b/internal/service/operations/tags_test.go
index 201eda9b3..3def7c506 100644
--- a/internal/service/operations/tags_test.go
+++ b/internal/service/operations/tags_test.go
@@ -218,6 +218,9 @@ func testSuccessfulGitHooksForUserCreateTagRequest(t *testing.T, ctx context.Con
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ projectPath := "project/path"
+ testRepo.GlProjectPath = projectPath
+
tagName := "new-tag"
request := &gitalypb.UserCreateTagRequest{
@@ -240,6 +243,7 @@ func testSuccessfulGitHooksForUserCreateTagRequest(t *testing.T, ctx context.Con
output := string(testhelper.MustReadFile(t, hookOutputTempPath))
require.Contains(t, output, "GL_USERNAME="+testhelper.TestUser.GlUsername)
+ require.Contains(t, output, "GL_PROJECT_PATH="+projectPath)
})
}
}
diff --git a/internal/service/smarthttp/receive_pack_test.go b/internal/service/smarthttp/receive_pack_test.go
index 463460060..2b33fb3f3 100644
--- a/internal/service/smarthttp/receive_pack_test.go
+++ b/internal/service/smarthttp/receive_pack_test.go
@@ -52,6 +52,10 @@ func TestSuccessfulReceivePackRequest(t *testing.T) {
require.NoError(t, err)
push := newTestPush(t, nil)
+
+ projectPath := "project/path"
+
+ repo.GlProjectPath = projectPath
firstRequest := &gitalypb.PostReceivePackRequest{Repository: repo, GlId: "user-123", GlRepository: "project-456"}
response := doPush(t, stream, firstRequest, push.body)
@@ -68,6 +72,7 @@ func TestSuccessfulReceivePackRequest(t *testing.T) {
"GL_ID=user-123",
"GL_REPOSITORY=project-456",
"GL_PROTOCOL=http",
+ "GL_PROJECT_PATH=" + projectPath,
"GITALY_GITLAB_SHELL_DIR=" + "/foo/bar/gitlab-shell",
} {
require.Contains(t, strings.Split(string(envData), "\n"), env)
diff --git a/internal/service/ssh/receive_pack_test.go b/internal/service/ssh/receive_pack_test.go
index a72cdbd5e..4b6a18afb 100644
--- a/internal/service/ssh/receive_pack_test.go
+++ b/internal/service/ssh/receive_pack_test.go
@@ -88,8 +88,9 @@ func TestReceivePackPushSuccess(t *testing.T) {
defer stop()
glRepository := "project-456"
+ glProjectPath := "project/path"
- lHead, rHead, err := testCloneAndPush(t, serverSocketPath, pushParams{storageName: testRepo.GetStorageName(), glID: "user-123", glRepository: glRepository})
+ lHead, rHead, err := testCloneAndPush(t, serverSocketPath, pushParams{storageName: testRepo.GetStorageName(), glID: "user-123", glRepository: glRepository, glProjectPath: glProjectPath})
if err != nil {
t.Fatal(err)
}
@@ -101,6 +102,7 @@ func TestReceivePackPushSuccess(t *testing.T) {
for _, env := range []string{
"GL_ID=user-123",
fmt.Sprintf("GL_REPOSITORY=%s", glRepository),
+ fmt.Sprintf("GL_PROJECT_PATH=%s", glProjectPath),
"GL_PROTOCOL=ssh",
"GITALY_GITLAB_SHELL_DIR=" + "/foo/bar/gitlab-shell",
} {
@@ -305,7 +307,7 @@ func setupSSHClone(t *testing.T) (SSHCloneDetails, func()) {
}
func sshPush(t *testing.T, cloneDetails SSHCloneDetails, serverSocketPath string, params pushParams) (string, string, error) {
- pbTempRepo := &gitalypb.Repository{StorageName: params.storageName, RelativePath: cloneDetails.TempRepo}
+ pbTempRepo := &gitalypb.Repository{StorageName: params.storageName, RelativePath: cloneDetails.TempRepo, GlProjectPath: params.glProjectPath}
pbMarshaler := &jsonpb.Marshaler{}
payload, err := pbMarshaler.MarshalToString(&gitalypb.SSHReceivePackRequest{
Repository: pbTempRepo,
@@ -385,6 +387,7 @@ type pushParams struct {
storageName string
glID string
glRepository string
+ glProjectPath string
gitConfigOptions []string
gitProtocol string
}
diff --git a/ruby/lib/gitlab/git/hook.rb b/ruby/lib/gitlab/git/hook.rb
index f60a638e1..7755ef925 100644
--- a/ruby/lib/gitlab/git/hook.rb
+++ b/ruby/lib/gitlab/git/hook.rb
@@ -113,6 +113,7 @@ module Gitlab
'GL_ID' => gl_id,
'GL_USERNAME' => gl_username,
'GL_REPOSITORY' => repository.gl_repository,
+ 'GL_PROJECT_PATH' => repository.gl_project_path,
'GL_PROTOCOL' => GL_PROTOCOL,
'PWD' => repo_path,
'GIT_DIR' => repo_path,
diff --git a/ruby/lib/gitlab/git/repository.rb b/ruby/lib/gitlab/git/repository.rb
index 942880482..fe3023554 100644
--- a/ruby/lib/gitlab/git/repository.rb
+++ b/ruby/lib/gitlab/git/repository.rb
@@ -62,7 +62,7 @@ module Gitlab
# Directory name of repo
attr_reader :name
- attr_reader :gitlab_projects, :storage, :gl_repository, :relative_path
+ attr_reader :gitlab_projects, :storage, :gl_repository, :gl_project_path, :relative_path
def initialize(gitaly_repository, path, gl_repository, gitlab_projects, combined_alt_dirs = "", feature_flags = GitalyServer::FeatureFlags.new({}))
@gitaly_repository = gitaly_repository
@@ -75,6 +75,7 @@ module Gitlab
@relative_path = gitaly_repository.relative_path
@path = path
@gl_repository = gl_repository
+ @gl_project_path = gitaly_repository.gl_project_path
@gitlab_projects = gitlab_projects
@feature_flags = feature_flags
end