The content submission system has been redesigned to use a git-bot approach that creates PRs directly on the origin repository. This eliminates the complexity and permission issues associated with fork-based workflows.
User Form → Bot API → Origin Repository → GitHub Actions → Admin Review → Merge
- User submits form → Frontend sends data to bot API
- Bot API → Creates branch on origin repo with payload files
- Bot API → Creates PR from that branch
- GitHub Actions → Simple workflow for branch-based PRs
- Admins → Review and merge PRs normally
✅ Simplified Workflow: No more fork complexity or permission issues
✅ Reliable: Bot has full access to origin repository
✅ Consistent: All PRs follow the same branch-based pattern
✅ Maintainable: Single workflow handles all content submissions
✅ Secure: User authentication verified before PR creation
api/github/create-content-pr.js- Bot API endpointtest-bot-api.js- Test script for bot APIBOT_APPROACH_README.md- This documentation
github-auth.js- Updated to use bot API instead of fork workflow.github/workflows/payload-pr-handler.yml- Simplified for branch-based PRspackage.json- Added @octokit/rest dependency
Endpoint: POST /api/github/create-content-pr
Request Body:
{
"contentData": {
"id": "unique-content-id",
"title": "Content Title",
"description": "Content Description",
"category": "algorithms",
"subtopic": "sorting",
"type": "guide",
"repo": "owner/repo",
"path": "path/to/file.md"
},
"userToken": "github_access_token"
}Response:
{
"success": true,
"pr": {
"number": 123,
"html_url": "https://github.com/prepguides/prepguides.dev/pull/123",
"title": "Content Submission: Title",
"state": "open",
"created_at": "2025-01-27T10:00:00Z"
},
"branch": "content-submission-username-1234567890",
"message": "Content submission PR created successfully!"
}# GitHub App Configuration
GITHUB_APP_ID=123456 # Your GitHub App ID
GITHUB_APP_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\n..." # App private key
GITHUB_APP_INSTALLATION_ID=789012 # Installation ID after installing app
# User Authentication (existing)
GITHUB_CLIENT_ID=your_client_id # For user authentication
GITHUB_CLIENT_SECRET=your_client_secret # For user authentication- Go to GitHub Settings → Developer settings → GitHub Apps
- Click "New GitHub App"
- Fill in details:
- Name: PrepGuides Content Bot
- Homepage URL: https://prepguides.dev
- User authorization callback URL: https://prepguides.dev/auth/callback
- Webhook URL: (leave blank)
- Webhook secret: (generate random string)
- Repository permissions:
- Contents: Read & write
- Issues: Write
- Pull requests: Write
- Metadata: Read
- Actions: Write
- Organization permissions:
- Members: Read (if needed)
- Pull request
- Issues
- Push
- After creating, click "Install App"
- Select repository:
prepguides/prepguides.dev - Install the app
- App ID: Found in app settings
- Private Key: Download the
.pemfile - Installation ID: Found after installing the app
Run the test script to verify the bot API works:
node test-bot-api.jsThe GitHub Actions workflow has been simplified:
- Removed: Fork detection logic
- Removed: Complex git diff commands for fork-based PRs
- Simplified: Back to standard
git diff HEAD~1 HEAD - Restored: Direct commit and push to PR branches
The old fork-based approach has been completely replaced:
- ❌
ensureFork()method - Removed - ❌
createBranch()method - Removed - ❌
createContentFile()method - Removed - ❌
formatContentAsJson()method - Removed - ❌
generatePRDescription()method - Removed
All of these are now handled by the bot API.
The bot API includes comprehensive error handling:
- User Authentication: Verifies user token before proceeding
- Branch Creation: Handles branch creation failures
- PR Creation: Handles PR creation failures
- Cleanup: Removes failed branches automatically
- Logging: Detailed logging for debugging
- User tokens are only used for authentication verification
- Bot token is used for all repository operations
- No user credentials are stored or logged
- All operations are logged for audit purposes
- Add PR template for bot-created PRs
- Implement automatic labeling based on content type
- Add support for multiple content files per submission
- Implement content validation before PR creation
- Add metrics and monitoring for bot operations