Consolidate duplicate formatNumber() implementations#2690
Merged
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Consolidate duplicate formatNumber implementations
Consolidate duplicate formatNumber() implementations
Oct 28, 2025
pelikhan
approved these changes
Oct 28, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR consolidates duplicate number formatting logic by replacing a simpler implementation with a more sophisticated one featuring adaptive precision based on magnitude (2 decimals for values under 10k/10M/10B, 1 decimal for 10-99k/10-99M/10-99B, and 0 decimals for 100k+/100M+/100B+).
Key changes:
- Enhanced
FormatNumber()inpkg/console/render.gowith better precision thresholds from thelogs.goimplementation - Removed 45-line duplicate
formatNumber()function frompkg/cli/logs.go - Updated 7 call sites across
logs.go,audit.go, andaudit_report.goto use the consolidated function - Adjusted test expectations to match the new precision behavior (e.g., "1.5k" → "1.50k")
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/console/render.go | Enhanced FormatNumber() with adaptive precision logic for K/M/B formatting |
| pkg/cli/logs.go | Removed duplicate formatNumber() and updated call sites to use console.FormatNumber() |
| pkg/cli/audit.go | Updated 3 call sites to use console.FormatNumber() |
| pkg/cli/audit_report.go | Updated 2 call sites to use console.FormatNumber() |
| pkg/console/render_test.go | Updated expected values and added comprehensive test coverage for FormatNumber() |
| pkg/console/render_formatting_test.go | Updated expected values to match new precision behavior |
| pkg/cli/logs_test.go | Updated test to use console.FormatNumber() |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
|
Agentic Changeset Generator triggered by this pull request. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two implementations of number formatting logic existed with 90% code overlap:
pkg/cli/logs.go:formatNumber()(41 lines, sophisticated precision thresholds)pkg/console/render.go:formatNumberForDisplay()(25 lines, simpler logic)Changes
console.FormatNumber(): Replaced simpler implementation with the sophisticated version featuring adaptive precision (2 decimals <10k, 1 decimal 10k-99k, 0 decimals 100k+)logs.go: Deleted 41-lineformatNumber()functionlogs.go,audit.go, andaudit_report.goto useconsole.FormatNumber()Example
Removes 45 lines of duplicate code while providing consistent, higher-quality number formatting across the codebase.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.