-
Notifications
You must be signed in to change notification settings - Fork 0
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
Pages routing hooks #26
Conversation
WalkthroughThe pull request introduces several changes across multiple files, primarily focusing on renaming types and constants for consistency, enhancing functionality related to project configurations, and improving test coverage. Key updates include the renaming of Changes
Possibly related PRs
Suggested reviewers
Warning Rate limit exceeded@evgenyk has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 24 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 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 (
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #26 +/- ##
==========================================
+ Coverage 54.00% 54.18% +0.17%
==========================================
Files 15 15
Lines 1759 1768 +9
==========================================
+ Hits 950 958 +8
- Misses 717 718 +1
Partials 92 92
|
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: 3
🧹 Outside diff range and nitpick comments (4)
projectBundler/projectBundler_test.go (2)
38-41
: Enhance configuration validation in workflow callbackWhile checking for non-nil configuration is good, consider validating the expected configuration properties to ensure the correct context is being passed.
Consider adding more specific assertions:
OnWorkflowDiscovered: func(ctx context.Context, bundle *bundler.BundlerResult[workflowSettings]) { onWorkflowDiscoveredCalled++ settings := GetProjectConfiguration(ctx) assert.NotNil(settings) + assert.Equal(t, "kindeSrc", settings.RootDir, "Project root directory should match") + assert.NotEmpty(t, settings.AbsLocation, "Absolute location should be set") },
71-73
: Enhance route validation in assertionsThe current assertions only check if routes are non-empty. Consider adding more specific checks to validate the route format and expected values.
Consider adding these assertions:
-assert.NotEmpty(kindeProject.Environment.Pages[0].Bundle.Content.Settings.Other.Route) +assert.Regexp(t, "^/[a-zA-Z0-9/-]+$", kindeProject.Environment.Pages[0].Bundle.Content.Settings.Other.Route, "Route should be properly formatted") -assert.NotEmpty(kindeProject.Environment.Pages[1].Bundle.Content.Settings.Other.Route) +assert.Regexp(t, "^/[a-zA-Z0-9/-]+$", kindeProject.Environment.Pages[1].Bundle.Content.Settings.Other.Route, "Route should be properly formatted")workflowBundler/workflowBundler.go (2)
25-28
: Consider the implications of exposing BundlingOptions in the outputWhile adding BundlingOptions to BundledContent provides transparency, consider:
- Security: Ensure no sensitive configuration data is exposed
- Performance: The bundling_options field might increase payload size unnecessarily if it contains data not needed by consumers
Consider either:
- Adding a filter to exclude sensitive/unnecessary fields during JSON marshaling
- Creating a separate BundlingOptionsView type with only the required fields
113-116
: Consider memory efficiency for large BundlingOptionsThe direct assignment of
b.bundleOptions
might create unnecessary copies for large option sets. Consider using a pointer to BundlerOptions if the options contain substantial data.type BundledContent[TSettings any] struct { Source []byte `json:"source"` BundleHash string `json:"hash"` Settings WorkflowSettings[TSettings] `json:"settings"` - BundlingOptions BundlerOptions[TSettings] `json:"bundling_options"` + BundlingOptions *BundlerOptions[TSettings] `json:"bundling_options"` }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
projectBundler/projectBundler.go
(4 hunks)projectBundler/projectBundler_test.go
(3 hunks)workflowBundler/workflowBundler.go
(2 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
projectBundler/projectBundler.go
[warning] 73-73: projectBundler/projectBundler.go#L73
Added line #L73 was not covered by tests
🔇 Additional comments (5)
projectBundler/projectBundler_test.go (1)
5-6
: LGTM: Import and struct field additions are appropriate
The new fmt import and Route field in pageSettings are well-structured and necessary for the routing functionality.
Also applies to: 25-25
workflowBundler/workflowBundler.go (1)
25-28
: Verify relationship with routing hooks
The changes focus on exposing bundling options, but the PR description mentions routing hooks. Could you clarify how these changes support the routing functionality described in the PR objectives?
Also applies to: 113-116
✅ Verification successful
Let me gather more context about the PR changes and routing functionality.
Based on the test file content, I can now generate the final response as I see the connection between bundling options and routing functionality.
Changes align with routing functionality through page discovery
The bundling options are used during page discovery to set up routing. Specifically, in the OnPageDiscovered
hook, the bundling options' WorkingFolder
and EntryPoints
are used to construct the route path for each page. The struct changes are necessary to support this routing mechanism.
projectBundler/projectBundler_test.go
: Shows howBundlingOptions
is used to generate route paths inOnPageDiscovered
hook:
relPath, _ := filepath.Rel(pagesPath, path.Join(bundle.Content.BundlingOptions.WorkingFolder, entryPoint))
cleanedPath := path.Clean(fmt.Sprintf("/%v", relPath))
bundle.Content.Settings.Other.Route = cleanedPath
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for routing-related code to understand the connection
rg -l 'rout(e|ing)' --type go
# Look for hooks implementation
ast-grep --pattern 'type $_ struct {
$$$
OnRoute $_
$$$
}'
Length of output: 136
Script:
#!/bin/bash
# Check the PR description and related files
gh pr view
# Look at the test file that mentions routing
cat projectBundler/projectBundler_test.go
# Search for any hook-related code
rg -l 'hook|Hook' --type go
# Look for bundling options usage
ast-grep --pattern 'BundlerOptions['
Length of output: 2747
projectBundler/projectBundler.go (3)
55-55
: LGTM: Well-designed callback addition
The new OnRootDiscovered
callback follows the established pattern of discovery hooks and aligns with the PR's objective of adding routing functionality. The function signature is consistent with existing callbacks.
154-158
: LGTM: Well-implemented context update and callback
The changes correctly:
- Update the context with project configuration
- Guard the callback invocation with a nil check
- Maintain proper ordering of operations
18-18
: Verify impact of unexported identifiers
The renaming of ProjectSettings
to projectSettings
and ProjectSettingsContextKey
to projectSettingsContextKey
makes these identifiers unexported. While this aligns with Go's convention of unexported implementation details, it's a breaking change that could affect dependent packages.
Also applies to: 22-22
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: 2
🧹 Outside diff range and nitpick comments (3)
projectBundler/projectBundler.go (3)
79-80
: Consider using type switch for better extensibilityThe direct type assertion might be limiting if we need to support multiple configuration types in the future.
Consider using a type switch for better extensibility:
-if val, ok := ctx.Value(projectSettingsContextKey).(ProjectConfiguration); ok { +switch val := ctx.Value(projectSettingsContextKey).(type) { +case ProjectConfiguration: return &val +default: + return nil }
58-64
: Add documentation for OnRootDiscovered callbackThe new
OnRootDiscovered
field lacks documentation explaining its purpose and when it's called.Add field documentation:
// DiscoveryOptions is the struct that holds the options for the project discovery. DiscoveryOptions[TWorkflowSettings, TPageSettings any] struct { StartFolder string + // OnRootDiscovered is called when the project root configuration is discovered + // It receives the context and the discovered project configuration OnRootDiscovered func(ctx context.Context, bundle ProjectConfiguration) OnWorkflowDiscovered func(ctx context.Context, bundle *bundler.BundlerResult[TWorkflowSettings]) OnPageDiscovered func(ctx context.Context, bundle *bundler.BundlerResult[TPageSettings]) }
Line range hint
204-209
: Add validation for required DiscoveryOptions fieldsThe constructor should validate that required fields like
StartFolder
are provided.Consider adding validation:
func NewProjectBundler[TWorkflowSettings, TPageSettings any](discoveryOptions DiscoveryOptions[TWorkflowSettings, TPageSettings]) ProjectBundler[TWorkflowSettings, TPageSettings] { + if discoveryOptions.StartFolder == "" { + panic("StartFolder is required in DiscoveryOptions") + } return &projectBundler[TWorkflowSettings, TPageSettings]{ options: discoveryOptions, } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
projectBundler/projectBundler.go
(5 hunks)projectBundler/projectBundler_test.go
(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- projectBundler/projectBundler_test.go
🧰 Additional context used
🪛 GitHub Check: codecov/patch
projectBundler/projectBundler.go
[warning] 82-82: projectBundler/projectBundler.go#L82
Added line #L82 was not covered by tests
Adding hooks to support routing
Checklist
🛟 If you need help, consider asking for advice over in the Kinde community.