summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/generate/src_contribs.go30
-rw-r--r--cmd/generate/src_contribs_test.go35
-rw-r--r--go.mod6
-rw-r--r--go.sum6
4 files changed, 66 insertions, 11 deletions
diff --git a/cmd/generate/src_contribs.go b/cmd/generate/src_contribs.go
index b47cf89..760b56a 100644
--- a/cmd/generate/src_contribs.go
+++ b/cmd/generate/src_contribs.go
@@ -20,7 +20,8 @@ type Contribution struct {
SubmittedAt time.Time `json:"submitted-at"`
LastUpdatedAt time.Time `json:"last-updated-at"`
Status string `json:"status"`
- StatusClass string `json:"-"`
+
+ StatusClass string `json:"-"`
}
func ReadContribs(filename string) ([]Contribution, error) {
@@ -62,19 +63,26 @@ func (c *Contribution) Fill() error {
return err
}
}
+ c.StatusClass, err = classifyStatus(c.Status)
+ if err != nil {
+ return err
+ }
+ return nil
+}
+
+func classifyStatus(status string) (string, error) {
switch {
- case strings.Contains(c.Status, "released") || strings.Contains(c.Status, "deployed"):
- c.StatusClass = "released"
- case strings.Contains(c.Status, "merged"):
- c.StatusClass = "merged"
- case strings.Contains(c.Status, "open"):
- c.StatusClass = "open"
- case strings.Contains(c.Status, "closed") || strings.Contains(c.Status, "locked"):
- c.StatusClass = "closed"
+ case strings.Contains(status, "released") || strings.Contains(status, "deployed"):
+ return "released", nil
+ case strings.Contains(status, "merged"):
+ return "merged", nil
+ case strings.Contains(status, "open"):
+ return "open", nil
+ case strings.Contains(status, "closed") || strings.Contains(status, "locked"):
+ return "closed", nil
default:
- return fmt.Errorf("unrecognized status string: %q", c.Status)
+ return "", fmt.Errorf("unrecognized status string: %q", status)
}
- return nil
}
var (
diff --git a/cmd/generate/src_contribs_test.go b/cmd/generate/src_contribs_test.go
new file mode 100644
index 0000000..f7566c0
--- /dev/null
+++ b/cmd/generate/src_contribs_test.go
@@ -0,0 +1,35 @@
+package main
+
+import (
+ "testing"
+
+ "github.com/alecthomas/assert/v2"
+)
+
+func TestClassifyStatus(t *testing.T) {
+ testcases := map[string]struct {
+ Str string
+ Err string
+ }{
+ "merged+deployed": {"released", ""},
+ "released in v1.2": {"released", ""},
+
+ "merged": {"merged", ""},
+
+ "open": {"open", ""},
+
+ "closed": {"closed", ""},
+ "locked": {"closed", ""},
+ }
+ for in, exp := range testcases {
+ t.Run(in, func(t *testing.T) {
+ actStr, actErr := classifyStatus(in)
+ assert.Equal(t, exp.Str, actStr)
+ if exp.Err == "" {
+ assert.NoError(t, actErr)
+ } else {
+ assert.EqualError(t, actErr, exp.Err)
+ }
+ })
+ }
+}
diff --git a/go.mod b/go.mod
index 6557c06..76a8828 100644
--- a/go.mod
+++ b/go.mod
@@ -3,6 +3,12 @@ module git.lukeshu.com/www
go 1.22.2
require (
+ github.com/alecthomas/assert/v2 v2.8.1
github.com/yuin/goldmark v1.7.1
sigs.k8s.io/yaml v1.4.0
)
+
+require (
+ github.com/alecthomas/repr v0.4.0 // indirect
+ github.com/hexops/gotextdiff v1.0.3 // indirect
+)
diff --git a/go.sum b/go.sum
index 6157653..b7034ba 100644
--- a/go.sum
+++ b/go.sum
@@ -1,5 +1,11 @@
+github.com/alecthomas/assert/v2 v2.8.1 h1:YCxnYR6jjpfnEK5AK5SysALKdUEBPGH4Y7As6tBnDw0=
+github.com/alecthomas/assert/v2 v2.8.1/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
+github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
+github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
+github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
+github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
github.com/yuin/goldmark v1.7.1 h1:3bajkSilaCbjdKVsKdZjZCLBNPL9pYzrCakKaf4U49U=
github.com/yuin/goldmark v1.7.1/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=