“贡献工作流程”
本指南将引导您完成为 XOOPS 做出贡献的完整过程,从初始设置到合并拉取请求。
在开始贡献之前,请确保您拥有:
- Git 安装并配置
- GitHub 帐户(免费)
- PHP 7.4+ 用于XOOPS 开发
- Composer 用于依赖管理
- Git 工作流程的基础知识
- 熟悉行为准则
步骤 1:分叉存储库
Section titled “步骤 1:分叉存储库”在 GitHub Web 界面上
Section titled “在 GitHub Web 界面上”- 导航到存储库(例如,
XOOPS/XOOPSCore27) - 单击顶部-right角的 Fork 按钮
- 选择分叉位置(您的个人账户) 4.等待fork完成
为什么要分叉?
Section titled “为什么要分叉?”- 您可以使用自己的副本
- 维护者不需要管理许多分支
- 你可以完全控制你的叉子
- 拉取请求引用您的分叉和上游存储库
第 2 步:在本地克隆您的分叉
Section titled “第 2 步:在本地克隆您的分叉”# Clone your fork (replace YOUR_USERNAME)git clone https://github.com/YOUR_USERNAME/XoopsCore27.gitcd XoopsCore27
# Add upstream remote to track original repositorygit remote add upstream https://github.com/XOOPS/XoopsCore27.git
# Verify remotes are set correctlygit remote -v# origin https://github.com/YOUR_USERNAME/XoopsCore27.git (fetch)# origin https://github.com/YOUR_USERNAME/XoopsCore27.git (push)# upstream https://github.com/XOOPS/XoopsCore27.git (fetch)# upstream https://github.com/XOOPS/XoopsCore27.git (nofetch)第三步:搭建开发环境
Section titled “第三步:搭建开发环境”# Install Composer dependenciescomposer install
# Install development dependenciescomposer install --dev
# For module developmentcd modules/mymodulecomposer install配置 Git
Section titled “配置 Git”# Set your Git identitygit config user.name "Your Name"git config user.email "your.email@example.com"
# Optional: Set global Git configgit config --global user.name "Your Name"git config --global user.email "your.email@example.com"# Make sure tests pass in clean state./vendor/bin/phpunit
# Run specific test suite./vendor/bin/phpunit --testsuite unit步骤 4:创建功能分支
Section titled “步骤 4:创建功能分支”分支命名约定
Section titled “分支命名约定”遵循以下模式:<type>/<description>
类型:
feature/- 新功能fix/- 错误修复docs/- 仅文档refactor/- 代码重构test/- 测试补充chore/- 维护、工具
示例:
# Feature branchgit checkout -b feature/add-two-factor-auth
# Bug fix branchgit checkout -b fix/prevent-xss-in-forms
# Documentation branchgit checkout -b docs/update-api-guide
# Always branch from upstream/main (or develop)git checkout -b feature/my-feature upstream/main保持分支最新
Section titled “保持分支最新”# Before you start work, sync with upstreamgit fetch upstreamgit merge upstream/main
# Later, if upstream has changedgit fetch upstreamgit rebase upstream/main第 5 步:进行更改
Section titled “第 5 步:进行更改”- 按照 PHP 标准编写代码
- 为新功能编写测试
- 根据需要更新文档
- 运行 linter 和代码格式化程序
代码质量检查
Section titled “代码质量检查”# Run all tests./vendor/bin/phpunit
# Run with coverage./vendor/bin/phpunit --coverage-html coverage/
# Run PHP CS Fixer./vendor/bin/php-cs-fixer fix --dry-run
# Run PHPStan static analysis./vendor/bin/phpstan analyse class/ src/做出好的改变
Section titled “做出好的改变”# Check what you changedgit statusgit diff
# Stage specific filesgit add class/MyClass.phpgit add tests/MyClassTest.php
# Or stage all changesgit add .
# Commit with descriptive messagegit commit -m "feat(auth): add two-factor authentication support"步骤 6:保持分支同步
Section titled “步骤 6:保持分支同步”在开发您的功能时,主分支可能会前进:
# Fetch latest changes from upstreamgit fetch upstream
# Option A: Rebase (preferred for clean history)git rebase upstream/main
# Option B: Merge (simpler but adds merge commits)git merge upstream/main
# If conflicts occur, resolve them then:git add .git rebase --continue # or git merge --continue第 7 步:推送到你的叉子
Section titled “第 7 步:推送到你的叉子”# Push your branch to your forkgit push origin feature/my-feature
# On subsequent pushesgit push
# If you rebased, you might need force push (use carefully!)git push --force-with-lease origin feature/my-feature步骤 8:创建拉取请求
Section titled “步骤 8:创建拉取请求”在 GitHub Web 界面上
Section titled “在 GitHub Web 界面上”- 转到 GitHub 上的分支
- 您将看到一条从您的分支创建 PR 的通知
- 点击**“比较并拉取请求”**
- 或者手动点击**“新拉取请求”**并选择您的分支
PR 标题和描述
Section titled “PR 标题和描述”标题格式:
<type>(<scope>): <subject>示例:
feat(auth): add two-factor authenticationfix(forms): prevent XSS in text inputdocs: update installation guiderefactor(core): improve performance描述模板:
## DescriptionBrief explanation of what this PR does.
## Changes- Changed X from A to B- Added feature Y- Fixed bug Z
## Type of Change- [ ] New feature (adds new functionality)- [ ] Bug fix (fixes an issue)- [ ] Breaking change (API/behavior change)- [ ] Documentation update
## Testing- [ ] Added tests for new functionality- [ ] All existing tests pass- [ ] Manual testing performed
## Screenshots (if applicable)Include before/after screenshots for UI changes.
## Related IssuesCloses #123Related to #456
## Checklist- [ ] Code follows style guidelines- [ ] Self-reviewed own code- [ ] Commented complex code- [ ] Updated documentation- [ ] No new warnings generated- [ ] Tests pass locally公关审查清单
Section titled “公关审查清单”提交之前,请确保:
- 代码遵循 PHP 标准
- 包含测试并通过
- 更新文档(如果需要)
- 无合并冲突
- 提交消息清晰
- 相关问题参考
- PR描述详细
- 无调试代码或控制台日志
步骤 9:回复反馈
Section titled “步骤 9:回复反馈”代码审查期间
Section titled “代码审查期间”- 仔细阅读评论 - 了解反馈
- 提出问题 - 如果不清楚,请要求澄清
- 讨论替代方案 - 尊重地辩论方法
- 进行请求的更改 - 更新您的分支
- 强制-push更新提交 - 如果重写历史记录
# Make changesgit add .git commit --amend # Modify last commitgit push --force-with-lease origin feature/my-feature
# Or add new commitsgit commit -m "Address feedback on PR review"git push origin feature/my-feature- 大多数 PR 需要多轮审核
- 保持耐心和建设性
- 将反馈视为学习机会
- 维护者可能会建议重构
步骤 10:合并和清理
Section titled “步骤 10:合并和清理”一旦维护者批准并合并:
- GitHub auto-merges或维护者点击合并
- 您的分支被删除(通常是自动的)
- 变化发生在上游
# Switch to main branchgit checkout main
# Update main with merged changesgit fetch upstreamgit merge upstream/main
# Delete local feature branchgit branch -d feature/my-feature
# Delete from your fork (if not auto-deleted)git push origin --delete feature/my-featuregraph LR A[Fork Repository] --> B[Clone Fork] B --> C[Create Branch] C --> D[Make Changes] D --> E[Commit & Push] E --> F[Create PR] F --> G{Review} G -->|Approved| H[Merge] G -->|Changes Needed| I[Update PR] I --> G H --> J[Cleanup] J --> K[Done]# Always start freshgit fetch upstreamgit checkout -b feature/new-thing upstream/main添加更多提交
Section titled “添加更多提交”# Just push againgit add .git commit -m "feat: additional changes"git push origin feature/new-thing# Last commit has wrong messagegit commit --amend -m "Correct message"git push --force-with-lease
# Revert to previous state (careful!)git reset --soft HEAD~1 # Keep changesgit reset --hard HEAD~1 # Discard changes处理合并冲突
Section titled “处理合并冲突”# Rebase and resolve conflictsgit fetch upstreamgit rebase upstream/main
# Edit conflicted files to resolve# Then continuegit add .git rebase --continuegit push --force-with-lease做- 让分支机构专注于单一问题
Section titled “做- 让分支机构专注于单一问题”- 进行小的、合乎逻辑的提交
- 编写描述性提交消息
- 经常更新你的分支
- 推动前测试
- 文件变更
- 积极响应反馈
- 直接在main/master分支机构工作
- 在一个 PR 中混合不相关的更改
- 提交生成的文件或node_modules
- PR 公开后强制推送(使用—force-with-lease)
- 忽略代码审查反馈
- 创建巨大的 PR(分解为较小的 PR)
- 提交敏感数据(API密钥、密码)
- 开始工作前在问题中提出问题
- 寻求有关复杂变更的指导
- 讨论 PR 描述中的方法
- 及时回复反馈
- 审查PHP标准
- 检查问题报告指南
- 阅读贡献概述
- 遵循拉取请求指南
- 阅读现有的代码模式
- 研究类似的实现
- 了解架构
- 检查核心概念
- 行为准则
- 拉取请求指南
- 问题报告
- PHP编码标准
- 贡献概述
#XOOPS #git #github #contributing #workflow #pull-request