Skip to content

Commit

Permalink
move title cleanup to its own testable function
Browse files Browse the repository at this point in the history
Signed-off-by: Doug Hellmann <[email protected]>
  • Loading branch information
dhellmann committed Nov 12, 2020
1 parent 6dd154e commit 8016677
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 6 deletions.
12 changes: 12 additions & 0 deletions tools/enhancements/title.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package enhancements

import "strings"

func CleanTitle(title string) string {
// Sometimes we have a superfluous "enhancement:" prefix in
// the PR title
if strings.HasPrefix(strings.ToLower(title), "enhancement:") {
title = strings.TrimLeft(title[12:], " ")
}
return title
}
41 changes: 41 additions & 0 deletions tools/enhancements/title_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package enhancements

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestCleanTitle(t *testing.T) {
for _, tc := range []struct {
Scenario string
Input string
Expected string
}{
{
Scenario: "empty-string",
Input: "",
Expected: "",
},
{
Scenario: "no-changes",
Input: "this is a perfectly nice title",
Expected: "this is a perfectly nice title",
},
{
Scenario: "enhancement-prefix",
Input: "enhancement: remove the prefix",
Expected: "remove the prefix",
},
{
Scenario: "enhancement-prefix-caps",
Input: "Enhancement: Remove the prefix",
Expected: "Remove the prefix",
},
} {
t.Run(tc.Scenario, func(t *testing.T) {
actual := CleanTitle(tc.Input)
assert.Equal(t, tc.Expected, actual)
})
}
}
1 change: 1 addition & 0 deletions tools/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.14
require (
github.com/google/go-github/v32 v32.1.0
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.6.1
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
gopkg.in/yaml.v2 v2.3.0
)
9 changes: 9 additions & 0 deletions tools/go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand All @@ -8,6 +10,11 @@ github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASu
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand All @@ -28,3 +35,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
7 changes: 1 addition & 6 deletions tools/report/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,7 @@ func showPRs(name string, prds []*stats.PullRequestDetails, withDescription bool
groupPrefix = ""
}

// Sometimes we have a superfluous "enhancement:" prefix in
// the PR title
title := *prd.Pull.Title
if strings.HasPrefix(strings.ToLower(title), "enhancement:") {
title = strings.TrimLeft(title[12:], " ")
}
title := enhancements.CleanTitle(*prd.Pull.Title)

fmt.Printf("- [%d](%s): (%d/%d) %s%s (%s)\n",
*prd.Pull.Number,
Expand Down

0 comments on commit 8016677

Please sign in to comment.