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

Allowing workflows in the root of workflows folder #20

Merged
merged 1 commit into from
Nov 9, 2024

Conversation

evgenyk
Copy link
Member

@evgenyk evgenyk commented Nov 9, 2024

Allowing workflows in the root of workflows folder

Checklist

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

Copy link

codecov bot commented Nov 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 53.25%. Comparing base (a48c2b3) to head (2890aee).
Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #20      +/-   ##
==========================================
+ Coverage   53.11%   53.25%   +0.13%     
==========================================
  Files          15       15              
  Lines        1702     1707       +5     
==========================================
+ Hits          904      909       +5     
  Misses        709      709              
  Partials       89       89              
Files with missing lines Coverage Δ
projectBundler/projectBundler.go 75.00% <100.00%> (+1.50%) ⬆️

Copy link

coderabbitai bot commented Nov 9, 2024

Walkthrough

The pull request introduces a refactoring of the workflow discovery logic in the KindeEnvironment struct by extracting the inline logic into a new function called maybeAddWorkflow. This change enhances code readability and maintainability. The error handling in the discoverKindeRoot method has been improved, including renaming the error variable for clarity. Additionally, the readProjectConfiguration method now handles file reading errors more explicitly. The test files have been updated to reflect the expected increase in workflows, and a new workflow configuration has been added.

Changes

File Change Summary
projectBundler/projectBundler.go - Introduced maybeAddWorkflow function for workflow discovery.
- Updated discover method to call maybeAddWorkflow.
- Improved error handling in discoverKindeRoot and readProjectConfiguration.
projectBundler/projectBundler_test.go - Updated Test_ProjectBunler to expect 3 workflows instead of 2.
runtime_test.go - Updated Test_ProjectBunlerE2E to expect 3 workflows and added assertion for the new workflow's errors.
testData/kindeSrc/environment/workflows/rootWorkflow.ts - Added new workflow configuration with ID 'tokenGen' and an asynchronous handle function.

Possibly related PRs

Suggested reviewers

  • davidkinde
  • rairaman
  • DanielRivers

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.

@evgenyk evgenyk marked this pull request as ready for review November 9, 2024 04:46
coderabbitai[bot]
coderabbitai bot previously requested changes Nov 9, 2024
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 (2)
testData/kindeSrc/environment/workflows/rootWorkflow.ts (1)

36-36: Fix typo in log object key.

The log object contains a typo in the key: "balh" should be "blah".

-    console.log('logging from action', {"balh": "blah"});
+    console.log('logging from action', {"blah": "blah"});
projectBundler/projectBundler.go (1)

68-68: LGTM! Consider improving error handling.

The refactoring to use maybeAddWorkflow for both root-level and subdirectory workflows is a good improvement that reduces code duplication. However, the error handling could be enhanced.

Consider handling potential errors from os.ReadDir instead of discarding them:

-    files, _ := os.ReadDir(workflowsPath)
+    files, err := os.ReadDir(workflowsPath)
+    if err != nil {
+        log.Warn().Err(err).Msgf("error reading directory: %s", workflowsPath)
+        continue
+    }

Also applies to: 71-72

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a48c2b3 and 2890aee.

📒 Files selected for processing (4)
  • projectBundler/projectBundler.go (1 hunks)
  • projectBundler/projectBundler_test.go (1 hunks)
  • runtime_test.go (1 hunks)
  • testData/kindeSrc/environment/workflows/rootWorkflow.ts (1 hunks)
🔇 Additional comments (4)
projectBundler/projectBundler_test.go (1)

27-27: LGTM! The assertion is updated to reflect the new workflow count.

The change correctly updates the expected number of workflows from 2 to 3, matching the new functionality that allows workflows in the root folder.

testData/kindeSrc/environment/workflows/rootWorkflow.ts (1)

1-16: Consider renaming the workflow ID to better reflect its purpose.

The workflow ID 'tokenGen' suggests token generation functionality, but the implementation appears to be more of a test/demo workflow that performs various operations. Consider a more appropriate name like 'demoWorkflow' or 'testWorkflow'.

Verify the security implications of resetting claims.

Both token services have resetClaims: true. This will clear all existing claims before setting new ones, which might not be the intended behavior in a production environment.

✅ Verification successful

Setting resetClaims: true is consistent with test workflow patterns

The usage of resetClaims: true in this workflow aligns with the established patterns in other test workflows (tokensWorkflow.ts and authWorkflow.ts). All test workflows consistently:

  • Set resetClaims: true for both ID and access tokens
  • Use similar test claim modifications via setCustomClaim

Since this is in a test data directory and follows the same testing patterns as other workflow files, the security concern about resetting claims is not applicable.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other workflows that modify token claims to understand the common patterns
rg -l "setCustomClaim|resetClaims" --type ts

Length of output: 231


Script:

#!/bin/bash
# Check the usage of resetClaims in other workflow files
rg "resetClaims" -C 5 --type ts

Length of output: 3405


Script:

#!/bin/bash
# Check for token claim modifications in other workflow files
rg "setCustomClaim" -C 5 --type ts

Length of output: 3536

projectBundler/projectBundler.go (1)

68-87: Verify workflow discovery behavior.

Let's verify that the workflow discovery works correctly for both root and nested workflows.

✅ Verification successful

Workflow discovery implementation is working as expected

The verification shows that:

  • The code correctly handles both root-level and nested workflow files (found in testData/kindeSrc/environment/workflows/)
  • Proper discovery of workflow files with .ts extension (e.g., rootWorkflow.ts, tokensWorkflow.ts, authWorkflow.ts)
  • The implementation correctly traverses directories and processes workflows in subdirectories (evTest/ and evTest2/)
  • File extension checking is implemented correctly in maybeAddWorkflow for both .ts and .js files
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify workflow discovery behavior

# Test 1: Check for workflow files in both root and subdirectories
echo "Checking workflow file locations..."
fd -e ts -e js . | grep -E 'workflow\.(ts|js)$'

# Test 2: Verify the structure matches the expected pattern
echo "Checking directory structure..."
tree environment/workflows 2>/dev/null || find environment/workflows -type f 2>/dev/null

# Test 3: Look for any potential duplicate workflow processing
echo "Checking for potential duplicate workflow definitions..."
rg -l "workflow\.(ts|js)'" | xargs -I {} dirname {} | sort | uniq -c | sort -nr

Length of output: 548


Script:

#!/bin/bash
# Let's try a different approach to verify workflow discovery

# Check for any workflow-related patterns in the codebase
echo "Searching for workflow patterns in the codebase..."
rg -l "workflow\.(ts|js)" --type ts --type js

# Look for actual workflow files
echo -e "\nListing all .ts and .js files:"
fd -e ts -e js .

# Check the actual implementation of workflow discovery
echo -e "\nChecking workflow discovery implementation:"
rg -A 5 -B 5 "maybeAddWorkflow" .

Length of output: 2053

runtime_test.go (1)

146-149: LGTM! Test updates correctly verify root workflow support.

The test assertions have been properly updated to verify the discovery of an additional workflow, maintaining consistency with the existing error checking pattern.

Let's verify the test data setup:

✅ Verification successful

The test data structure shows a rootWorkflow.ts file in the root of the workflows directory, along with other workflow files in subdirectories evTest and evTest2. This aligns with the test's expectation of 3 workflows. Let me verify the content of these files to ensure they are valid workflow files.


Test assertions correctly match the test data structure

The test data setup is valid and properly structured:

  • Root workflow (rootWorkflow.ts) is a complete workflow file with proper exports and handler function
  • The test's expectation of 3 workflows aligns with the directory structure:
    1. Workflows in evTest/ directory
    2. Workflows in evTest2/ directory
    3. Root workflow in the workflows directory root
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify test data structure includes a workflow in the root folder
# Expected: Find workflow files in both subdirectories and root of workflows folder

echo "Checking workflow files structure:"
fd -t f . testData/kindeSrc/environment/workflows

Length of output: 428


Script:

#!/bin/bash
# Check content of rootWorkflow.ts and a sample workflow from subdirectory
echo "=== Root Workflow Content ==="
cat testData/kindeSrc/environment/workflows/rootWorkflow.ts

echo -e "\n=== Sample Subdirectory Workflow Content ==="
cat testData/kindeSrc/environment/workflows/evTest/hello.ts

Length of output: 1551

projectBundler/projectBundler_test.go Show resolved Hide resolved
projectBundler/projectBundler.go Show resolved Hide resolved
@evgenyk evgenyk dismissed coderabbitai[bot]’s stale review November 9, 2024 09:05

this is internal method, which modifies the state via side-effect, no need to return

@evgenyk evgenyk merged commit ff9e8cb into main Nov 9, 2024
4 checks passed
@evgenyk evgenyk deleted the ev/workflows-no-subfolder-support branch November 9, 2024 09:05
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