Skip to content

Commit

Permalink
feat: add gateway issues/sections
Browse files Browse the repository at this point in the history
  • Loading branch information
npepinpe authored and MiguelPires committed May 6, 2021
1 parent c84d987 commit b47c01a
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
1 change: 0 additions & 1 deletion pkg/github/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,3 @@ func (ghc *Client) FetchIssues(githubOrg, githubRepo, label string) *Changelog {

return changelog
}

7 changes: 6 additions & 1 deletion pkg/github/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

const (
brokerLabel = "Scope: broker"
gatewayLabel = "Scope: gateway"
javaClientLabel = "Scope: clients/java"
goClientLabel = "Scope: clients/go"

Expand All @@ -15,7 +16,7 @@ const (
docsLabel = "Type: Docs"
)

var knownLabels = []string{brokerLabel, javaClientLabel, goClientLabel, enhancementLabel, bugLabel, docsLabel}
var knownLabels = []string{brokerLabel, gatewayLabel, javaClientLabel, goClientLabel, enhancementLabel, bugLabel, docsLabel}

type Issue struct {
title *string
Expand Down Expand Up @@ -52,6 +53,10 @@ func (i *Issue) HasBrokerLabel() bool {
return i.hasLabel(brokerLabel)
}

func (i *Issue) HasGatewayLabel() bool {
return i.hasLabel(gatewayLabel)
}

func (i *Issue) HasJavaClientLabel() bool {
return i.hasLabel(javaClientLabel)
}
Expand Down
17 changes: 17 additions & 0 deletions pkg/github/issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ func TestIssue_HasBrokerLabel(t *testing.T) {
}
}

func TestIssue_HasGatewayLabel(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, gatewayLabel), hasLabel: true},
"Multiple Labels": {issue: createIssue("", 0, "", false, javaClientLabel, enhancementLabel, gatewayLabel), hasLabel: true},
}
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
assert.Equal(t, tc.hasLabel, tc.issue.HasGatewayLabel())
})
}
}

func TestIssue_HasJavaClientLabel(t *testing.T) {
tests := map[string]struct {
issue *Issue
Expand Down
10 changes: 10 additions & 0 deletions pkg/github/section.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

const (
brokerSection = "Broker"
gatewaySection = "Gateway"
javaClientSection = "Java Client"
goClientSection = "Go Client"
miscSection = "Misc"
Expand All @@ -27,6 +28,10 @@ func (s *Section) AddIssue(issue *Issue) *Section {
s.addIssueToSection(brokerSection, issue)
}

if issue.HasGatewayLabel() {
s.addIssueToSection(gatewaySection, issue)
}

if issue.HasJavaClientLabel() {
s.addIssueToSection(javaClientSection, issue)
}
Expand All @@ -50,6 +55,10 @@ func (s *Section) GetBrokerIssues() []*Issue {
return s.getIssues(brokerSection)
}

func (s *Section) GetGatewayIssues() []*Issue {
return s.getIssues(gatewaySection)
}

func (s *Section) GetJavaClientIssues() []*Issue {
return s.getIssues(javaClientSection)
}
Expand All @@ -74,6 +83,7 @@ func (s *Section) String() string {
var b bytes.Buffer

b.WriteString(sectionToString(brokerSection, s.GetBrokerIssues()))
b.WriteString(sectionToString(gatewaySection, s.GetGatewayIssues()))
b.WriteString(sectionToString(javaClientSection, s.GetJavaClientIssues()))
b.WriteString(sectionToString(goClientSection, s.GetGoClientIssues()))
b.WriteString(sectionToString(miscSection, s.GetMiscIssues()))
Expand Down
23 changes: 23 additions & 0 deletions pkg/github/section_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,29 @@ func TestSection_GetBrokerIssues(t *testing.T) {
}
}

func TestSection_GetGatewayIssues(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(gatewayLabel)), size: 1},
"Multiple Issues": {
section: NewSection().
AddIssue(createIssueWithLabel(gatewayLabel, enhancementLabel)).
AddIssue(createIssueWithLabel(bugLabel, gatewayLabel)).
AddIssue(createIssueWithLabel(javaClientLabel)),
size: 2,
},
}
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
assert.Equal(t, tc.size, len(tc.section.GetGatewayIssues()))
})
}
}

func TestSection_GetJavaClientIssues(t *testing.T) {
tests := map[string]struct {
section *Section
Expand Down

0 comments on commit b47c01a

Please sign in to comment.