diff --git a/httplistener/generic_test.go b/httplistener/generic_test.go index 37698bc..114be0e 100644 --- a/httplistener/generic_test.go +++ b/httplistener/generic_test.go @@ -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) diff --git a/httplistener/templates.go b/httplistener/templates.go index c7efbd3..fa4ea53 100644 --- a/httplistener/templates.go +++ b/httplistener/templates.go @@ -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 { diff --git a/httplistener/templates_test.go b/httplistener/templates_test.go new file mode 100644 index 0000000..f95cb28 --- /dev/null +++ b/httplistener/templates_test.go @@ -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) + } +}