Github Contribution
by @linux2010
GitHub开源项目代码贡献完整工作流程。使用场景:当需要为开源项目解决issue或bug时,提供从fork、同步、开发到提交PR的完整指导。包含Chrome浏览器PR提交支持。
clawhub install github-contribution📖 About This Skill
GitHub Contribution Skill
Purpose
Automated GitHub contribution workflow that handles fork synchronization, branch creation, and PR submission while maintaining clean fork state.Core Features
1. Fork Protection & Synchronization
2. Automated Contribution Workflow
3. Safety Measures
Usage
Basic Command
./github-contribution.sh [projects-root]
Examples
# Fix issue #123 in openclaw/openclaw
./github-contribution.sh Linux2010 openclaw/openclaw 123 fix/issue-descriptionSpecify custom project root
./github-contribution.sh Linux2010 openclaw/openclaw 456 fix/bug-fix /custom/path
Fork Protection Best Practices
Main Branch Rules
1. Never commit directly to fork's main branch 2. Always sync first before creating new branches 3. Use feature branches for all development work 4. Regular cleanup of local pollution filesSafe Synchronization Script
#!/bin/bash
sync-fork.sh - Safe fork synchronization
git checkout main
git fetch upstream
git reset --hard upstream/main
git clean -fdx # Remove all untracked files
Verify clean state
if [[ $(git status --porcelain) ]]; then
echo "❌ Warning: Working tree not clean"
exit 1
fi
echo "✅ Fork synchronized successfully"
Local Git Configuration
# Prevent accidental main branch pushes
git config branch.main.pushRemote no_pushSet safe push default
git config push.default nothing
Workflow Steps
Step 1: Fork Validation
Step 2: Synchronization
Step 3: Feature Branch Creation
Step 4: PR Creation
🩺 Bug Fix Module: Change Plan
Before fixing any bug, always write a change plan first. This ensures minimal, safe changes and makes PR review easier.
The 5-Point Analysis
Answer these 5 questions in plain language before writing any code:
| # | Question | Purpose | |---|----------|---------| | 1 | Observed behavior | What's broken? (What the user sees) | | 2 | Expected behavior | What should happen? (Correct behavior) | | 3 | Suspected root cause | Where's the bug? (Specific code location) | | 4 | Safest seam to modify | Minimal change location? (Narrowest fix) | | 5 | Risk surface | What else could break? (Impact scope) |
Change Plan Template
## Change Plan for Issue #1. Observed behavior:
2. Expected behavior:
3. Suspected root cause:
4. Safest seam to modify:
5. Risk surface:
Example: Issue #5968
## Change Plan for Issue #59681. Observed behavior:
extract_content_or_reasoning() crashes when response.choices is None, missing, or empty list.
2. Expected behavior:
Function should return empty string gracefully when no usable choices exist.
3. Suspected root cause:
Line msg = response.choices[0].message in agent/auxiliary_client.py assumes choices is always non-empty.
4. Safest seam to modify:
Add a guard at the top of extract_content_or_reasoning() before accessing choices:
if not getattr(response, "choices", None): return ""
5. Risk surface:
Minimal - only affects edge cases where API response is malformed.
When to Use Change Plan
| Scenario | Required? | |----------|-----------| | Bug fix | ✅ Always | | Paper-cut UX improvement | ✅ Always | | Feature addition | ❌ Use feature spec instead | | Refactoring | ❌ Use refactor plan instead | | Documentation fix | ❌ Not needed |
Benefits of Change Plan
| Benefit | Why It Matters | |---------|----------------| | Forces understanding | Can't fix what you don't understand | | Defines boundaries | Prevents scope creep and "opportunistic" changes | | Reduces risk | Identifies potential side effects upfront | | Speeds review | Maintainer can understand intent in 20 seconds | | Enables rollback | Clear what was changed and why |
Change Plan Checklist
Before coding:
If you answered "no" to any question, do more investigation before coding.
Error Handling
Common Issues & Solutions
#### Fork Not Clean
#### Permission Denied (Workflow Scope)
#### Upstream Not Configured
#### Branch Already Exists
Security Considerations
Token Permissions
repo scopeworkflow scope (for full automation)Local Security
Integration with Other Skills
PR Advocacy Skill
Document Spell Check Skill
High-Quality PR Best Practices (Maximize Merge Success Rate)
🎯 Merge Success Rate Formula (Based on 30+ Merged PRs Analysis)
Merge Success Rate =
(PR Description Completeness × 0.2) +
(Review Response Speed × 0.25) +
(Test Coverage × 0.2) +
(Conflict Resolution Status × 0.15) +
(Review Resolution Rate × 0.2)
Target: > 80% success rate
✅ 10 Success Characteristics (Must Follow 100%)
1. ✅ Complete PR Description - Use template, fill ALL required fields 2. ✅ Fast Review Response - < 30 minutes average response time 3. ✅ Small Focused Commits - 1 commit solves 1 problem 4. ✅ 100% Test Coverage - Include edge cases and regression tests 5. ✅ Zero Conflicts - Daily rebase upstream, keep CLEAN 6. ✅ Changelog Updated - All user-visible changes 7. ✅ Security Checklist - 5 required security questions 8. ✅ Human Verification Statement - Manual test content + untested areas 9. ✅ Review Conversations Resolved - 100% resolve bot review comments 10. ✅ Rollback Plan - Rollback steps + known issues
📋 Pre-Submission Checklist
Before pushing PR:
Code Quality:
type(scope): descriptionCI Pre-flight (MUST pass locally):
pnpm protocol:check - Protocol validationpnpm test - All tests passpnpm lint - No lint errorspnpm tsc --noEmit - TypeScript compilationReview Readiness:
📊 High Success Rate PR Patterns
#### Pattern 1: Security Fix Response (vincentkoc #44437)
7 commits in same day:
1. Main fix implementation
2. Changelog update
3. Merge main (resolve conflicts)
4. Tests: add coverage for review comments
5. Fix: address Greptile suggestions
6. Extra hardening (defensive programming)
7. Merge main (final sync)
Key Learnings:
#### Pattern 2: Security Report Response (gumadeiras #44176)
When Aisle Security reports issues:1. Quote SECURITY.md to explain why it's out of scope
2. But still fix it (defensive programming)
3. List specific hardening done
4. Provide verification commands
Key Learnings:
⚠️ Common Mistakes That Reduce Merge Rate
| Mistake | Impact | Solution | |---------|--------|----------| | ❌ Missing Changelog | -20% | Always update CHANGELOG.md | | ❌ Slow review response (>24h) | -25% | Respond within 24h, ideally <30min | | ❌ Incomplete test coverage | -20% | Add tests for edge cases | | ❌ Merge conflicts | -15% | Daily rebase upstream | | ❌ Unresolved bot reviews | -20% | 100% resolve all comments | | ❌ CI failures | Automatic reject | Pre-flight check locally |
🎯 Quality Metrics
| Metric | Target | Current Best Practice | |--------|--------|----------------------| | Greptile Score | ≥ 4/5 | Address all P1/P2 issues | | Aisle Security | 0 unresolved | Respond or fix all | | Test Coverage | ≥ 1 new test | Include edge cases | | CI Pass Rate | 100% | Pre-check locally | | Behind upstream | 0 commits | Daily rebase | | Response Time | < 24h | Same day preferred |
📝 PR Template Best Practices
Title Format:
✅ fix(hooks): fail closed on unreadable loader paths
✅ feat(context-engine): plumb sessionKey into all methods
✅ docs: codify American English spelling convention
✅ security: include accountId in session keys
Commit Message Structure:
First line: What was done (concise description)Second paragraph: Why (problem background, impact)
Optional: Regeneration-Prompt / AI assistance notes
Example (#44411):
fix(ci): restore generated protocol swift outputsRegenerate the Swift protocol models so PushTestResult keeps the
transport field required by the current gateway schema, and update
protocol:check to diff both generated Swift destinations because
the generator writes both files.
Regeneration-Prompt: |
Investigate the protocol CI failure on current origin/main...
Best Practices
For Contributors
PR Rebase Best Practices (Critical!)
Golden Rule: Always rebase on the original PR branch, never create a new branch.
#### Correct Rebase Workflow
# 1. Confirm current branch
git branch --show-current2. Confirm PR's branch name
gh pr view --json headRefName --jq .headRefName3. Switch to correct branch if needed
git checkout 4. Rebase on the SAME branch (do NOT create new branch)
git fetch upstream
git rebase upstream/main5. Push to the SAME branch
git push -f origin
#### Common Mistakes to Avoid
| ❌ Wrong | ✅ Correct |
|---------|---------|
| git checkout -b new-branch then rebase | Stay on original branch, rebase there |
| Switch to different branch for rebase | Rebase on PR's own branch |
| Skip branch confirmation | Always run git branch --show-current first |
| Don't verify PR branch name | Use gh pr view to confirm |
#### Why This Matters?
1. Clean branch history - No duplicate branches created 2. Avoid confusion - PR always linked to same branch 3. Reduce errors - Won't push to wrong branch 4. Easy management - All changes in one place
#### Pre-Rebase Checklist
Before rebasing:
git branch --show-current to confirm current branchgh pr view --json headRefName to confirm PR branchgit checkout first#### Post-Rebase Checklist
After rebasing:
git log --oneline -3 to verify commitspnpm test or relevant testsgit push -f origin to update PR#### Example: Rebase PR #48568
# Check current branch
$ git branch --show-current
fix/47752-final # ✅ Correct!Confirm PR branch
$ gh pr view 48568 --json headRefName --jq .headRefName
fix/47752-final # ✅ Matches!Rebase on same branch
git fetch upstream
git rebase upstream/mainTest
pnpm test src/infra/heartbeat-runner.timeout.test.tsPush to same branch
git push -f origin fix/47752-final
#### Troubleshooting
Problem: Accidentally created new branch during rebase
Solution:
# Go back to original branch
git checkout Rebase there instead
git rebase upstream/mainDelete the accidental branch
git branch -D Push to original branch
git push -f origin
For Maintainers
Limitations
GitHub Fork Restrictions
Workarounds
Maintenance
Updates
Monitoring
💡 Examples
# Fix issue #123 in openclaw/openclaw
./github-contribution.sh Linux2010 openclaw/openclaw 123 fix/issue-descriptionSpecify custom project root
./github-contribution.sh Linux2010 openclaw/openclaw 456 fix/bug-fix /custom/path
📋 Tips & Best Practices
For Contributors
PR Rebase Best Practices (Critical!)
Golden Rule: Always rebase on the original PR branch, never create a new branch.
#### Correct Rebase Workflow
# 1. Confirm current branch
git branch --show-current2. Confirm PR's branch name
gh pr view --json headRefName --jq .headRefName3. Switch to correct branch if needed
git checkout 4. Rebase on the SAME branch (do NOT create new branch)
git fetch upstream
git rebase upstream/main5. Push to the SAME branch
git push -f origin
#### Common Mistakes to Avoid
| ❌ Wrong | ✅ Correct |
|---------|---------|
| git checkout -b new-branch then rebase | Stay on original branch, rebase there |
| Switch to different branch for rebase | Rebase on PR's own branch |
| Skip branch confirmation | Always run git branch --show-current first |
| Don't verify PR branch name | Use gh pr view to confirm |
#### Why This Matters?
1. Clean branch history - No duplicate branches created 2. Avoid confusion - PR always linked to same branch 3. Reduce errors - Won't push to wrong branch 4. Easy management - All changes in one place
#### Pre-Rebase Checklist
Before rebasing:
git branch --show-current to confirm current branchgh pr view --json headRefName to confirm PR branchgit checkout first#### Post-Rebase Checklist
After rebasing:
git log --oneline -3 to verify commitspnpm test or relevant testsgit push -f origin to update PR#### Example: Rebase PR #48568
# Check current branch
$ git branch --show-current
fix/47752-final # ✅ Correct!Confirm PR branch
$ gh pr view 48568 --json headRefName --jq .headRefName
fix/47752-final # ✅ Matches!Rebase on same branch
git fetch upstream
git rebase upstream/mainTest
pnpm test src/infra/heartbeat-runner.timeout.test.tsPush to same branch
git push -f origin fix/47752-final
#### Troubleshooting
Problem: Accidentally created new branch during rebase
Solution:
# Go back to original branch
git checkout Rebase there instead
git rebase upstream/mainDelete the accidental branch
git branch -D Push to original branch
git push -f origin