mirror of
https://github.com/langgenius/dify-plugin-sdks.git
synced 2026-08-25 12:29:32 -04:00
d6fa7bfb7e
- Updated the version in pyproject.toml from 0.6.0b6 to 0.6.0b7. - Renamed trigger-related methods and classes for clarity, changing invoke_trigger to invoke_trigger_event and updating associated request and response classes. - Adjusted event handling in the GithubTrigger class to improve event dispatching. These changes ensure the plugin is up-to-date and enhance the clarity and functionality of event handling.
48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
from collections.abc import Mapping
|
|
from typing import Any
|
|
|
|
from werkzeug import Request
|
|
|
|
from dify_plugin.entities.trigger import Variables
|
|
from dify_plugin.errors.trigger import EventIgnoreError
|
|
from dify_plugin.interfaces.trigger import Event
|
|
|
|
|
|
class StarCreatedEvent(Event):
|
|
"""
|
|
GitHub Star Created Event
|
|
|
|
This event transforms GitHub star created webhook events and extracts relevant
|
|
information from the webhook payload to provide as variables to the workflow.
|
|
"""
|
|
|
|
def _check_starred_by(self, sender: Mapping[str, Any], starred_by_param: str | None) -> None:
|
|
"""Check if star was added by allowed users"""
|
|
if not starred_by_param:
|
|
return
|
|
|
|
allowed_users = [user.strip() for user in starred_by_param.split(",") if user.strip()]
|
|
if not allowed_users:
|
|
return
|
|
|
|
sender_login = sender.get("login")
|
|
if sender_login not in allowed_users:
|
|
raise EventIgnoreError()
|
|
|
|
def _on_event(self, request: Request, parameters: Mapping[str, Any]) -> Variables:
|
|
"""
|
|
Transform GitHub star created webhook event into structured Variables
|
|
"""
|
|
payload = request.get_json()
|
|
if not payload:
|
|
raise ValueError("No payload received")
|
|
|
|
sender = payload.get("sender")
|
|
if not sender:
|
|
raise ValueError("No sender data in payload")
|
|
|
|
# Apply filters
|
|
self._check_starred_by(sender, parameters.get("starred_by"))
|
|
|
|
return Variables(variables={**payload})
|