From 37a87ecc15a1082154cea488cc32d737b2f69a54 Mon Sep 17 00:00:00 2001 From: Houssain Barouni Date: Mon, 13 May 2024 21:57:41 +0200 Subject: [PATCH] feat: add Operate and Tasklist issues/sections --- pkg/github/issue.go | 12 ++++++++++ pkg/github/issues_test.go | 34 ++++++++++++++++++++++++++++ pkg/github/section.go | 22 ++++++++++++++++++ pkg/github/section_test.go | 46 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+) diff --git a/pkg/github/issue.go b/pkg/github/issue.go index 782f5d6..195c980 100644 --- a/pkg/github/issue.go +++ b/pkg/github/issue.go @@ -15,6 +15,8 @@ const ( bugLabel = "kind/bug" docsLabel = "kind/documentation" toilLabel = "kind/toil" + operateLabel = "component/operate" + tasklistLabel = "component/tasklist" ) var knownLabels = []string{ @@ -27,6 +29,8 @@ var knownLabels = []string{ docsLabel, zbctlLabel, toilLabel, + operateLabel, + tasklistLabel, } type Issue struct { @@ -96,6 +100,14 @@ func (i *Issue) HasToilLabel() bool { return i.hasLabel(toilLabel) } +func (i *Issue) HasOperateLabel() bool { + return i.hasLabel(operateLabel) +} + +func (i *Issue) HasTasklistLabel() bool { + return i.hasLabel(tasklistLabel) +} + func (i *Issue) hasLabel(label string) bool { return i.labels[label] } diff --git a/pkg/github/issues_test.go b/pkg/github/issues_test.go index c1649d1..230fbb0 100644 --- a/pkg/github/issues_test.go +++ b/pkg/github/issues_test.go @@ -157,6 +157,40 @@ func TestIssue_HasToilLabel(t *testing.T) { } } +func TestIssue_HasOperateLabel(t *testing.T) { + tests := map[string]struct { + issue *Issue + hasLabel bool + }{ + "No Label": {issue: createIssue("", 0, "", false), hasLabel: false}, + "Different Label": {issue: createIssue("", 0, "", false, javaClientLabel), hasLabel: false}, + "Has Label": {issue: createIssue("", 0, "", false, operateLabel), hasLabel: true}, + "Multiple Labels": {issue: createIssue("", 0, "", false, operateLabel, featureLabel, tasklistLabel), hasLabel: true}, + } + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + assert.Equal(t, tc.hasLabel, tc.issue.HasOperateLabel()) + }) + } +} + +func TestIssue_HasTasklistLabel(t *testing.T) { + tests := map[string]struct { + issue *Issue + hasLabel bool + }{ + "No Label": {issue: createIssue("", 0, "", false), hasLabel: false}, + "Different Label": {issue: createIssue("", 0, "", false, operateLabel), hasLabel: false}, + "Has Label": {issue: createIssue("", 0, "", false, tasklistLabel), hasLabel: true}, + "Multiple Labels": {issue: createIssue("", 0, "", false, tasklistLabel, featureLabel, brokerLabel), hasLabel: true}, + } + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + assert.Equal(t, tc.hasLabel, tc.issue.HasTasklistLabel()) + }) + } +} + func TestIssue_String(t *testing.T) { issue := createIssue("Test Issue", 1234, "https://github.com", false) assert.Equal(t, "Test Issue ([#1234](https://github.com))", issue.String()) diff --git a/pkg/github/section.go b/pkg/github/section.go index 7899d16..92353cf 100644 --- a/pkg/github/section.go +++ b/pkg/github/section.go @@ -11,6 +11,8 @@ const ( javaClientSection = "Java Client" goClientSection = "Go Client" zbctlSection = "zbctl" + operateSection = "Operate" + tasklistSection = "Tasklist" miscSection = "Misc" ) @@ -51,6 +53,16 @@ func (s *Section) AddIssue(issue *Issue) *Section { hasSection = true } + if issue.HasOperateLabel() { + s.addIssueToSection(operateSection, issue) + hasSection = true + } + + if issue.HasTasklistLabel() { + s.addIssueToSection(tasklistSection, issue) + hasSection = true + } + if !hasSection { s.addIssueToSection(miscSection, issue) } @@ -81,6 +93,14 @@ func (s *Section) GetZbctlIssues() []*Issue { return s.getIssues(zbctlSection) } +func (s *Section) GetOperateIssues() []*Issue { + return s.getIssues(operateSection) +} + +func (s *Section) GetTasklistIssues() []*Issue { + return s.getIssues(tasklistSection) +} + func (s *Section) GetMiscIssues() []*Issue { return s.getIssues(miscSection) } @@ -101,6 +121,8 @@ func (s *Section) String() string { b.WriteString(sectionToString(javaClientSection, s.GetJavaClientIssues())) b.WriteString(sectionToString(goClientSection, s.GetGoClientIssues())) b.WriteString(sectionToString(zbctlSection, s.GetZbctlIssues())) + b.WriteString(sectionToString(operateSection, s.GetOperateIssues())) + b.WriteString(sectionToString(tasklistSection, s.GetTasklistIssues())) b.WriteString(sectionToString(miscSection, s.GetMiscIssues())) return b.String() diff --git a/pkg/github/section_test.go b/pkg/github/section_test.go index 702a7e9..ccdd102 100644 --- a/pkg/github/section_test.go +++ b/pkg/github/section_test.go @@ -99,6 +99,52 @@ func TestSection_GetGoClientIssues(t *testing.T) { } } +func TestSection_GetOperateIssues(t *testing.T) { + tests := map[string]struct { + section *Section + size int + }{ + "No Issues": {section: NewSection(), size: 0}, + "Different Issue": {section: NewSection().AddIssue(createIssueWithLabel("unknown")), size: 0}, + "One Issue": {section: NewSection().AddIssue(createIssueWithLabel(operateLabel)), size: 1}, + "Multiple Issues": { + section: NewSection(). + AddIssue(createIssueWithLabel(operateLabel, featureLabel)). + AddIssue(createIssueWithLabel(bugLabel, operateLabel)). + AddIssue(createIssueWithLabel(brokerLabel)), + size: 2, + }, + } + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + assert.Equal(t, tc.size, len(tc.section.GetOperateIssues())) + }) + } +} + +func TestSection_GetTasklistIssues(t *testing.T) { + tests := map[string]struct { + section *Section + size int + }{ + "No Issues": {section: NewSection(), size: 0}, + "Different Issue": {section: NewSection().AddIssue(createIssueWithLabel("unknown")), size: 0}, + "One Issue": {section: NewSection().AddIssue(createIssueWithLabel(tasklistLabel)), size: 1}, + "Multiple Issues": { + section: NewSection(). + AddIssue(createIssueWithLabel(tasklistLabel, featureLabel)). + AddIssue(createIssueWithLabel(bugLabel, tasklistLabel)). + AddIssue(createIssueWithLabel(brokerLabel)), + size: 2, + }, + } + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + assert.Equal(t, tc.size, len(tc.section.GetTasklistIssues())) + }) + } +} + func TestSection_GetMiscIssues(t *testing.T) { tests := map[string]struct { section *Section