fleet/tools/github-manage/pkg/tui/table.go
George Karr 3c687f2ed9
Adding direction to add views and workflows (#33177)
This looks like a log but it's just moving the code that lived in
cmd/gm/ui.go into it's own pkg that makes it clearer where each part of
the UI lives.

I am also adding the functionality for bulk sprint demo to grab names
from github usernames.
2025-09-25 14:05:39 -05:00

78 lines
2 KiB
Go

package tui
import (
"fmt"
"strings"
"fleetdm/gm/pkg/ghapi"
)
func truncTitle(title string) string {
if len(title) > 50 {
return title[:47] + "..."
}
return title
}
// prioritize labels 'story', 'bug', ':release', ':product', '#g-mdm', '#g-orchestration',
// '#g-software'
// show a maximum of 30 characters, if longer, truncate and add '...+n' where n is the number of additional labels
func truncLables(labels []ghapi.Label) string {
if len(labels) == 0 {
return fmt.Sprintf("%-35s", "- No Labels -")
}
priorityLabels := map[string]bool{"story": true, "bug": true, ":release": true, ":product": true, "#g-mdm": true, "#g-orchestration": true, "#g-software": true}
var labelNames []string
for _, label := range labels {
labelNames = append(labelNames, label.Name)
}
displayLabels := []string{}
secondaryLabels := []string{}
for _, label := range labelNames {
if priorityLabels[label] {
displayLabels = append(displayLabels, label)
} else {
secondaryLabels = append(secondaryLabels, label)
}
}
if len(secondaryLabels) > 0 {
displayLabels = append(displayLabels, secondaryLabels...)
}
countDisplay := 0
sumCharacters := 0
for _, label := range displayLabels {
if (sumCharacters + len(label)) > 30 {
break
}
countDisplay += 1
sumCharacters += len(label) + 2
}
extraLabels := 0
if countDisplay < len(displayLabels) {
extraLabels = len(displayLabels) - countDisplay
}
extraString := ""
if extraLabels > 0 {
extraString = fmt.Sprintf("...+%d", extraLabels)
}
return fmt.Sprintf("%-35s", fmt.Sprintf("%s%s", strings.Join(displayLabels[:countDisplay], ", "), extraString))
}
func truncEstimate(estimate int) string {
estString := fmt.Sprintf("%d", estimate)
if estimate == 0 {
estString = "-"
}
return fmt.Sprintf("%-9s", estString)
}
func truncType(typename string) string {
if typename == "" {
typename = "-"
}
// Return the typename with spaces filling out to 10 characters
if len(typename) < 10 {
return fmt.Sprintf("%-10s", typename)
}
return strings.TrimSpace(typename[:10])
}