diff options
author | Andrew Newdigate <andrew@gitlab.com> | 2017-08-10 15:21:10 +0300 |
---|---|---|
committer | Andrew Newdigate <andrew@gitlab.com> | 2017-08-10 15:21:10 +0300 |
commit | 28cac33712676196f3365d04d40b3db7c7aebd63 (patch) | |
tree | d82fbe055408016c9782292589429eb26f32b70d /internal/helper | |
parent | ff4830c2f57ed9cdfef856782cf06a2bb11042a6 (diff) |
Log top level group for easier analysis
Diffstat (limited to 'internal/helper')
-rw-r--r-- | internal/helper/fieldextractors/repository.go | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/internal/helper/fieldextractors/repository.go b/internal/helper/fieldextractors/repository.go index 582a647d1..2b812d3d1 100644 --- a/internal/helper/fieldextractors/repository.go +++ b/internal/helper/fieldextractors/repository.go @@ -1,6 +1,10 @@ package fieldextractors -import pb "gitlab.com/gitlab-org/gitaly-proto/go" +import ( + "strings" + + pb "gitlab.com/gitlab-org/gitaly-proto/go" +) func formatRepoRequest(repo *pb.Repository) map[string]interface{} { if repo == nil { @@ -12,11 +16,26 @@ func formatRepoRequest(repo *pb.Repository) map[string]interface{} { } return map[string]interface{}{ - "repoStorage": repo.StorageName, - "repoPath": repo.RelativePath, + "repoStorage": repo.StorageName, + "repoPath": repo.RelativePath, + "topLevelGroup": getTopLevelGroupFromRepoPath(repo.RelativePath), } } +// getTopLevelGroupFromRepoPath gives the top-level group name, given +// a repoPath. For example: +// - "gitlab-org/gitlab-ce.git" returns "gitlab-org" +// - "gitlab-org/gitter/webapp.git" returns "gitlab-org" +// - "x.git" returns "" +func getTopLevelGroupFromRepoPath(repoPath string) string { + parts := strings.SplitN(repoPath, "/", 2) + if len(parts) != 2 { + return "" + } + + return parts[0] +} + type repositoryBasedRequest interface { GetRepository() *pb.Repository } |