Skip to content

Commit

Permalink
fix: allow slash in slug to avoid gitlab subgroup flattening
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippHeuer committed Jan 16, 2024
1 parent ad3391c commit 73c73c2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pkg/util/slug.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ func Slugify(input string, namingStyle string) string {
if namingStyle == "lowercase" {
return strings.ToLower(input)
} else if namingStyle == "slug" || namingStyle == "" {
s := slug.Make(input)
return strings.ToLower(s)
parts := strings.Split(input, "/")
for i, part := range parts {
parts[i] = slug.Make(part)
}
return strings.Join(parts, "/")
} else if namingStyle == "name" {
return input
}
Expand Down
33 changes: 33 additions & 0 deletions pkg/util/slug_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package util

import (
"testing"

"github.com/gosimple/slug"
)

func TestSlugify(t *testing.T) {
testCases := []struct {
input string
namingStyle string
expectedOutput string
}{
{"Hello World", "lowercase", "hello world"},
{"Hello World", "slug", "hello-world"},
{"Hello World/My Project", "slug", "hello-world/my-project"},
{"Hello World", "name", "Hello World"},

// Test case for empty naming style, defaulting to slug
{"Hello World", "", slug.Make("Hello World")},
}

for _, tc := range testCases {
t.Run(tc.namingStyle, func(t *testing.T) {
result := Slugify(tc.input, tc.namingStyle)

if result != tc.expectedOutput {
t.Errorf("Expected %s, but got %s", tc.expectedOutput, result)
}
})
}
}

0 comments on commit 73c73c2

Please sign in to comment.