-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
make markdown filename shorter #5899
Conversation
WalkthroughThe changes in the pull request focus on modifying the Changes
Assessment against linked issues
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (1)
pkg/reporting/exporters/markdown/markdown.go (1)
Line range hint
143-147
: Consider full path length for Windows compatibilityThe current implementation truncates filenames at 256 characters, but Windows has a 260-character limit for the full path. The sanitizeFilename function should consider:
- The base directory path length
- Any subdirectory path length (when using SortMode)
- The filename itself
Consider this enhancement:
-func sanitizeFilename(filename string) string { +func sanitizeFilename(filename string, basePath string) string { + // Windows MAX_PATH is 260 chars + const maxWindowsPath = 260 + + // Calculate available space for filename + baseLen := len(basePath) + 1 // +1 for path separator + maxFilenameLen := maxWindowsPath - baseLen + if len(filename) > 256 { - filename = filename[0:255] + filename = filename[0:maxFilenameLen] } return stringsutil.ReplaceAll(filename, "_", "?", "/", ">", "|", ":", ";", "*", "<", "\"", "'", " ") }This would require updating the Export method to pass the full base path:
- filename := sanitizeFilename(filenameBuilder.String()) + fullPath := filepath.Join(exporter.directory, subdirectory) + filename := sanitizeFilename(filenameBuilder.String(), fullPath)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
pkg/reporting/exporters/markdown/markdown.go
(2 hunks)
🔇 Additional comments (2)
pkg/reporting/exporters/markdown/markdown.go (2)
9-9
: LGTM: Good choice for generating unique identifiers
The addition of the uuid package is appropriate for ensuring unique filenames.
Line range hint 1-147
: Verify existing usage patterns and test coverage
Let's verify the impact of these changes on existing code and tests.
✅ Verification successful
The changes appear safe to proceed
Based on the verification results:
- The markdown exporter is only used in
pkg/reporting/reporting.go
through theNew()
function - The test coverage focuses on markdown utilities (table creation, headers) rather than the export functionality
- The changes introduce better organization through subdirectories based on severity/host/template without breaking the existing file generation logic
- The filename sanitization remains consistent with the existing implementation
The modifications enhance the organization of exported files while maintaining backward compatibility with the existing interface and usage patterns.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check for existing usage patterns and test coverage
# Look for direct usage of the Matched field in markdown generation
rg -l "event\.Matched.*\.md" --type go
# Check for existing test cases
rg -l "TestExport.*markdown" --type go
# Look for potential template ID patterns to understand typical filename lengths
ast-grep --pattern 'TemplateID: "$_"'
Length of output: 121
Script:
#!/bin/bash
# Let's try a different approach to verify the changes
# Check for existing test files for markdown exporter
fd "markdown.*test.*\.go$"
# Look for any markdown-related test files in the reporting directory
fd ".*test.*\.go$" pkg/reporting
# Check for usage of markdown exporter in the codebase
rg -A 3 "markdown\.New\(" --type go
# Look for any existing markdown files to understand the current structure
fd "\.md$"
Length of output: 1316
Script:
#!/bin/bash
# Let's examine the test file and current implementation
# Check the markdown utils test content
cat pkg/reporting/exporters/markdown/util/markdown_utils_test.go
# Look for any existing markdown exporter tests in the reporting tests
rg -A 5 "markdown.*Export" pkg/reporting/exporters/markdown/util/markdown_utils_test.go
# Check the reporting implementation for markdown usage patterns
rg -A 5 "markdown\.Export" pkg/reporting/reporting.go
Length of output: 2029
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.
@dogancanbakir we track / fix failing test as follow up issue, looks like it's being failed in all other PRs as well.
Proposed changes
Closes #5769
Checklist
Summary by CodeRabbit
New Features
Bug Fixes
Documentation