Skip to content

Commit

Permalink
📱 cleanup summary report with stage level grouping
Browse files Browse the repository at this point in the history
  • Loading branch information
harshanarayana committed Jun 10, 2020
1 parent fa2c23e commit 3737af6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
10 changes: 8 additions & 2 deletions models/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ var TypeToColumnMap = map[string]string{
"notes": "M",
}

type IssueSummary struct {
IssueId string `json:"issue_id"`
Title string `json:"title"`
Stage string `json:"stage"`
Status string `json:"status"`
}

type Summary struct {
Count int
IssueData map[string]string
IssueData map[string][]IssueSummary
}
17 changes: 12 additions & 5 deletions sheets/sheets.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,19 @@ func GetSummary(owner string) map[string]models.Summary {
for _, item := range items {

if _, ok := data[item.EnhancementStatus]; !ok {
data[item.EnhancementStatus] = models.Summary{IssueData: make(map[string]string, 0)}
data[item.EnhancementStatus] = models.Summary{IssueData: map[string][]models.IssueSummary{}}
}
s := data[item.EnhancementStatus]
s.Count += 1
s.IssueData[item.IssueID] = item.EnhancementTitle
data[item.EnhancementStatus] = s

if _, ok := data[item.EnhancementStatus].IssueData[item.Stage]; !ok {
data[item.EnhancementStatus].IssueData[item.Stage] = make([]models.IssueSummary, 0)
}

data[item.EnhancementStatus].IssueData[item.Stage] = append(data[item.EnhancementStatus].IssueData[item.Stage], models.IssueSummary{
Title: item.EnhancementTitle,
Stage: item.Stage,
Status: item.StageStatus,
IssueId: item.IssueID,
})
}
return data
}
33 changes: 12 additions & 21 deletions utils/sheets.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/olekukonko/tablewriter"
"k8s-enhancements/models"
"os"
"sort"
"strconv"
"strings"
)
Expand All @@ -14,37 +13,29 @@ var tracker models.Tracker
func DisplaySummary(summary map[string]models.Summary) {
table := tablewriter.NewWriter(os.Stdout)

table.SetHeader([]string{"Enhancement Status", "Issue Count", "Issue ID", "Issue Description"})
table.SetHeader([]string{"Enhancement Status", "Stage", "Issue Count", "Issue ID", "Issue Description"})

table.SetHeaderColor(
tablewriter.Colors{tablewriter.Bold},
tablewriter.Colors{tablewriter.Bold},
tablewriter.Colors{tablewriter.Bold},
tablewriter.Colors{tablewriter.Bold},
tablewriter.Colors{tablewriter.Bold},
)

var data [][]string

for status, info := range summary {
issueIDs := make([]string, 0)
for id, _ := range info.IssueData {
issueIDs = append(issueIDs, id)
}

// Pass in our list and a func to compare values
sort.Slice(issueIDs, func(i, j int) bool {
numA, _ := strconv.Atoi(issueIDs[i])
numB, _ := strconv.Atoi(issueIDs[j])
return numA < numB
})

for _, id := range issueIDs {
r := make([]string, 0)
r = append(r, status)
r = append(r, strconv.Itoa(info.Count))
r = append(r, id)
r = append(r, info.IssueData[id])
data = append(data, r)
for stage, records := range info.IssueData {
for _, record := range records {
r := make([]string, 0)
r = append(r, status)
r = append(r, stage)
r = append(r, strconv.Itoa(len(records)))
r = append(r, record.IssueId)
r = append(r, record.Title)
data = append(data, r)
}
}
}

Expand Down

0 comments on commit 3737af6

Please sign in to comment.