Skip to content

Commit

Permalink
feat: add Operate and Tasklist issues/sections
Browse files Browse the repository at this point in the history
  • Loading branch information
houssain-barouni committed May 13, 2024
1 parent ce4dc1f commit 37a87ec
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/github/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const (
bugLabel = "kind/bug"
docsLabel = "kind/documentation"
toilLabel = "kind/toil"
operateLabel = "component/operate"
tasklistLabel = "component/tasklist"
)

var knownLabels = []string{
Expand All @@ -27,6 +29,8 @@ var knownLabels = []string{
docsLabel,
zbctlLabel,
toilLabel,
operateLabel,
tasklistLabel,
}

type Issue struct {
Expand Down Expand Up @@ -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]
}
Expand Down
34 changes: 34 additions & 0 deletions pkg/github/issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
22 changes: 22 additions & 0 deletions pkg/github/section.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const (
javaClientSection = "Java Client"
goClientSection = "Go Client"
zbctlSection = "zbctl"
operateSection = "Operate"
tasklistSection = "Tasklist"
miscSection = "Misc"
)

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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()
Expand Down
46 changes: 46 additions & 0 deletions pkg/github/section_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 37a87ec

Please sign in to comment.