Implements a complete workflow for non-technical users to contribute to open source projects: **New Features:** - ContributeButton component shows "Propose Changes" when project has upstream remote - ContributeWizard guides users through 5-step contribution process - PRStatusBadge shows existing PR status for current branch - Automatic forking when user lacks push permissions - OAuth and PAT authentication for GitHub, GitLab, Gitea/Codeberg - Pre-submission validation (type check + build) - Automatic remote configuration (upstream/origin) - PR creation and updates via Git host APIs **Git Host Abstraction:** - GitHostProvider interface for platform-agnostic operations - GitHubProvider with GitHub REST API v3 - GitLabProvider with GitLab REST API v4 - GiteaProvider for Gitea/Forgejo/Codeberg instances - Auto-detection of Git host from repository URL **Components:** - components/contribute/ContributeButton.tsx - Entry point button - components/contribute/ContributeWizard.tsx - Multi-step wizard UI - components/contribute/AuthStep.tsx - Authentication flow - components/contribute/DiffView.tsx - Changed files review - components/contribute/PRStatusBadge.tsx - PR status display **Hooks:** - hooks/useContribute.ts - Main contribution workflow orchestration **Context Updates:** - Extended GitSettings to include hostTokens for API authentication - Updated GitHubOAuth to save tokens in both formats **Integration:** - Added to ProjectView header (mobile and desktop) - Integrated with existing Git workflow - Works with existing OAuth callback system **Documentation:** - CONTRIBUTING_GUIDE.md with user guide and developer docs The system handles the entire fork → branch → commit → push → PR flow transparently, making open source contribution accessible to users without Git knowledge.
10 KiB
Contributing to Open Source Projects from Shakespeare
Shakespeare now includes a complete contribution workflow that allows anyone to propose changes to open source projects without needing to understand Git, forks, or pull requests.
Overview
The contribution system handles the entire process of submitting changes to upstream repositories:
- Authentication - Connect to GitHub, GitLab, or Gitea/Codeberg
- Review Changes - See what files you've modified
- Branch & Commit - Describe your changes
- Validation - Automatic build and type checks
- Fork & Push - Automatic forking and pushing (if needed)
- Pull Request - Create or update PRs with one click
For Users: How to Contribute
Step 1: Make Your Changes
Edit any project in Shakespeare that was cloned from a Git repository. Make your changes using the AI assistant or code editor.
Step 2: Click "Propose Changes"
When you're ready to submit your changes:
- Look for the "Propose Changes" button in the project header
- Click it to open the contribution wizard
- The system will detect which Git host you're using (GitHub, GitLab, etc.)
Step 3: Connect Your Account
Option A: Quick Connect (GitHub only)
- Click "Connect with GitHub"
- Authorize Shakespeare to access your GitHub account
- You'll be redirected back automatically
Option B: Personal Access Token
- Click the link to create a token on the Git host
- Follow the instructions to generate a token with the right permissions
- Paste the token into Shakespeare
- Click "Connect"
Required permissions:
- GitHub:
public_reposcope - GitLab:
apiorwrite_repositoryscope - Codeberg/Gitea:
repopermission
Step 4: Review Your Changes
The wizard shows you all files that have been:
- ✅ Added (new files)
- ✏️ Modified (changed files)
- ❌ Deleted (removed files)
Review the list and click "Continue" when ready.
Step 5: Describe Your Changes
Fill in the contribution details:
- Branch Name: A unique name for your changes (e.g.,
fix-typooradd-feature) - Commit Message: Brief description of what you changed
- PR Title: Clear summary of your contribution
- Description: Detailed explanation of the changes and why they're needed
- Allow maintainers to edit: ✓ Recommended (lets project maintainers make small adjustments)
Click "Run Checks" to continue.
Step 6: Validation
Shakespeare automatically:
- ✅ Type checks your code
- ✅ Builds the project
- ✅ Ensures everything compiles
If checks fail, you'll see specific errors to fix.
Step 7: Submit
Click "Submit Pull Request" and Shakespeare will:
- Check permissions - See if you can push directly to the repo
- Create a fork (if needed) - Automatically fork the repository to your account
- Create a branch - Make a new branch with your chosen name
- Commit changes - Save all your changes with your commit message
- Push to your fork - Upload the changes to GitHub/GitLab/etc.
- Open a pull request - Create a PR from your fork to the upstream repository
You'll see a success message with a link to your pull request!
Updating an Existing PR
If you're on a branch that already has an open PR:
- Make additional changes
- The "Update PR" option will appear
- Click it to push new commits to the existing PR
- The PR is automatically updated with your latest changes
For Developers: Architecture
Git Host Abstraction
The system uses a provider pattern to support multiple Git hosting platforms:
// lib/git-hosts/types.ts
interface GitHostProvider {
getRepository(owner: string, repo: string): Promise<GitRepository>;
canUserPush(owner: string, repo: string): Promise<boolean>;
createFork(owner: string, repo: string): Promise<GitFork>;
getFork(upstreamOwner: string, upstreamRepo: string, username: string): Promise<GitFork | null>;
createPullRequest(options: CreatePullRequestOptions): Promise<PullRequest>;
// ... and more
}
Implemented providers:
GitHubProvider- GitHub REST API v3GitLabProvider- GitLab REST API v4GiteaProvider- Gitea/Forgejo/Codeberg API v1
Component Structure
ContributeButton (components/contribute/ContributeButton.tsx)
- Detects if contribution is available for the current project
- Opens the ContributeWizard when clicked
ContributeWizard (components/contribute/ContributeWizard.tsx)
- Multi-step wizard component
- Handles the entire contribution flow
- Progress bar shows current step
- Error handling and validation
AuthStep (components/contribute/AuthStep.tsx)
- Authentication with Git hosts
- Supports OAuth (GitHub) and Personal Access Tokens
- Clear instructions for token generation
DiffView (components/contribute/DiffView.tsx)
- Shows all changed files
- Color-coded by change type (added/modified/deleted)
- File statistics
PRStatusBadge (components/contribute/PRStatusBadge.tsx)
- Shows existing PR status for current branch
- Displays PR state (open/merged/closed)
- Shows CI check status
- Links to the PR on the Git host
Hook: useContribute
The main hook that orchestrates the contribution process:
const {
needsAuth, // Check if user needs to authenticate
authenticate, // Add authentication token
contribute, // Execute full contribution workflow
updatePR, // Push new commits to existing PR
isLoading, // Loading state
error, // Error message
step, // Current workflow step
pr, // Created/updated pull request
} = useContribute();
Token Storage
Tokens are stored in two places for compatibility:
- Git Credentials (
settings.credentials) - For Git push/pull operations - Host Tokens (
settings.hostTokens) - For API operations (fork, PR creation, etc.)
// GitSettingsContext
interface GitSettings {
credentials: Record<string, GitCredential>; // For Git auth
hostTokens: Record<string, GitHostToken>; // For API auth
// ...
}
Remote Configuration
The system automatically manages Git remotes:
Before Forking:
origin -> https://github.com/original/repo.git
After Forking:
upstream -> https://github.com/original/repo.git (read-only)
origin -> https://github.com/yourname/repo.git (your fork)
This allows users to:
- Pull updates from upstream
- Push changes to their fork
- Keep their fork in sync
Security
- Tokens stored locally: All authentication tokens are stored in browser IndexedDB, never sent to Shakespeare servers
- Minimal scopes: Instructions guide users to grant only necessary permissions
- PKCE for OAuth: GitHub OAuth uses PKCE (Proof Key for Code Exchange) for enhanced security
- Token revocation: Users can remove tokens anytime from Git settings
API Rate Limiting
The system handles rate limiting gracefully:
- Caches Git host API responses where possible
- Shows clear error messages when rate limited
- Provides fallback to manual PR creation via compare URLs
Supported Git Hosts
GitHub
- ✅ OAuth login (PKCE)
- ✅ Personal Access Token
- ✅ Fork creation
- ✅ Pull request creation
- ✅ PR status and checks
- ✅ PR updates
GitLab
- ✅ Personal Access Token
- ✅ Fork creation (project forking)
- ✅ Merge request creation
- ✅ MR status and pipeline checks
- ✅ MR updates
Gitea/Forgejo/Codeberg
- ✅ Personal Access Token
- ✅ Fork creation
- ✅ Pull request creation
- ✅ PR status
- ✅ PR updates
Self-Hosted Git
For self-hosted Gitea/Forgejo instances:
- API URL is auto-detected from repository URL
- Uses same token authentication
- Full PR workflow support
Extending the System
Adding a New Git Host
- Create a new provider in
lib/git-hosts/:
export class NewHostProvider implements GitHostProvider {
readonly name = 'NewHost';
readonly apiBaseUrl = 'https://api.newhost.com';
// Implement all GitHostProvider methods
// ...
}
- Add detection logic in
lib/git-hosts/types.ts:
export function detectGitHost(url: string): HostType {
// ... existing logic
if (hostname.includes('newhost.com')) return 'newhost';
// ...
}
- Update factory in
lib/git-hosts/index.ts:
export function createGitHostProvider(url: string, config: GitHostConfig) {
// ... existing cases
case 'newhost':
return new NewHostProvider(config, corsProxy);
// ...
}
Customizing the Workflow
The ContributeWizard component is designed to be extensible:
- Add new validation steps in
handleBranchNext() - Add custom checks in the "checks" step
- Modify the UI for specific use cases
- Add custom metadata to PRs
Error Handling
The system provides fallbacks at every step:
- No API access → Manual token entry
- Fork fails → Direct push if user has permissions
- Rate limited → Show compare URL for manual PR creation
- Build fails → Show specific error, allow override with warning
Troubleshooting
"Not authenticated with github.com"
Solution: Connect your GitHub account:
- Click "Propose Changes"
- Follow the OAuth or token flow
- Your token is saved for future contributions
"Build failed. Please fix errors before submitting."
Solution: Fix the TypeScript/build errors:
- Check the error message in the wizard
- Fix the issues in your code
- Click "Run Checks" again
"Timeout waiting for fork to be created"
Solution: The Git host is slow to create your fork:
- Wait a moment and try again
- Check if the fork exists on the Git host website
- If it exists, the next attempt should succeed
"Failed to push"
Solution: Check your permissions:
- Verify your token has write access
- Make sure the token hasn't expired
- Try disconnecting and reconnecting your account
"No remote repository found"
Solution: This project isn't connected to Git:
- Clone a project from GitHub/GitLab
- Or initialize the project with a Git remote
- Then you can propose changes
Privacy & Data
- Local storage only: All tokens and settings are stored in your browser's IndexedDB
- No tracking: Shakespeare doesn't track your contributions or activity
- No server storage: Your code and tokens never touch Shakespeare servers
- Revocable: Delete tokens anytime from Settings → Git
Future Enhancements
Planned features:
- Draft PRs
- PR templates
- Custom branch naming patterns
- Conflict resolution UI
- Multi-commit PRs
- Review request suggestions
- Automated changelog generation
- Integration with CI/CD status