Consolidate duplicate formatNumber implementations#2683
Closed
Consolidate duplicate formatNumber implementations#2683
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Consolidate duplicate implementations of formatNumber()
Consolidate duplicate formatNumber implementations
Oct 28, 2025
Contributor
|
Agentic Changeset Generator triggered by this pull request. |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR consolidates duplicate number formatting logic by merging two similar implementations (~90% code overlap) into a single exported function. The consolidated version uses the more sophisticated 3-tier precision logic from logs.go (2 decimals for 1-9.99, 1 decimal for 10-99.9, 0 decimals for 100+) and is now available as console.FormatNumber() for consistent formatting across the application.
Key Changes:
- Exported
console.FormatNumber()with enhanced precision handling inpkg/console/render.go - Removed duplicate 41-line
formatNumber()function frompkg/cli/logs.go - Updated 7 call sites across multiple files to use the consolidated function
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pkg/console/render.go | Replaced formatNumberForDisplay() with exported FormatNumber() using sophisticated 3-tier precision logic |
| pkg/console/render_test.go | Updated test expectation to reflect new precision behavior (1.5k → 1.50k) |
| pkg/console/render_formatting_test.go | Updated multiple test cases to expect 2-decimal precision for numbers in 1-9.99k/M/B range |
| pkg/cli/logs.go | Removed duplicate formatNumber() function and updated call sites to use console.FormatNumber() |
| pkg/cli/logs_test.go | Added console package import and updated test 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() |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Collaborator
|
@copilot merge main |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Contributor
Author
Collaborator
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.
Consolidate formatNumber() duplicate implementations
This PR consolidates two similar number formatting functions into a single shared implementation.
Changes completed:
formatNumberForDisplay()inpkg/console/render.gowith the sophisticated version fromlogs.goFormatNumber()pkg/cli/logs.goto import and useconsole.FormatNumber()pkg/cli/audit.goto useconsole.FormatNumber()pkg/cli/audit_report.goto useconsole.FormatNumber()formatNumber()fromlogs.gopkg/cli/logs_test.goto use the exported functionpkg/console/render_formatting_test.gofor new precisionpkg/console/render_test.gofor new precisionpkg/console/render_test.goto match expectationKey differences between implementations:
logs.goversion: More sophisticated with 3-tier precision (2 decimals for 1-9.99, 1 decimal for 10-99.9, 0 decimals for 100+)render.goversion: Simpler with 2-tier precisionImpact:
pkg/console/render.goconsole.FormatNumber()and used in:pkg/cli/logs.go(2 call sites)pkg/cli/audit.go(3 call sites)pkg/cli/audit_report.go(2 call sites)pkg/console/render.go(for struct tag formatting)Merge with main:
timeutil.FormatDuration()from main instead of localformatDuration()console.FormatNumber()consolidation from this PRTesting:
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.