Files
dify-plugin-sdks/python/examples/github_trigger/triggers/issues.py
T
Yeuoly 76d1820205 feat: introduce UnsubscribeError for improved error handling in GitHub provider
- Added UnsubscribeError class to handle errors during unsubscribe operations, providing detailed error messages and codes.
- Updated GithubProvider to raise UnsubscribeError in various failure scenarios, enhancing error reporting and debugging.
- Minor adjustments in the IssuesTrigger class to prepare for future enhancements.

These changes improve the robustness of the GitHub trigger integration by ensuring clearer error management during webhook unsubscription processes.
2025-09-26 20:15:04 +08:00

53 lines
2.1 KiB
Python

from collections.abc import Mapping
from typing import Any
from werkzeug import Request
from dify_plugin.entities.trigger import Event
from dify_plugin.errors.trigger import TriggerIgnoreEventError
from dify_plugin.interfaces.trigger import TriggerEvent
class IssuesTrigger(TriggerEvent):
"""
GitHub Issue Event Trigger
This unified trigger handles all GitHub issue events and extracts relevant
information from the webhook payload to provide as variables to the workflow.
"""
def _trigger(self, request: Request, parameters: Mapping[str, Any]) -> Event:
"""
Handle GitHub issue event trigger with comprehensive filtering
Parameters:
- event: Select which issue actions to trigger on (opened, closed, reopened, edited, assigned, labeled, etc.)
- labels: Only trigger if issue has these labels (comma-separated)
- exclude_labels: Don't trigger if issue has these labels (comma-separated)
- assignee: Only trigger if assigned to these users (comma-separated)
- authors: Only trigger for issues from these authors (comma-separated)
- exclude_authors: Don't trigger for issues from these authors (comma-separated)
- milestone: Only trigger for issues with these milestones (comma-separated)
- title_pattern: Only trigger if title matches this pattern (supports wildcards, comma-separated)
- body_contains: Only trigger if body contains these keywords (comma-separated)
"""
# Get the event payload
payload = request.get_json()
if not payload:
raise ValueError("No payload received")
# Get the action type
action = payload.get("action", "")
# Apply event filter
event = parameters.get("event", [])
if event and action not in event:
raise TriggerIgnoreEventError(f"Action '{action}' not in filter list: {event}")
return Event(
variables={
"action": action,
# TODO: add more variables depends on the trigger configuration
}
)