Skip to content

ADD: 添加多种⌚️支持#10

Merged
AptS-1547 merged 7 commits intomasterfrom
feat-polling
May 6, 2025
Merged

ADD: 添加多种⌚️支持#10
AptS-1547 merged 7 commits intomasterfrom
feat-polling

Conversation

@AptS-1547
Copy link
Copy Markdown
Owner

This pull request introduces significant updates to the GitHub webhook handling system, including enhanced support for various event types, a new unified bot client interface, and improved modularization of the codebase. Below is a summary of the most important changes grouped by theme.

GitHub Webhook Enhancements

  • Expanded the webhook event handling to support additional GitHub events, including pull_request, issues, release, and issue_comment. Each event type now has dedicated message formatting functions for improved notification clarity. (app/api/github_webhook.py, [1] [2] [3]
  • Added validation for empty request payloads and refactored the logic to dynamically match branches or other event-specific information based on the event type. (app/api/github_webhook.py, [1] [2]

Unified Bot Client Interface

  • Introduced a new BotClient class in app/botclient/__init__.py to provide a unified interface for managing bot clients (e.g., OneBot, Rocket.Chat, Telegram). This allows for easier extension and switching between bot implementations. (app/botclient/__init__.py, app/botclient/init.pyR1-R83)
  • Refactored the OneBot client initialization to align with the new unified interface, including renaming parameters (e.g., client_type to portol_type) for clarity. (app/botclient/onebot/onebot.py, [1] [2] [3]

Modularization and Code Cleanup

  • Moved the OneBot client implementation to a new directory structure under app/botclient/onebot/ for better modularization. Removed the text utility function in favor of MessageSegment for consistent message formatting. (app/botclient/onebot/__init__.py, [1] [2]
  • Added new modules for GitHub-related operations, including GitHubWebhookHandler and a placeholder for GitHubPollingHandler, with proper licensing and documentation. (app/core/github/__init__.py, [1]; app/core/github/polling.py, [2]

Documentation and Licensing

  • Updated the NOTICE file to include the APScheduler library under the MIT License. (NOTICE, NOTICER9)
  • Added licensing headers and detailed module-level documentation for new and modified files, ensuring compliance and clarity. (app/botclient/__init__.py, [1]; app/core/github/__init__.py, [2]; app/core/github/polling.py, [3]

@AptS-1547 AptS-1547 added the enhancement New feature or request label May 6, 2025
@AptS-1547 AptS-1547 requested a review from Copilot May 6, 2025 07:31
@AptS-1547 AptS-1547 self-assigned this May 6, 2025
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Hello @AptS-1547, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request introduces several enhancements and refactors to the GitHub webhook handling system. It expands support for various GitHub event types, introduces a unified bot client interface, and improves the modularity of the codebase. The changes include adding support for pull_request, issues, release, and issue_comment events, along with corresponding message formatting functions. A new BotClient class is introduced to provide a unified interface for managing different bot clients. The OneBot client implementation is moved to a new directory structure and refactored to align with the new interface. Additionally, new modules for GitHub-related operations are added, and licensing and documentation are updated.

Highlights

  • GitHub Webhook Enhancements: Expanded webhook event handling to support pull_request, issues, release, and issue_comment events. Dedicated message formatting functions are added for each event type.
  • Unified Bot Client Interface: Introduced a new BotClient class to provide a unified interface for managing bot clients, facilitating easier extension and switching between bot implementations.
  • Modularization and Code Cleanup: Moved the OneBot client implementation to a new directory structure under app/botclient/onebot/ for better modularization. Replaced the text utility function with MessageSegment for consistent message formatting.
  • Documentation and Licensing: Updated the NOTICE file to include APScheduler library under the MIT License. Added licensing headers and detailed module-level documentation for new and modified files.

Changelog

Click here to see the changelog
  • NOTICE
    • Added APScheduler to the list of third-party libraries with its MIT License.
  • app/api/github_webhook.py
    • Replaced direct OneBot client usage with the new BotClient interface.
    • Added validation for empty request payloads.
    • Refactored logic to dynamically match branches or event-specific information based on event type.
    • Added handling for pull_request, issues, release, and issue_comment events with corresponding message formatting.
    • Replaced text with MessageSegment.text for message formatting.
  • app/botclient/init.py
    • Introduced the BotClient class as a unified interface for managing bot clients.
    • Added methods for initializing, retrieving, and shutting down bot clients.
  • app/botclient/onebot/init.py
    • Removed text from the exported symbols.
    • Refactored to align with the new BotClient interface.
  • app/botclient/onebot/onebot.py
    • Renamed client_type to portol_type in init_onebot_client for clarity (line 417).
    • Removed the text utility function (lines 413-416).
  • app/core/github/init.py
    • Added new modules for GitHub-related operations, including GitHubWebhookHandler and GitHubPollingHandler.
  • app/core/github/polling.py
    • Added a placeholder for GitHubPollingHandler.
  • app/core/github/webhook.py
    • Added methods to extract data from pull_request, issue, release, and issue_comment events.
    • Added methods to extract data from pull_request, issue, release, and issue_comment events.
  • app/models/init.py
    • Exported MessageSegment.
  • app/models/config.py
    • Renamed ONEBOT_TYPE to ONEBOT_PORTOL_TYPE.
    • Updated validation logic to use ONEBOT_PORTOL_TYPE.
  • app/models/message.py
    • Created MessageSegment class with a static method text for creating text message segments.
  • config.example.yaml
    • Renamed ONEBOT_TYPE to ONEBOT_PORTOL_TYPE.
  • main.py
    • Replaced direct calls to init_onebot_client and shutdown_onebot_client with BotClient methods.
  • poetry.lock
    • Updated to Poetry 2.1.2.
    • Added apscheduler dependency.
    • Removed unittest group from colorama, iniconfig, packaging, and pytest.
    • Added tzdata and tzlocal dependencies.
    • Updated content hash.
  • pyproject.toml
    • Added apscheduler dependency.
    • Added packages = [{include = "app"}] and package-mode = false to tool.poetry.
    • Removed tool.poetry.group.unittest.dependencies.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


A webhook's tale,
Events trigger, bots prevail,
Messages now flow.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a unified bot client interface and expands webhook event handling, which are great improvements. The code is well-structured and includes necessary documentation and licensing. However, there are a few areas that could be improved for better maintainability and clarity.

Summary of Findings

  • Naming consistency: Inconsistent naming conventions are used for similar concepts (e.g., client_type vs. portol_type). Consistent naming improves code readability and reduces confusion.
  • Error handling: The error handling in github_webhook function could be improved by providing a more informative error message when an exception occurs during event processing.
  • Redundant checks: The payload check is performed twice in the github_webhook function. This redundancy can be removed to streamline the code.

Merge Readiness

The pull request is almost ready for merging. Addressing the naming inconsistencies and improving error handling would significantly enhance the code quality. I am unable to approve this pull request, and recommend that others review and approve this code before merging. At a minimum, the high severity issues should be addressed before merging.

Comment on lines 61 to 63
raise ValueError("当 ONEBOT_TYPE 为 ws 时,ONEBOT_URL 必须以 'ws://' 或 'wss://' 开头")
if self.ONEBOT_TYPE == "http" and not (self.ONEBOT_URL.startswith("http://") or self.ONEBOT_URL.startswith("https://")): # pylint: disable=line-too-long
if self.ONEBOT_PORTOL_TYPE == "http" and not (self.ONEBOT_URL.startswith("http://") or self.ONEBOT_URL.startswith("https://")): # pylint: disable=line-too-long
raise ValueError("当 ONEBOT_TYPE 为 http 时,ONEBOT_URL 必须以 'http://' 或 'https://' 开头")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For consistency, rename ONEBOT_TYPE to ONEBOT_CLIENT_TYPE or ONEBOT_PROTOCOL_TYPE to align with the naming in BotClient.

Suggested change
raise ValueError("当 ONEBOT_TYPE 为 ws 时,ONEBOT_URL 必须以 'ws://' 或 'wss://' 开头")
if self.ONEBOT_TYPE == "http" and not (self.ONEBOT_URL.startswith("http://") or self.ONEBOT_URL.startswith("https://")): # pylint: disable=line-too-long
if self.ONEBOT_PORTOL_TYPE == "http" and not (self.ONEBOT_URL.startswith("http://") or self.ONEBOT_URL.startswith("https://")): # pylint: disable=line-too-long
raise ValueError("当 ONEBOT_TYPE 为 http 时,ONEBOT_URL 必须以 'http://' 或 'https://' 开头")
if self.ONEBOT_PORTOL_TYPE == "ws" and not (self.ONEBOT_URL.startswith("ws://") or self.ONEBOT_URL.startswith("wss://")):
raise ValueError("当 ONEBOT_TYPE 为 ws 时,ONEBOT_URL 必须以 'ws://' 或 'wss://' 开头")
if self.ONEBOT_PORTOL_TYPE == "http" and not (self.ONEBOT_URL.startswith("http://") or self.ONEBOT_URL.startswith("https://")):

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the GitHub webhook handling system with support for additional events, implements a unified BotClient interface for managing various bot implementations, and refactors the codebase for improved modularity and configuration clarity.

  • Expanded webhook support for push, pull_request, issues, issue_comment, and release events with dedicated data extraction and message formatting functions.
  • Introduced a unified BotClient class and refactored OneBot client initialization by renaming parameters and updating configuration keys.
  • Modularized the code structure by moving OneBot client code and adding new modules for GitHub operations and polling.

Reviewed Changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pyproject.toml Added apscheduler dependency and updated Poetry configuration
main.py Refactored to use BotClient for client initialization
config.example.yaml Updated configuration key from ONEBOT_TYPE to ONEBOT_PORTOL_TYPE
app/models/message.py Introduced MessageSegment for unified message formatting
app/models/config.py Updated config schema including ONEBOT_PORTOL_TYPE; error messages need alignment
app/models/init.py Exported MessageSegment
app/core/github/webhook.py Added GitHub event data extraction functions
app/core/github/polling.py Added GitHub polling handler module
app/core/github/init.py Aggregated GitHub webhook and polling modules
app/botclient/onebot/onebot.py Refactored OneBot client initialization and messaging using portol_type
app/botclient/onebot/init.py Removed redundant text() export
app/botclient/init.py Introduced unified BotClient interface
app/api/github_webhook.py Updated webhook endpoint to use BotClient and support multiple events
Files not reviewed (1)
  • NOTICE: Language not supported
Comments suppressed due to low confidence (3)

app/models/config.py:60

  • Error message still refers to 'ONEBOT_TYPE' despite the renaming to 'ONEBOT_PORTOL_TYPE'. Please update the message for consistency.
raise ValueError("当 ONEBOT_TYPE 为 ws 时,ONEBOT_URL 必须以 'ws://' 或 'wss://' 开头")

app/botclient/onebot/onebot.py:417

  • [nitpick] The parameter name 'portol_type' appears ambiguous and may be a typo. Consider renaming it to 'protocol_type' for improved clarity.
async def init_onebot_client(portol_type: str,

app/api/github_webhook.py:76

  • The variable 'event_type' is referenced without being defined. Please extract it from the request headers (e.g., using 'request.headers.get("X-GitHub-Event")') before using it.
if event_type == "push":

@AptS-1547
Copy link
Copy Markdown
Owner Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a unified bot client interface and enhances GitHub webhook handling. The changes are well-structured and modular, improving the codebase's maintainability and extensibility. However, there are a few areas that could be improved for better clarity and error handling.

Summary of Findings

  • Inconsistent Naming: The configuration parameter name ONEBOT_TYPE was changed to ONEBOT_PROTOCOL_TYPE in some places but not consistently across all files. This inconsistency should be resolved to avoid confusion.
  • Error Handling: The github_webhook function in app/api/github_webhook.py returns a generic 'failed' status without providing specific error details, which makes debugging difficult. Improved error logging and more informative return messages would be beneficial.
  • Missing Input Validation: The find_matching_webhook function in app/core/github/webhook.py could benefit from input validation to ensure that repo_name, branch, and event_type are not None or empty strings before proceeding with the matching logic.

Merge Readiness

The pull request is well-structured and introduces valuable enhancements. However, addressing the identified issues related to naming consistency and error handling is recommended before merging. I am unable to directly approve this pull request, and it should be reviewed and approved by others before merging. At a minimum, the high severity issues should be addressed before merging.

"ENV": "production",
"ONEBOT_URL": "",
"ONEBOT_TYPE": "ws",
"ONEBOT_PORTOL_TYPE": "ws",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Typo: ONEBOT_PORTOL_TYPE should be ONEBOT_PROTOCOL_TYPE to match the variable name defined in the class.

Suggested change
"ONEBOT_PORTOL_TYPE": "ws",
"ONEBOT_PROTOCOL_TYPE": "ws",

@AptS-1547 AptS-1547 merged commit fdb30d2 into master May 6, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

2 participants