mirror of
https://github.com/langgenius/dify-plugin-sdks.git
synced 2026-07-22 10:25:23 -04:00
chore: bump dify_plugin version to 0.6.0b7 and update trigger event handling
- 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.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
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})
|
||||
@@ -0,0 +1,209 @@
|
||||
identity:
|
||||
name: star_created
|
||||
author: langgenius
|
||||
label:
|
||||
en_US: Star Created
|
||||
zh_Hans: 仓库被 Star
|
||||
ja_JP: Star 追加
|
||||
|
||||
description:
|
||||
human:
|
||||
en_US: Triggers when someone stars the repository
|
||||
zh_Hans: 当有人给仓库添加 star 时触发
|
||||
ja_JP: 誰かがリポジトリにスターを付けたときにトリガーされます
|
||||
llm:
|
||||
en_US: This trigger activates when a user stars a GitHub repository, providing information about the repository and the user who starred it.
|
||||
zh_Hans: 当用户给 GitHub 仓库添加 star 时,此触发器会被激活,提供有关仓库和添加 star 的用户的信息。
|
||||
ja_JP: ユーザーが GitHub リポジトリにスターを付けたときにトリガーがアクティブになり、リポジトリとスターを付けたユーザーに関する情報を提供します。
|
||||
|
||||
parameters:
|
||||
- name: starred_by
|
||||
label:
|
||||
en_US: Starred By
|
||||
zh_Hans: Star 用户过滤
|
||||
ja_JP: ユーザーフィルター
|
||||
type: string
|
||||
required: false
|
||||
description:
|
||||
en_US: "Only trigger for stars from these users (e.g., user1, user2, comma-separated)"
|
||||
zh_Hans: "仅对这些用户的 star 操作触发(例如:user1, user2,逗号分隔)"
|
||||
ja_JP: "これらのユーザーのスターのみトリガー(例: user1, user2,カンマ区切り)"
|
||||
|
||||
output_schema:
|
||||
type: object
|
||||
properties:
|
||||
action:
|
||||
type: string
|
||||
enum:
|
||||
- created
|
||||
description: The action that was performed (created)
|
||||
|
||||
starred_at:
|
||||
type:
|
||||
- string
|
||||
- "null"
|
||||
format: date-time
|
||||
description: The time the star was created
|
||||
|
||||
repository:
|
||||
type: object
|
||||
description: The repository that was starred
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
description: Unique identifier of the repository
|
||||
node_id:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
description: The name of the repository
|
||||
full_name:
|
||||
type: string
|
||||
description: Full name including owner
|
||||
private:
|
||||
type: boolean
|
||||
description: Whether the repository is private
|
||||
owner:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
login:
|
||||
type: string
|
||||
node_id:
|
||||
type: string
|
||||
avatar_url:
|
||||
type: string
|
||||
format: uri
|
||||
html_url:
|
||||
type: string
|
||||
format: uri
|
||||
type:
|
||||
type: string
|
||||
enum:
|
||||
- Bot
|
||||
- User
|
||||
- Organization
|
||||
site_admin:
|
||||
type: boolean
|
||||
required:
|
||||
- id
|
||||
- login
|
||||
html_url:
|
||||
type: string
|
||||
format: uri
|
||||
description:
|
||||
type:
|
||||
- string
|
||||
- "null"
|
||||
fork:
|
||||
type: boolean
|
||||
url:
|
||||
type: string
|
||||
format: uri
|
||||
created_at:
|
||||
type: string
|
||||
format: date-time
|
||||
updated_at:
|
||||
type: string
|
||||
format: date-time
|
||||
pushed_at:
|
||||
type:
|
||||
- string
|
||||
- "null"
|
||||
format: date-time
|
||||
stargazers_count:
|
||||
type: integer
|
||||
watchers_count:
|
||||
type: integer
|
||||
language:
|
||||
type:
|
||||
- string
|
||||
- "null"
|
||||
forks_count:
|
||||
type: integer
|
||||
open_issues_count:
|
||||
type: integer
|
||||
default_branch:
|
||||
type: string
|
||||
description: The default branch of the repository
|
||||
topics:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
visibility:
|
||||
type: string
|
||||
enum:
|
||||
- public
|
||||
- private
|
||||
- internal
|
||||
required:
|
||||
- id
|
||||
- node_id
|
||||
- name
|
||||
- full_name
|
||||
- private
|
||||
- owner
|
||||
- html_url
|
||||
- url
|
||||
- created_at
|
||||
- updated_at
|
||||
- fork
|
||||
- default_branch
|
||||
- visibility
|
||||
|
||||
sender:
|
||||
type: object
|
||||
description: The user who starred the repository
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
login:
|
||||
type: string
|
||||
node_id:
|
||||
type: string
|
||||
avatar_url:
|
||||
type: string
|
||||
format: uri
|
||||
html_url:
|
||||
type: string
|
||||
format: uri
|
||||
type:
|
||||
type: string
|
||||
enum:
|
||||
- Bot
|
||||
- User
|
||||
- Organization
|
||||
site_admin:
|
||||
type: boolean
|
||||
required:
|
||||
- id
|
||||
- login
|
||||
- type
|
||||
|
||||
organization:
|
||||
type: object
|
||||
description: The organization that owns the repository (if applicable)
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
login:
|
||||
type: string
|
||||
node_id:
|
||||
type: string
|
||||
url:
|
||||
type: string
|
||||
format: uri
|
||||
avatar_url:
|
||||
type: string
|
||||
format: uri
|
||||
|
||||
required:
|
||||
- action
|
||||
- repository
|
||||
- sender
|
||||
|
||||
extra:
|
||||
python:
|
||||
source: events/star/star_created.py
|
||||
@@ -0,0 +1,47 @@
|
||||
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 StarDeletedEvent(Event):
|
||||
"""
|
||||
GitHub Star Deleted Event
|
||||
|
||||
This event transforms GitHub star deleted webhook events and extracts relevant
|
||||
information from the webhook payload to provide as variables to the workflow.
|
||||
"""
|
||||
|
||||
def _check_unstarred_by(self, sender: Mapping[str, Any], unstarred_by_param: str | None) -> None:
|
||||
"""Check if star was removed by allowed users"""
|
||||
if not unstarred_by_param:
|
||||
return
|
||||
|
||||
allowed_users = [user.strip() for user in unstarred_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 deleted 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_unstarred_by(sender, parameters.get("unstarred_by"))
|
||||
|
||||
return Variables(variables={**payload})
|
||||
@@ -0,0 +1,209 @@
|
||||
identity:
|
||||
name: star_deleted
|
||||
author: langgenius
|
||||
label:
|
||||
en_US: Star Deleted
|
||||
zh_Hans: 仓库 Star 被移除
|
||||
ja_JP: Star 削除
|
||||
|
||||
description:
|
||||
human:
|
||||
en_US: Triggers when someone unstars the repository
|
||||
zh_Hans: 当有人移除仓库的 star 时触发
|
||||
ja_JP: 誰かがリポジトリのスターを削除したときにトリガーされます
|
||||
llm:
|
||||
en_US: This trigger activates when a user removes their star from a GitHub repository, providing information about the repository and the user who unstarred it.
|
||||
zh_Hans: 当用户移除 GitHub 仓库的 star 时,此触发器会被激活,提供有关仓库和移除 star 的用户的信息。
|
||||
ja_JP: ユーザーが GitHub リポジトリからスターを削除したときにトリガーがアクティブになり、リポジトリとスターを削除したユーザーに関する情報を提供します。
|
||||
|
||||
parameters:
|
||||
- name: unstarred_by
|
||||
label:
|
||||
en_US: Unstarred By
|
||||
zh_Hans: 取消 Star 用户过滤
|
||||
ja_JP: ユーザーフィルター
|
||||
type: string
|
||||
required: false
|
||||
description:
|
||||
en_US: "Only trigger for unstars from these users (e.g., user1, user2, comma-separated)"
|
||||
zh_Hans: "仅对这些用户的取消 star 操作触发(例如:user1, user2,逗号分隔)"
|
||||
ja_JP: "これらのユーザーのスター削除のみトリガー(例: user1, user2,カンマ区切り)"
|
||||
|
||||
output_schema:
|
||||
type: object
|
||||
properties:
|
||||
action:
|
||||
type: string
|
||||
enum:
|
||||
- deleted
|
||||
description: The action that was performed (deleted)
|
||||
|
||||
starred_at:
|
||||
type:
|
||||
- string
|
||||
- "null"
|
||||
format: date-time
|
||||
description: The time the star was originally created
|
||||
|
||||
repository:
|
||||
type: object
|
||||
description: The repository that was unstarred
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
description: Unique identifier of the repository
|
||||
node_id:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
description: The name of the repository
|
||||
full_name:
|
||||
type: string
|
||||
description: Full name including owner
|
||||
private:
|
||||
type: boolean
|
||||
description: Whether the repository is private
|
||||
owner:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
login:
|
||||
type: string
|
||||
node_id:
|
||||
type: string
|
||||
avatar_url:
|
||||
type: string
|
||||
format: uri
|
||||
html_url:
|
||||
type: string
|
||||
format: uri
|
||||
type:
|
||||
type: string
|
||||
enum:
|
||||
- Bot
|
||||
- User
|
||||
- Organization
|
||||
site_admin:
|
||||
type: boolean
|
||||
required:
|
||||
- id
|
||||
- login
|
||||
html_url:
|
||||
type: string
|
||||
format: uri
|
||||
description:
|
||||
type:
|
||||
- string
|
||||
- "null"
|
||||
fork:
|
||||
type: boolean
|
||||
url:
|
||||
type: string
|
||||
format: uri
|
||||
created_at:
|
||||
type: string
|
||||
format: date-time
|
||||
updated_at:
|
||||
type: string
|
||||
format: date-time
|
||||
pushed_at:
|
||||
type:
|
||||
- string
|
||||
- "null"
|
||||
format: date-time
|
||||
stargazers_count:
|
||||
type: integer
|
||||
watchers_count:
|
||||
type: integer
|
||||
language:
|
||||
type:
|
||||
- string
|
||||
- "null"
|
||||
forks_count:
|
||||
type: integer
|
||||
open_issues_count:
|
||||
type: integer
|
||||
default_branch:
|
||||
type: string
|
||||
description: The default branch of the repository
|
||||
topics:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
visibility:
|
||||
type: string
|
||||
enum:
|
||||
- public
|
||||
- private
|
||||
- internal
|
||||
required:
|
||||
- id
|
||||
- node_id
|
||||
- name
|
||||
- full_name
|
||||
- private
|
||||
- owner
|
||||
- html_url
|
||||
- url
|
||||
- created_at
|
||||
- updated_at
|
||||
- fork
|
||||
- default_branch
|
||||
- visibility
|
||||
|
||||
sender:
|
||||
type: object
|
||||
description: The user who unstarred the repository
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
login:
|
||||
type: string
|
||||
node_id:
|
||||
type: string
|
||||
avatar_url:
|
||||
type: string
|
||||
format: uri
|
||||
html_url:
|
||||
type: string
|
||||
format: uri
|
||||
type:
|
||||
type: string
|
||||
enum:
|
||||
- Bot
|
||||
- User
|
||||
- Organization
|
||||
site_admin:
|
||||
type: boolean
|
||||
required:
|
||||
- id
|
||||
- login
|
||||
- type
|
||||
|
||||
organization:
|
||||
type: object
|
||||
description: The organization that owns the repository (if applicable)
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
login:
|
||||
type: string
|
||||
node_id:
|
||||
type: string
|
||||
url:
|
||||
type: string
|
||||
format: uri
|
||||
avatar_url:
|
||||
type: string
|
||||
format: uri
|
||||
|
||||
required:
|
||||
- action
|
||||
- repository
|
||||
- sender
|
||||
|
||||
extra:
|
||||
python:
|
||||
source: events/star/star_deleted.py
|
||||
@@ -34,4 +34,4 @@ resource:
|
||||
tags:
|
||||
- utilities
|
||||
type: plugin
|
||||
version: 1.1.2
|
||||
version: 1.1.3
|
||||
|
||||
@@ -41,9 +41,8 @@ class GithubTrigger(Trigger):
|
||||
|
||||
payload: Mapping[str, Any] = self._validate_payload(request)
|
||||
response = Response(response='{"status": "ok"}', status=200, mimetype="application/json")
|
||||
return EventDispatch(
|
||||
events=[self._dispatch_trigger_event(event_type=event_type, payload=payload)], response=response
|
||||
)
|
||||
event: str = self._dispatch_trigger_event(event_type=event_type, payload=payload)
|
||||
return EventDispatch(events=[event] if event else [], response=response)
|
||||
|
||||
def _dispatch_trigger_event(self, event_type: str, payload: Mapping[str, Any]) -> str:
|
||||
event_type = event_type.lower()
|
||||
@@ -54,7 +53,10 @@ class GithubTrigger(Trigger):
|
||||
if event_type == "issue_comments":
|
||||
return f"issue_comment_{action}"
|
||||
|
||||
raise TriggerDispatchError(f"Unsupported event type: {event_type}")
|
||||
if event_type == "star":
|
||||
return f"star_{action}"
|
||||
|
||||
return ""
|
||||
|
||||
def _validate_payload(self, request: Request) -> Mapping[str, Any]:
|
||||
try:
|
||||
|
||||
@@ -437,6 +437,8 @@ events:
|
||||
- events/issue_comment/issue_comment_created.yaml
|
||||
- events/issue_comment/issue_comment_edited.yaml
|
||||
- events/issue_comment/issue_comment_deleted.yaml
|
||||
- events/star/star_created.yaml
|
||||
- events/star/star_deleted.yaml
|
||||
|
||||
identity:
|
||||
author: langgenius
|
||||
|
||||
@@ -1 +1 @@
|
||||
dify_plugin==0.6.0b6
|
||||
dify_plugin==0.6.0b7
|
||||
Reference in New Issue
Block a user