Skip to content

Commit

Permalink
Don't trim Git branches/tags with slashes down to the first component
Browse files Browse the repository at this point in the history
  • Loading branch information
edwinbalani authored and russss committed Mar 16, 2024
1 parent 1770b0d commit c4db8d0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
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)
}
}

0 comments on commit c4db8d0

Please sign in to comment.