Skip to content
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

Merged
merged 4 commits into from
Nov 18, 2024
Merged

Pages routing hooks #26

merged 4 commits into from
Nov 18, 2024

Conversation

evgenyk
Copy link
Member

@evgenyk evgenyk commented Nov 18, 2024

Adding hooks to support routing

Checklist

🛟 If you need help, consider asking for advice over in the Kinde community.

Copy link

coderabbitai bot commented Nov 18, 2024

Walkthrough

The 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 ProjectSettings to projectSettings, the addition of a new function GetProjectConfiguration, and the introduction of a callback mechanism in the DiscoveryOptions struct. In the test file, a new field for routing information is added, and existing callback functions are updated to utilize the new configuration retrieval method.

Changes

File Change Summary
projectBundler/projectBundler.go - Renamed ProjectSettings to projectSettings and ProjectSettingsContextKey to projectSettingsContextKey.
- Added function GetProjectConfiguration(ctx context.Context) *ProjectConfiguration.
- Updated DiscoveryOptions struct to include OnRootDiscovered field.
- Updated Discover method to use the new context key and invoke the callback.
projectBundler/projectBundler_test.go - Added Route field to pageSettings struct.
- Introduced OnRootDiscovered callback for testing.
- Updated logic in OnWorkflowDiscovered and OnPageDiscovered to use GetProjectConfiguration.
- Enhanced assertions to validate routing information.
workflowBundler/workflowBundler.go - Added BundlingOptions field to BundledContent struct.
- Updated Bundle method to populate BundlingOptions in BundledContent.

Possibly related PRs

Suggested reviewers

  • davidkinde
  • DanielRivers
  • rairaman

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

📥 Commits

Reviewing files that changed from the base of the PR and between a0f0db5 and b681a50.


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Nov 18, 2024

Codecov Report

Attention: Patch coverage is 92.85714% with 1 line in your changes missing coverage. Please review.

Project coverage is 54.18%. Comparing base (83b82c7) to head (b681a50).
Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
projectBundler/projectBundler.go 90.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            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              
Files with missing lines Coverage Δ
workflowBundler/workflowBundler.go 82.75% <100.00%> (+0.14%) ⬆️
projectBundler/projectBundler.go 76.11% <90.00%> (+0.72%) ⬆️

Copy link

@coderabbitai coderabbitai bot left a 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 callback

While 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 assertions

The 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 output

While adding BundlingOptions to BundledContent provides transparency, consider:

  1. Security: Ensure no sensitive configuration data is exposed
  2. 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 BundlingOptions

The 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

📥 Commits

Reviewing files that changed from the base of the PR and between 710beb5 and a0f0db5.

📒 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 how BundlingOptions is used to generate route paths in OnPageDiscovered 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:

  1. Update the context with project configuration
  2. Guard the callback invocation with a nil check
  3. 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

projectBundler/projectBundler_test.go Show resolved Hide resolved
projectBundler/projectBundler_test.go Outdated Show resolved Hide resolved
projectBundler/projectBundler.go Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a 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 extensibility

The 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 callback

The 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 fields

The 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

📥 Commits

Reviewing files that changed from the base of the PR and between a0f0db5 and b681a50.

📒 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

projectBundler/projectBundler.go Show resolved Hide resolved
projectBundler/projectBundler.go Show resolved Hide resolved
@evgenyk evgenyk merged commit 8f5c201 into main Nov 18, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants