mirror of
https://github.com/langgenius/dify-plugin-sdks.git
synced 2026-07-22 02:15:22 -04:00
GitHub Trigger Plugin
This plugin provides GitHub webhook triggers for Dify workflows, allowing you to automatically respond to GitHub events like code pushes, pull requests, issues, and more.
Features
- Push Event Trigger: Responds to code pushes to GitHub repositories
- Webhook Signature Verification: Securely validates GitHub webhook requests
- OAuth Integration: Easy authentication with GitHub
- Rich Event Data: Extracts detailed information from GitHub events
Setup
1. Install Dependencies
pip install -r requirements.txt
2. Configure GitHub OAuth (Optional)
If you want to use OAuth for authentication:
- Go to your GitHub Settings > Developer settings > OAuth Apps
- Create a new OAuth App
- Set the Authorization callback URL to your Dify instance
- Copy the Client ID and Client Secret
3. Generate GitHub Personal Access Token
- Go to GitHub Settings > Developer settings > Personal access tokens
- Generate a new token with appropriate repository permissions
- Copy the token for use in the plugin configuration
4. Set Up Webhook
- Go to your repository Settings > Webhooks
- Add a new webhook with:
- Payload URL: Your Dify plugin webhook endpoint
- Content type:
application/json - Secret: (optional but recommended for security)
- Events: Select the events you want to trigger on (e.g., "Pushes")
Available Triggers
Push Trigger
Triggered when someone pushes code to a repository.
Event Variables:
repository_name: Name of the repositoryrepository_full_name: Full name (owner/repo)repository_url: Repository URLbranch: Branch name that was pushed toref: Git reference (e.g., refs/heads/main)pusher_name: Name of the user who pushedpusher_email: Email of the user who pushedcommits_count: Number of commits in the pushcommits: Array of commit objects with detailshead_commit: Information about the head commit
Parameters:
repository_filter(optional): Filter by repository namebranch_filter(optional): Filter by branch name
Usage in Dify
- Install the plugin in your Dify instance
- Configure the plugin with your GitHub credentials
- Create a workflow and add the GitHub trigger
- Configure the trigger parameters as needed
- Add your workflow logic to process the GitHub event data
Example Workflow
# Example workflow triggered by GitHub push events
triggers:
- type: github_trigger.push_trigger
parameters:
branch_filter: "main" # Only trigger on main branch pushes
steps:
- name: process_push
type: code
code: |
# Access trigger variables
repo_name = trigger.repository_name
branch = trigger.branch
commits = trigger.commits
# Your processing logic here
print(f"New push to {repo_name} on branch {branch}")
print(f"Number of commits: {len(commits)}")
Security
- Always use webhook secrets to verify request authenticity
- Store credentials securely using Dify's credential management
- Use OAuth when possible for better security
- Regularly rotate access tokens
Troubleshooting
- Webhook not triggering: Check that the webhook URL is correct and accessible
- Authentication errors: Verify your GitHub token has the required permissions
- Signature verification fails: Ensure the webhook secret matches your configuration