[PR #31175] feat: add GitHub workflow versioning integration #33124

Open
opened 2026-02-21 20:52:42 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/31175

State: open
Merged: No


GitHub Workflow Versioning Integration

issue link: https://github.com/langgenius/dify/issues/9972

Summary

This PR adds comprehensive GitHub integration for workflow versioning in Dify, enabling users to connect their workflows to GitHub repositories, manage branches, and push/pull workflow changes.

Features

1. GitHub OAuth 2.0 Authentication

  • Secure OAuth flow with CSRF protection using Redis-based state management
  • Temporary token storage in Redis (10-minute TTL) to prevent incomplete connections
  • Support for app-specific and workspace-level connections

2. GitHub Connection Management

  • Create, read, update, and delete GitHub connections
  • One connection per app enforcement
  • Repository and branch selection UI
  • Connection status tracking (complete/incomplete)

3. Workflow Versioning Operations

  • Push: Export workflow to GitHub repository with commit messages
  • Pull: Import workflow from GitHub repository (overwrites local draft)
  • Branch Management: Create, list, and switch branches
  • Commit History: View commit history for workflow files

4. Database Schema

  • New github_connections table with encrypted token storage
  • Support for multiple workflows per repository via workflow_file_path
  • Migration scripts for PostgreSQL and MySQL

5. Frontend UI Components

  • GitHub connection modal with repository selection
  • Push/Pull modals with branch selection
  • Branch management modal
  • Integration into workflow editor header

Technical Details

Backend Changes

  • Models: api/models/github_connection.py - Database model for GitHub connections
  • Services:
    • api/services/github/github_oauth_service.py - OAuth flow handling
    • api/services/github/github_api_client.py - GitHub API client wrapper
    • api/services/github/workflow_git_service.py - Workflow serialization and Git operations
  • Controllers:
    • api/controllers/console/github/connection.py - Connection CRUD endpoints
    • api/controllers/console/github/oauth.py - OAuth endpoints
    • api/controllers/console/github/workflow.py - Push/Pull endpoints
    • api/controllers/console/github/branches.py - Branch management endpoints
  • Migrations:
    • 2026_01_15_1200-add_github_connections_table.py - Initial table creation
    • 2026_01_18_1200-add_workflow_file_path_to_github_connections.py - Add workflow file path support

Frontend Changes

  • Components:
    • web/app/components/github/github-connection-modal.tsx - Connection management UI
    • web/app/components/github/github-push-pull-modal.tsx - Push/Pull UI
    • web/app/components/github/github-branch-modal.tsx - Branch management UI
    • web/app/components/workflow/header/github-connection-button.tsx - Header button
    • web/app/components/workflow/header/github-workflow-actions.tsx - Push/Pull/Branch buttons
  • Services: web/service/github.ts - API client functions
  • Types: web/types/github.ts - TypeScript type definitions
  • i18n: web/i18n/en-US/github.json - Internationalization strings

Security Features

  • Encrypted token storage using Dify's encryption utilities
  • SSRF protection via proxy service for all external HTTP requests
  • CSRF protection for OAuth flow using Redis-based state management
  • Tenant and user isolation for all operations

Testing

  • Unit tests for GitHubOAuthService and GitHubAPIClient
  • Manual testing of OAuth flow, connection management, push/pull operations
  • Tested with multiple branches and conflict scenarios

Configuration Required

  • GITHUB_CLIENT_ID - GitHub OAuth App Client ID
  • GITHUB_CLIENT_SECRET - GitHub OAuth App Client Secret
  • CONSOLE_API_URL - Backend API URL for OAuth callback
  • CONSOLE_WEB_URL - Frontend URL for OAuth redirect

Migration Notes

  • Two database migrations included
  • Backward compatible - existing workflows unaffected
  • No data migration required for existing users

Breaking Changes

None - this is a new feature addition.

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint and make type-check (backend) and cd web && npx lint-staged (frontend) to appease the lint gods

Screenshots

New Github button

Shows the new Github button in the workflow header, allowing users to connect their workflows to GitHub.

image

GitHub Connection Modal - Initial State

Shows the initial GitHub connection modal with "Connect to GitHub" button after clicking the new Github button, allowing users to initiate the OAuth flow.

image

GitHub Connection Modal - After OAuth Success

Displays the connection modal after successful OAuth authorization, showing repository selection dropdown and branch input field.

image

Workflow Editor with GitHub Actions

Shows the workflow editor with GitHub integration active, displaying Push, Pull, and Branch management buttons in the header.

image

Push Workflow Modal

Displays the push workflow modal with commit message input field and branch selection, allowing users to push workflow changes to GitHub.

image

Branch Management - Multiple Branches

Shows the branch management modal displaying multiple branches with the current branch highlighted, allowing users to switch between branches.

image

Branch Management - Create Branch

Displays the branch management modal with "Create New Branch" button, enabling users to create new branches from the current branch.

image

Future Enhancements (Not in this PR)

  • Webhook support for automatic sync
  • Conflict resolution UI
  • Multi-file workflow support
  • Pull request creation from Dify UI
**Original Pull Request:** https://github.com/langgenius/dify/pull/31175 **State:** open **Merged:** No --- # GitHub Workflow Versioning Integration **issue link:** https://github.com/langgenius/dify/issues/9972 ## Summary This PR adds comprehensive GitHub integration for workflow versioning in Dify, enabling users to connect their workflows to GitHub repositories, manage branches, and push/pull workflow changes. ## Features ### 1. GitHub OAuth 2.0 Authentication - Secure OAuth flow with CSRF protection using Redis-based state management - Temporary token storage in Redis (10-minute TTL) to prevent incomplete connections - Support for app-specific and workspace-level connections ### 2. GitHub Connection Management - Create, read, update, and delete GitHub connections - One connection per app enforcement - Repository and branch selection UI - Connection status tracking (complete/incomplete) ### 3. Workflow Versioning Operations - **Push**: Export workflow to GitHub repository with commit messages - **Pull**: Import workflow from GitHub repository (overwrites local draft) - **Branch Management**: Create, list, and switch branches - **Commit History**: View commit history for workflow files ### 4. Database Schema - New `github_connections` table with encrypted token storage - Support for multiple workflows per repository via `workflow_file_path` - Migration scripts for PostgreSQL and MySQL ### 5. Frontend UI Components - GitHub connection modal with repository selection - Push/Pull modals with branch selection - Branch management modal - Integration into workflow editor header ## Technical Details ### Backend Changes - **Models**: `api/models/github_connection.py` - Database model for GitHub connections - **Services**: - `api/services/github/github_oauth_service.py` - OAuth flow handling - `api/services/github/github_api_client.py` - GitHub API client wrapper - `api/services/github/workflow_git_service.py` - Workflow serialization and Git operations - **Controllers**: - `api/controllers/console/github/connection.py` - Connection CRUD endpoints - `api/controllers/console/github/oauth.py` - OAuth endpoints - `api/controllers/console/github/workflow.py` - Push/Pull endpoints - `api/controllers/console/github/branches.py` - Branch management endpoints - **Migrations**: - `2026_01_15_1200-add_github_connections_table.py` - Initial table creation - `2026_01_18_1200-add_workflow_file_path_to_github_connections.py` - Add workflow file path support ### Frontend Changes - **Components**: - `web/app/components/github/github-connection-modal.tsx` - Connection management UI - `web/app/components/github/github-push-pull-modal.tsx` - Push/Pull UI - `web/app/components/github/github-branch-modal.tsx` - Branch management UI - `web/app/components/workflow/header/github-connection-button.tsx` - Header button - `web/app/components/workflow/header/github-workflow-actions.tsx` - Push/Pull/Branch buttons - **Services**: `web/service/github.ts` - API client functions - **Types**: `web/types/github.ts` - TypeScript type definitions - **i18n**: `web/i18n/en-US/github.json` - Internationalization strings ### Security Features - Encrypted token storage using Dify's encryption utilities - SSRF protection via proxy service for all external HTTP requests - CSRF protection for OAuth flow using Redis-based state management - Tenant and user isolation for all operations ## Testing - Unit tests for `GitHubOAuthService` and `GitHubAPIClient` - Manual testing of OAuth flow, connection management, push/pull operations - Tested with multiple branches and conflict scenarios ## Configuration Required - `GITHUB_CLIENT_ID` - GitHub OAuth App Client ID - `GITHUB_CLIENT_SECRET` - GitHub OAuth App Client Secret - `CONSOLE_API_URL` - Backend API URL for OAuth callback - `CONSOLE_WEB_URL` - Frontend URL for OAuth redirect ## Migration Notes - Two database migrations included - Backward compatible - existing workflows unaffected - No data migration required for existing users ## Breaking Changes None - this is a new feature addition. ## Checklist - [x] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `make lint` and `make type-check` (backend) and `cd web && npx lint-staged` (frontend) to appease the lint gods ## Screenshots ### New Github button Shows the new Github button in the workflow header, allowing users to connect their workflows to GitHub. <img width="2422" height="1346" alt="image" src="https://github.com/user-attachments/assets/bf404eeb-f91e-4c1a-ae82-9707a1a53623" /> ### GitHub Connection Modal - Initial State Shows the initial GitHub connection modal with "Connect to GitHub" button after clicking the new Github button, allowing users to initiate the OAuth flow. <img width="2422" height="1346" alt="image" src="https://github.com/user-attachments/assets/f8b0d95f-c686-4d24-abe9-fd0814c85865" /> ### GitHub Connection Modal - After OAuth Success Displays the connection modal after successful OAuth authorization, showing repository selection dropdown and branch input field. <img width="2422" height="1346" alt="image" src="https://github.com/user-attachments/assets/b78781c1-01bd-4bb6-968b-8164761bd0b8" /> ### Workflow Editor with GitHub Actions Shows the workflow editor with GitHub integration active, displaying Push, Pull, and Branch management buttons in the header. <img width="2422" height="1346" alt="image" src="https://github.com/user-attachments/assets/bbe64a92-75b4-4eb4-9c45-1ce9912910a5" /> ### Push Workflow Modal Displays the push workflow modal with commit message input field and branch selection, allowing users to push workflow changes to GitHub. <img width="2422" height="1346" alt="image" src="https://github.com/user-attachments/assets/4b2aa979-540a-4040-8971-e7d20b567e95" /> ### Branch Management - Multiple Branches Shows the branch management modal displaying multiple branches with the current branch highlighted, allowing users to switch between branches. <img width="2422" height="1346" alt="image" src="https://github.com/user-attachments/assets/986c5b63-7be8-4889-93f1-02d9c6b36189" /> ### Branch Management - Create Branch Displays the branch management modal with "Create New Branch" button, enabling users to create new branches from the current branch. <img width="2422" height="1346" alt="image" src="https://github.com/user-attachments/assets/29fa5a0f-9dfb-4d5b-965e-0c98066c1266" /> ## Future Enhancements (Not in this PR) - Webhook support for automatic sync - Conflict resolution UI - Multi-file workflow support - Pull request creation from Dify UI
yindo added the pull-request label 2026-02-21 20:52:42 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#33124