Skip to content

feat: read repo config from repository config file#668

Closed
myakove wants to merge 3 commits intomainfrom
repo-config-from-repo
Closed

feat: read repo config from repository config file#668
myakove wants to merge 3 commits intomainfrom
repo-config-from-repo

Conversation

@myakove
Copy link
Copy Markdown
Collaborator

@myakove myakove commented Feb 25, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a new exception class to handle uninitialized repositories, improving error management.
  • Bug Fixes

    • Enhanced error handling during webhook event processing to manage scenarios where expected data is missing.
  • Refactor

    • Streamlined internal type annotations to boost code clarity and consistency.
    • Updated function to support an additional optional dictionary for enhanced value retrieval.
  • Chores

    • Improved logging functionality to capture detailed error messages during webhook processing.

@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
  • to assign reviewer to PR use /assign-reviewer @<reviewer>
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 Feb 25, 2025

Walkthrough

The pull request updates type annotations in the github_api.py, helpers.py, and github_repository_settings.py files by replacing capitalized types (Dict, List, Tuple, Optional) with their lowercase equivalents (dict, list, tuple). Additionally, it introduces a new exception class, RepositoryNotInitializedError, enhances error handling in the process_webhook function, and modifies the get_value_from_dicts function to accept an optional third dictionary parameter. The changes improve clarity and modernize the codebase without altering existing functionality.

Changes

File Changes Summary
webhook_server_container/.../github_api.py - Updated type annotations from Dict to dict across classes and methods.
- Introduced RepositoryNotInitializedError for improved error handling.
- Added a check in process_webhook to fetch the pull request only when necessary.
- Added local_repo_dict in _repo_data_from_config for better repo config handling.
webhook_server_container/.../helpers.py - Updated the get_value_from_dicts function signature by adding an optional third_dict parameter (defaulting to None).
- Modified the function logic to initialize third_dict as an empty dictionary when not provided and check it for the specified key before returning a fallback value.
- Revised type hints throughout.
webhook_server_container/.../github_repository_settings.py - Updated type annotations from capitalized types to lowercase equivalents across multiple function signatures and variable declarations.
- Modified the return type of get_repository_github_app_api from Optional[Github] to `Github

Possibly related PRs

Suggested labels

verified, size/L, can-be-merged, approved-rnetser

Suggested reviewers

  • rnetser
  • dbasunag

Tip

CodeRabbit's docstrings feature is now available as part of our Pro Plan! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
  • @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
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: 1

🧹 Nitpick comments (1)
webhook_server_container/libs/github_api.py (1)

372-372: Fix typo in configuration filename.

There's a typo in the configuration filename: .gethub-webhok_server.config should probably be .github-webhook_server.config.

-                content = repository.get_contents(".gethub-webhok_server.config", ref=self.pull_request_branch)
+                content = repository.get_contents(".github-webhook_server.config", ref=self.pull_request_branch)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f15a635 and 6a4c006.

📒 Files selected for processing (2)
  • webhook_server_container/libs/github_api.py (27 hunks)
  • webhook_server_container/utils/helpers.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: tox
  • GitHub Check: python-module-install
  • GitHub Check: build-container
  • GitHub Check: pre-commit
🔇 Additional comments (5)
webhook_server_container/utils/helpers.py (1)

19-32: Implementation of third_dict parameter looks good!

The function has been updated to accept an optional third dictionary for lookups. The implementation correctly handles the case when third_dict is None and the docstring has been updated to reflect the new behavior.

webhook_server_container/libs/github_api.py (4)

387-391: Good use of dictionary unpacking for cleaner code.

The use of dictionary unpacking to pass parameters to get_value_from_dicts makes the code cleaner and more maintainable.


131-136: Improved error handling with try-except block.

Adding a try-except block for NoPullRequestError allows the code to gracefully handle cases where a pull request cannot be found.


208-210: Efficient resource usage.

Checking if self.pull_request is None before calling _get_pull_request() avoids unnecessary API calls, which is a good optimization.


13-13: Modernized type annotations.

Replacing Dict with dict aligns with modern Python type annotation practices. In Python 3.9+, the built-in types can be used directly for annotations.

Comment on lines +381 to 382
if not repo_data or local_repo_dict:
raise RepositoryNotFoundError(f"Repository {self.repository_name} not found in config file")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix incorrect conditional logic.

The current condition will raise an error if repo_data is empty BUT local_repo_dict has data, which doesn't seem to be the intended behavior. The logic should check if both are empty before raising an error.

-        if not repo_data or local_repo_dict:
+        if not repo_data and not local_repo_dict:
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if not repo_data or local_repo_dict:
raise RepositoryNotFoundError(f"Repository {self.repository_name} not found in config file")
if not repo_data and not local_repo_dict:
raise RepositoryNotFoundError(f"Repository {self.repository_name} not found in config file")

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: 1

🔭 Outside diff range comments (4)
webhook_server_container/app.py (4)

18-18: 🛠️ Refactor suggestion

Update return type annotation to use lowercase types.

For consistency with the modernization effort, the return type should also use lowercase dict instead of Dict.

-def healthcheck() -> Dict[str, Any]:
+def healthcheck() -> dict[str, Any]:

23-23: 🛠️ Refactor suggestion

Update return type annotation to use lowercase types.

For consistency with the modernization effort, the return type should also use lowercase dict instead of Dict.

-async def process_webhook(request: Request) -> Dict[str, Any]:
+async def process_webhook(request: Request) -> dict[str, Any]:

27-27: 🛠️ Refactor suggestion

Update type annotation to use lowercase types.

For consistency with the modernization effort, the type annotation should use lowercase dict instead of Dict.

-    process_failed_msg: Dict[str, Any] = {
+    process_failed_msg: dict[str, Any] = {

33-33: 🛠️ Refactor suggestion

Update type annotation to use lowercase types.

For consistency with the modernization effort, the type annotation should use lowercase dict instead of Dict.

-        hook_data: Dict[Any, Any] = await request.json()
+        hook_data: dict[Any, Any] = await request.json()
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bd9464f and 69a931b.

📒 Files selected for processing (4)
  • webhook_server_container/app.py (2 hunks)
  • webhook_server_container/libs/github_api.py (56 hunks)
  • webhook_server_container/utils/github_repository_settings.py (11 hunks)
  • webhook_server_container/utils/helpers.py (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • webhook_server_container/utils/helpers.py
  • webhook_server_container/libs/github_api.py
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: tox
  • GitHub Check: python-module-install
  • GitHub Check: build-container
  • GitHub Check: pre-commit
🔇 Additional comments (16)
webhook_server_container/app.py (3)

7-7: LGTM! Good addition of explicit Request import.

Explicitly importing Request from FastAPI is a good practice since it's being used in the function signature at line 23.


47-47: Good simplification of exception handling.

Nice cleanup by removing the unused exc_obj variable and replacing it with the underscore convention for unused variables.


53-53: Good addition of error logging.

Adding this logging statement enhances error visibility and debugging capabilities.

webhook_server_container/utils/github_repository_settings.py (13)

5-5: LGTM! Good cleanup of imports.

The import statement has been updated to only include the types that are actually used in the file, removing unnecessary imports.


50-50: LGTM! Modernized type annotation.

The type annotation has been updated to use lowercase list instead of List in accordance with modern Python typing practices.


104-107: LGTM! Consistent type annotation updates.

All type annotations have been properly updated to use lowercase types (dict and list) instead of their capitalized equivalents.


134-136: LGTM! Modernized type annotations.

The type annotations have been updated to use lowercase types (tuple, list, and dict) instead of their capitalized equivalents, making the code more aligned with modern Python typing practices.


148-148: LGTM! Modernized type annotation.

The type annotation has been updated to use lowercase dict instead of Dict in accordance with modern Python typing practices.


176-178: LGTM! Modernized type annotation.

The type annotation has been updated to use lowercase list instead of List in accordance with modern Python typing practices.


179-179: LGTM! Modernized type annotation.

The type annotation has been updated to use lowercase dict instead of Dict in accordance with modern Python typing practices.


204-205: LGTM! Modernized type annotations.

All type annotations in the function signature have been properly updated to use lowercase types (dict, list, and tuple) instead of their capitalized equivalents.


210-210: LGTM! Modernized type annotation.

The type annotation has been updated to use lowercase dict instead of Dict in accordance with modern Python typing practices.


222-222: LGTM! Modernized type annotation.

The type annotation has been updated to use lowercase list instead of List in accordance with modern Python typing practices.


275-275: LGTM! Modernized type annotation.

The type annotation has been updated to use lowercase list instead of List in accordance with modern Python typing practices.


295-296: LGTM! Modernized type annotations.

All type annotations in the function signature have been properly updated to use lowercase types (dict and tuple) instead of their capitalized equivalents.


328-328: LGTM! Modernized return type using pipe syntax.

The return type has been updated from Optional[Github] to Github | None, which is the newer Python 3.10+ syntax for union types.

from typing import Any, Dict
import os
import sys
from typing import Any, Dict
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Type annotation should use lowercase types for consistency.

The type annotation still uses Dict instead of the lowercase dict. According to the PR summary, one of the goals is to modernize type annotations by replacing capitalized types with their lowercase equivalents.

-from typing import Any, Dict
+from typing import Any
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
from typing import Any, Dict
from typing import Any

Comment on lines +392 to +394
# self.github_app_id: str = get_value_from_dicts(
# primary_dict=repo_data, secondary_dict=config_data, key="github-app-id"
# )
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

leftovers?


if not value:
value = secondary_dict.get(key)
if not value:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if not value:
if third_dict and not value:

@myakove myakove closed this Apr 24, 2025
@myakove myakove deleted the repo-config-from-repo branch April 24, 2025 10:41
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