Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't trim Git branches/tags with slashes down to the first component #33

Merged
merged 1 commit into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion httplistener/generic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func testMultipartBase64(t *testing.T) {
}
}

func TestAll(t *testing.T) {
func TestGeneric(t *testing.T) {
writer, err := loggo.RemoveWriter("default")
if err != nil {
t.Error(err)
Expand Down
3 changes: 2 additions & 1 deletion httplistener/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ var defaultTemplates = map[string]string{
}

func refName(ref string) string {
// Trim leading 'refs/heads/', 'refs/tags/' etc.
parts := strings.Split(ref, "/")
return parts[2]
return strings.Join(parts[2:], "/")
}

func refType(ref string) string {
Expand Down
16 changes: 16 additions & 0 deletions httplistener/templates_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package httplistener

import "testing"

func TestTemplates(t *testing.T) {
test_refName(t, "refs/heads/main", "main")
test_refName(t, "refs/tags/v1.2.3", "v1.2.3")
test_refName(t, "refs/heads/feature/123-abc", "feature/123-abc")
}

func test_refName(t *testing.T, ref string, expected string) {
got := refName(ref)
if got != expected {
t.Fatalf("Expected ref %q to be prettified to %q, got %q", ref, expected, got)
}
}