Skip to content

Fix no owners for subfolders#639

Merged
myakove merged 4 commits intomainfrom
fix-owners-sub-folders
Dec 12, 2024
Merged

Fix no owners for subfolders#639
myakove merged 4 commits intomainfrom
fix-owners-sub-folders

Conversation

@myakove
Copy link
Copy Markdown
Collaborator

@myakove myakove commented Dec 12, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new pytest fixture for testing GitHub webhook processing.
    • Added classes for handling file trees and repository simulation in tests.
    • Implemented tests for evaluating pull request size thresholds based on additions and deletions.
  • Bug Fixes

    • Enhanced logic for processing ownership data in GitHub webhook handling.
  • Refactor

    • Updated type annotations for improved data structure representation.
    • Removed unnecessary classes from test files to streamline structure.
    • Adjusted coverage reporting settings for stricter requirements.
  • Documentation

    • Configuration updates for pytest and coverage targets documented.

@myakove-bot
Copy link
Copy Markdown
Collaborator

Report bugs in Issues

The following are automatically added:

  • Add reviewers from OWNER file (in the root of the repository) under reviewers section.
  • Set PR size label.
  • New issue is created for the PR. (Closed when PR is merged/closed)
  • Run pre-commit if .pre-commit-config.yaml exists in the repo.

Available user actions:

  • To mark PR as WIP comment /wip to the PR, To remove it from the PR comment /wip cancel to the PR.
  • To block merging of PR comment /hold, To un-block merging of PR comment /hold cancel.
  • To mark PR as verified comment /verified to the PR, to un-verify comment /verified cancel to the PR.
    verified label removed on each new commit push.
  • To cherry pick a merged PR comment /cherry-pick <target branch to cherry-pick to> in the PR.
    • Multiple target branches can be cherry-picked, separated by spaces. (/cherry-pick branch1 branch2)
    • Cherry-pick will be started when PR is merged
  • To build and push container image command /build-and-push-container in the PR (tag will be the PR number).
    • You can add extra args to the Podman build command
      • Example: /build-and-push-container --build-arg OPENSHIFT_PYTHON_WRAPPER_COMMIT=<commit_hash>
  • To add a label by comment use /<label name>, to remove, use /<label name> cancel
  • To assign reviewers based on OWNERS file use /assign-reviewers
  • To check if PR can be merged use /check-can-merge
Supported /retest check runs
  • /retest tox: Retest tox
  • /retest build-container: Retest build-container
  • /retest python-module-install: Retest python-module-install
  • /retest pre-commit: Retest pre-commit
  • /retest all: Retest all
Supported labels
  • hold
  • verified
  • wip
  • lgtm

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Dec 12, 2024

Walkthrough

The pull request introduces several changes across multiple files. The pytest.ini configuration is updated to include a new debugger option and modifies the coverage target. In github_api.py, type annotations are refined, and logic adjustments enhance the handling of owner data. A new conftest.py file is added to support testing with classes and a pytest fixture. The test file test_pull_request_owners.py is streamlined by removing unnecessary classes and focusing on a new Repository class. Lastly, a new test file test_pull_request_size.py is created to evaluate pull request size thresholds.

Changes

File Path Change Summary
pytest.ini Added --pdbcls=IPython.terminal.debugger:TerminalPdb and updated coverage target from --cov=github_webhook_server to --cov=webhook_server_container.
webhook_server_container/libs/github_api.py Updated type annotations for changed_folder_match from list[str] to list[Path] and for require_root_approvers from bool to `bool
webhook_server_container/tests/conftest.py Introduced classes Tree, ContentFile, and Repository, along with a pytest fixture process_github_webhook to mock dependencies for testing GitHub webhook processing.
webhook_server_container/tests/test_pull_request_owners.py Removed classes Label, Tree, ContentFile, and PullRequest. Added Repository class to streamline tests, updating test functions to reflect changes and enhance coverage for owner checks in nested directories.
webhook_server_container/tests/test_pull_request_size.py Added classes Label and PullRequest, along with a parameterized test function test_get_size_thresholds to evaluate pull request size thresholds based on additions and deletions.
pyproject.toml Reformatted coverage settings, increased fail_under threshold from 0 to 30, and made several formatting adjustments for consistency across various sections.

Suggested labels

size/XXL, commented-myakove, commented-coderabbitai[bot]

Suggested reviewers

  • rnetser
  • dbasunag

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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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.

@myakove
Copy link
Copy Markdown
Collaborator Author

myakove commented Dec 12, 2024

/verified

Copy link
Copy Markdown

@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)
webhook_server_container/tests/conftest.py (1)

47-93: Consider removing unused conditional branches in Repository.get_contents

In the get_contents method, the conditional branch for path == "folder" returns an empty ContentFile. If this case is not required for your tests, consider removing it to simplify the method.

Apply this diff if the branch is unnecessary:

         elif path == "folder":
-            return ContentFile(yaml.dump({}))
webhook_server_container/libs/github_api.py (1)

2080-2087: Consider improving the readability of the fallback logic

The nested else block could be refactored for better readability.

Consider this alternative structure:

-        else:
-            for _folder in changed_folders:
-                for _changed_path in changed_folder_match:
-                    if _folder == _changed_path or _changed_path in _folder.parents:
-                        continue
-                    else:
-                        data["."] = self.all_approvers_and_reviewers.get(".", {})
-                        break
+        else:
+            # Check if any changed folder is not covered by OWNERS files
+            for _folder in changed_folders:
+                if not any(_folder == path or path in _folder.parents 
+                          for path in changed_folder_match):
+                    data["."] = self.all_approvers_and_reviewers.get(".", {})
+                    break
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1d70f8a and 8686590.

📒 Files selected for processing (5)
  • pytest.ini (1 hunks)
  • webhook_server_container/libs/github_api.py (1 hunks)
  • webhook_server_container/tests/conftest.py (1 hunks)
  • webhook_server_container/tests/test_pull_request_owners.py (2 hunks)
  • webhook_server_container/tests/test_pull_request_size.py (1 hunks)
🔇 Additional comments (6)
webhook_server_container/tests/test_pull_request_owners.py (1)

4-5: Good use of importing shared classes for reuse

Importing ContentFile and Tree from conftest promotes code reuse and keeps the test code DRY (Don't Repeat Yourself).

pytest.ini (2)

4-4: Update coverage target to match the package structure

Updating the coverage target to --cov=webhook_server_container aligns with the current package name and ensures accurate coverage reporting.


3-3: Verify that IPython is included in development dependencies

Since you've specified --pdbcls=IPython.terminal.debugger:TerminalPdb, ensure that IPython is included in your development dependencies to avoid runtime errors when invoking the debugger.

Run the following script to check if IPython is listed in your dependencies:

✅ Verification successful

IPython is properly included in development dependencies

The verification confirms that IPython (version >=8.12.3) is correctly listed in the project's development dependencies within pyproject.toml.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for IPython in development requirements.

# Search for 'ipython' in requirements files.
rg -i 'ipython' requirements/

Length of output: 83


Script:

#!/bin/bash
# Let's check for any requirements or dependency files in the repository
fd -e txt -e ini -e toml -e cfg -e in "requirements|dependencies|pyproject|setup|poetry"

# Then let's check for IPython in any Python-related dependency files
rg -i "ipython" -g "requirements*" -g "setup*" -g "pyproject*" -g "poetry*" -g "Pipfile*"

Length of output: 268

webhook_server_container/tests/conftest.py (1)

110-112: 🛠️ Refactor suggestion

Ensure correct assignment of changed_files in the fixture

The assignment of changed_files may not handle input parameters with extra nesting appropriately. Adjust the fixture to unpack request.param correctly.

Apply this diff to make the assignment more robust:

     if hasattr(request, "param") and request.param:
-        process_github_webhook.changed_files = request.param[0]
+        process_github_webhook.changed_files = request.param
     else:
         process_github_webhook.changed_files = ALL_CHANGED_FILES

This change allows the fixture to accept parameters without unnecessary nesting.

Likely invalid or redundant comment.

webhook_server_container/libs/github_api.py (2)

2060-2060: LGTM: Type annotation improvements

The changes to type annotations are good improvements:

  • Using Path objects instead of strings provides better path manipulation capabilities
  • Making require_root_approvers nullable (bool | None) allows for proper representation of an undetermined state

Also applies to: 2062-2062


2065-2066: LGTM: Improved owner data processing logic

The changes enhance the owner data processing by:

  • Skipping unnecessary processing for root directory
  • Using proper path comparison with Path objects
  • Adding comprehensive handling of root approvers requirement

Also applies to: 2071-2071, 2073-2074, 2077-2077

Comment thread webhook_server_container/tests/test_pull_request_owners.py
Comment thread webhook_server_container/tests/test_pull_request_owners.py
Comment thread webhook_server_container/tests/test_pull_request_size.py Outdated
@myakove
Copy link
Copy Markdown
Collaborator Author

myakove commented Dec 12, 2024

/verified

@myakove myakove enabled auto-merge (squash) December 12, 2024 20:38
@myakove myakove disabled auto-merge December 12, 2024 20:40
@myakove
Copy link
Copy Markdown
Collaborator Author

myakove commented Dec 12, 2024

/verified

Copy link
Copy Markdown

@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: 0

🧹 Outside diff range and nitpick comments (1)
pyproject.toml (1)

70-70: Remove leading whitespace in email address

There's an unnecessary leading space in the email address.

-email = " myakove@gmail.com"
+email = "myakove@gmail.com"
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0a680b3 and 34325d6.

📒 Files selected for processing (1)
  • pyproject.toml (5 hunks)
🔇 Additional comments (4)
pyproject.toml (4)

17-18: LGTM: Ruff formatting configuration

The exclude patterns for Ruff formatting are appropriate and follow common practices.


30-30: Verify package name changes across the codebase

The package name has been changed to "webhook_server_container". This change might require corresponding updates in import statements and package references throughout the codebase.

✅ Verification successful

Let me gather more information about the package structure and usage to make a conclusive verification.


Package name change is consistent with the codebase

The package name change to "webhook_server_container" in pyproject.toml is correctly reflected throughout the codebase:

  • The package directory structure exists as webhook_server_container/
  • All imports in Python files correctly reference webhook_server_container
  • No references to old package names were found
  • The wheel build configuration in pyproject.toml correctly specifies the package
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential mismatches in package references

# Search for old package references
echo "Searching for potential old package references..."
rg -l "github_webhook_server" || echo "No old package references found"

# Check import statements
echo "Checking import statements..."
ast-grep --pattern 'import webhook_server_container' || echo "No direct imports found"
ast-grep --pattern 'from webhook_server_container import' || echo "No from imports found"

Length of output: 395


Script:

#!/bin/bash
# Check the actual package structure and imports
echo "Checking package structure:"
fd -t d webhook_server_container

echo -e "\nChecking Python files for any imports:"
fd -e py --exec rg -l "webhook_server_container"

echo -e "\nChecking setup files and configurations:"
fd "setup.py|setup.cfg|pyproject.toml" --exec cat {}

Length of output: 2796


Line range hint 47-65: Verify compatibility of dependency versions

Several dependencies are pinned to specific versions. While this is good for reproducibility, we should:

  1. Verify that these versions are compatible with each other
  2. Check for any known security vulnerabilities
  3. Consider if any version constraints could be relaxed to allow minor updates
✅ Verification successful

Dependencies are secure and up-to-date

Based on the vulnerability checks performed on key dependencies:

  • FastAPI (>=0.115.0): Clear of known vulnerabilities (latest advisory affects <=0.109.0)
  • PyGithub (>=2.4.0): No known vulnerabilities
  • JIRA (>=3.8.0): No known vulnerabilities
  • uvicorn (>=0.31.0): Clear of known vulnerabilities (latest advisory affects <0.11.7)
  • requests (>=2.32.3): Clear of known vulnerabilities (latest advisory affects <2.32.0)

The specified version constraints are appropriate and secure. All dependencies are pinned to versions that are:

  • Above any known vulnerable versions
  • Compatible with modern Python environments
  • Recent enough to include important security fixes
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential dependency issues

# Check for known vulnerabilities in key dependencies
echo "Checking FastAPI vulnerability advisories..."
gh api graphql -f query='
{
  securityVulnerabilities(first: 5, ecosystem: PIP, package: "fastapi") {
    nodes {
      advisory {
        summary
        severity
        publishedAt
      }
      vulnerableVersionRange
    }
  }
}'

echo "Checking PyGithub vulnerability advisories..."
gh api graphql -f query='
{
  securityVulnerabilities(first: 5, ecosystem: PIP, package: "pygithub") {
    nodes {
      advisory {
        summary
        severity
        publishedAt
      }
      vulnerableVersionRange
    }
  }
}'

Length of output: 1107


Script:

#!/bin/bash
# Let's check for any potential conflicts or issues in other key dependencies

# Check for JIRA vulnerabilities
echo "Checking JIRA vulnerability advisories..."
gh api graphql -f query='
{
  securityVulnerabilities(first: 5, ecosystem: PIP, package: "jira") {
    nodes {
      advisory {
        summary
        severity
        publishedAt
      }
      vulnerableVersionRange
    }
  }
}'

# Check for uvicorn vulnerabilities
echo "Checking uvicorn vulnerability advisories..."
gh api graphql -f query='
{
  securityVulnerabilities(first: 5, ecosystem: PIP, package: "uvicorn") {
    nodes {
      advisory {
        summary
        severity
        publishedAt
      }
      vulnerableVersionRange
    }
  }
}'

# Check for requests vulnerabilities
echo "Checking requests vulnerability advisories..."
gh api graphql -f query='
{
  securityVulnerabilities(first: 5, ecosystem: PIP, package: "requests") {
    nodes {
      advisory {
        summary
        severity
        publishedAt
      }
      vulnerableVersionRange
    }
  }
}'

Length of output: 2396


5-5: Verify current test coverage meets new threshold

The coverage threshold has been significantly increased from 0% to 30%. While this is a good practice to enforce better test coverage, we should verify that the current codebase meets this requirement to avoid breaking the CI/CD pipeline.

@myakove myakove deleted the fix-owners-sub-folders branch December 12, 2024 20:48
Comment thread webhook_server_container/tests/test_pull_request_size.py
@myakove-bot
Copy link
Copy Markdown
Collaborator

New container for quay.io/myakove/github-webhook-server:latest published

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants