Skip to content

fix bug in depends_on traversal #1932

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

Merged
merged 1 commit into from
Apr 2, 2025
Merged

Conversation

motatoes
Copy link
Contributor

@motatoes motatoes commented Apr 2, 2025

Our BFS traversal during depends on was returning "true" as a default value in the algorithm and when this happens the traversal of BFS stops, this caused some nodes to be never explored. Bug description:

In a digger.yml as follows:

projects:
  - name: core
    dir: ./core
  - name: platform
    dir: ./platform
    depends_on: ["core"]
    # include_patterns: ["./core/**"]
  - name: services
    dir: ./services
    depends_on: ["platform"]
    # include_patterns: ["core/**", "platform/**"]

workflows:
  default:
    plan:
      steps:
        - init
        - plan
        - run: echo "running the custom command!"

Which has the following dependency graph:

image

creating a PR which changes "platform" causes "no projects impacted". Turns out we are not properly traversing all nodes since we return true in the BFS function and terminate early

Copy link
Contributor

coderabbitai bot commented Apr 2, 2025

Walkthrough

The change updates the return value in the FindAllProjectsDependantOnImpactedProjects function within the dependency graph traversal. Previously, the function returned true to terminate the traversal upon a condition. With the modification, it now returns false, allowing the breadth-first search (BFS) algorithm to continue traversing subsequent nodes. This alteration impacts the control flow during the dependency check and may lead to a broader collection of dependent projects.

Changes

File Summary
libs/ci/.../events.go Changed return value in FindAllProjectsDependantOnImpactedProjects from true to false to enable continuous BFS traversal.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as "Caller"
    participant Func as "FindAllProjectsDependantOnImpactedProjects"
    participant BFS as "BFS Traversal"

    Caller->>Func: Invoke function
    Func->>BFS: Start dependency traversal
    BFS->>Func: Evaluate current node dependency
    alt Node impacts project?
        Func-->>BFS: Return false (continue traversal)
    else No impact
        Func-->>BFS: Process normally
    end
    BFS->>Caller: Return collected dependent projects
Loading

Poem

I'm Hop, a coding rabbit with glee,
Hopping through code, as happy as can be.
A change from true to false paved the way,
Letting BFS explore more each day.
Nodes keep dancing in a joyful spree,
In this revised graph, there's magic to see!
Bouncy code and bright prospects — hooray!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4c9cfb6 and 0548545.

📒 Files selected for processing (1)
  • libs/ci/generic/events.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build
🔇 Additional comments (1)
libs/ci/generic/events.go (1)

90-90:

✅ Verification successful

Improved dependency traversal behavior.

Changing the return value from true to false in this case significantly improves the BFS traversal behavior. Previously, the traversal would terminate prematurely for nodes that weren't directly impacted or didn't have impacted parents, potentially missing transitive dependencies. With this change, the BFS will continue exploring all paths through the dependency graph, ensuring a more thorough collection of dependent projects.

This change aligns with the function's purpose of finding all projects dependent on impacted projects, not just direct dependencies.


🏁 Script executed:

#!/bin/bash
# Description: Verify that the modified function properly traverses all dependencies

# Find any test files that might test this function
rg -l "FindAllProjectsDependantOnImpactedProjects" --type go

# Look for any instances where this function is used
rg -A 3 -B 3 "FindAllProjectsDependantOnImpactedProjects" --type go

Length of output: 3367


Improved Dependency Traversal Behavior Approved:
The change in libs/ci/generic/events.go—returning false instead of true at line 90—successfully prevents premature termination of the BFS, ensuring all dependency paths (including transitive ones) are examined. Verification through existing tests and usages in libs/ci/github/github.go, libs/ci/gitlab/webhooks.go, and libs/ci/github/github_test.go confirms that the revised behavior aligns with the function’s intent to capture all dependent projects.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

The PR modifies the dependency graph traversal in /libs/ci/generic/events.go by changing the BFS callback's return value from true to false when a parent's impacted, which affects the impacted projects detection flow.

• Updated BFS callback in /libs/ci/generic/events.go now permits deeper traversal on impacted parents.
• Verify that cyclic dependencies are handled correctly to avoid infinite loops.
• Ensure tests in /libs/ci/github/github_test.go and /libs/ci/gitlab/gitlab_test.go cover all edge cases post-change.

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

@motatoes motatoes changed the title improvements for depends_on traversal fix bug in depends_on traversal Apr 2, 2025
@motatoes motatoes merged commit 96c9822 into develop Apr 2, 2025
12 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.

1 participant