-
Notifications
You must be signed in to change notification settings - Fork 424
Replace raw fmt.Fprintf output in outcomes_history.go with console package #39248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
fd13d94
311b16f
7de4bd6
824669f
d5298b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import ( | |
| "strconv" | ||
| "strings" | ||
|
|
||
| "github.com/github/gh-aw/pkg/console" | ||
| "github.com/github/gh-aw/pkg/constants" | ||
| ghmapping "github.com/github/gh-aw/pkg/github" | ||
| "github.com/github/gh-aw/pkg/workflow" | ||
|
|
@@ -162,7 +163,7 @@ func RunOutcomesHistory(config OutcomesHistoryConfig) error { | |
| return nil | ||
| } | ||
|
|
||
| fmt.Fprintf(os.Stderr, "Objective history for %s (limit %d)\n", repo, config.Limit) | ||
| fmt.Fprintln(os.Stderr, console.FormatSectionHeader(fmt.Sprintf("Objective history for %s (limit %d)", repo, config.Limit))) | ||
| if data.Issues != nil { | ||
| renderHistoricalObjectiveReport(*data.Issues) | ||
| } | ||
|
|
@@ -295,22 +296,41 @@ func buildHistoricalObjectiveReport(source string, items []historicalGitHubItem, | |
| } | ||
|
|
||
| func renderHistoricalObjectiveReport(report historicalObjectiveReport) { | ||
| fmt.Fprintf(os.Stderr, "\n%s\n", strings.ToUpper(report.Source)) | ||
| fmt.Fprintf(os.Stderr, " Sample size: %d\n", report.SampleSize) | ||
| fmt.Fprintf(os.Stderr, " Scored items: %d\n", report.ScoredItems) | ||
| fmt.Fprintf(os.Stderr, " Total objective value: %d\n", report.TotalObjectiveValue) | ||
| fmt.Fprintf(os.Stderr, "\n%s\n", console.FormatSectionHeader(strings.ToUpper(report.Source))) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
💡 Impact and suggested fixThis creates an inverted TTY mismatch:
The console package itself demonstrates the correct pattern — Fix options:
|
||
| fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("Sample size: %d", report.SampleSize))) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
💡 DetailsFrom the console package source: func FormatInfoMessage(message string) string {
return applyStyle(styles.Info, "i ") + message
}
After, in any non-TTY context (CI logs, Any script, grep pattern, golden-file test, or downstream parser keyed on the old format will silently break. If the intent is purely cosmetic styling, |
||
| fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("Scored items: %d", report.ScoredItems))) | ||
| fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("Total objective value: %d", report.TotalObjectiveValue))) | ||
|
|
||
| if len(report.ObjectiveBuckets) > 0 { | ||
| fmt.Fprintln(os.Stderr, " Top objective buckets:") | ||
| bucketRows := make([][]string, 0, min(len(report.ObjectiveBuckets), 8)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/improve-codebase-architecture] Magic display-cap numbers ( 💡 Suggested changeAdd at the top of the file (alongside the existing const (
maxDisplayedBuckets = 8
maxDisplayedRepresentativeItems = 5
)Then use: bucketRows := make([][]string, 0, min(len(report.ObjectiveBuckets), maxDisplayedBuckets))
for _, bucket := range report.ObjectiveBuckets[:min(len(report.ObjectiveBuckets), maxDisplayedBuckets)] {Note: |
||
| for _, bucket := range report.ObjectiveBuckets[:min(len(report.ObjectiveBuckets), 8)] { | ||
| fmt.Fprintf(os.Stderr, " %-22s %3d x %3d = %4d\n", bucket.Label, bucket.Count, bucket.MappedValue, bucket.ContributedValue) | ||
| bucketRows = append(bucketRows, []string{ | ||
| bucket.Label, | ||
| strconv.Itoa(bucket.Count), | ||
| strconv.Itoa(bucket.MappedValue), | ||
| strconv.Itoa(bucket.ContributedValue), | ||
| }) | ||
| } | ||
| fmt.Fprint(os.Stderr, console.RenderTable(console.TableConfig{ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bucket table loses the formula relationship between columns: the old 💡 Suggested fixThe old one-liner: immediately communicates that Consider one of:
All data is still present in the table, so this is non-blocking, but the information is meaningfully less readable for diagnosing why a particular bucket dominates the objective score. |
||
| Title: "Top objective buckets", | ||
| Headers: []string{"Bucket", "Count", "Mapped Value", "Contributed Value"}, | ||
| Rows: bucketRows, | ||
| })) | ||
|
Comment on lines
+314
to
+318
|
||
| } | ||
|
|
||
| if len(report.RepresentativeItems) > 0 { | ||
| fmt.Fprintln(os.Stderr, " Representative items:") | ||
| itemRows := make([][]string, 0, min(len(report.RepresentativeItems), 5)) | ||
| for _, item := range report.RepresentativeItems[:min(len(report.RepresentativeItems), 5)] { | ||
| fmt.Fprintf(os.Stderr, " #%d %-3d %s\n", item.Number, item.ObjectiveValue, item.Title) | ||
| itemRows = append(itemRows, []string{ | ||
| fmt.Sprintf("#%d", item.Number), | ||
| strconv.Itoa(item.ObjectiveValue), | ||
| item.Title, | ||
| }) | ||
| } | ||
| fmt.Fprint(os.Stderr, console.RenderTable(console.TableConfig{ | ||
| Title: "Representative items", | ||
| Headers: []string{"Number", "Value", "Title"}, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/grill-with-docs] The Consider |
||
| Rows: itemRows, | ||
| })) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[/zoom-out] Minor inconsistency: the outer header (line 166) uses
fmt.Fprintln, but this inner section header usesfmt.Fprintfwith embedded\ncharacters.The leading blank line is important for visual separation, but expressing it as a bare
fmt.Fprintln(os.Stderr)followed byfmt.Fprintln(os.Stderr, console.FormatSectionHeader(...))would be more explicit and consistent with the rest of the file.💡 Suggested change
This matches the
fmt.Fprintlnpattern used at line 166 and makes blank-line intent explicit.