如何贡献代码和文档

开始之前

github或社区提交问题

欢迎为项目贡献任何代码或文档,但是建议先在github社区上提交一个问题,和大家共同讨论。

签署贡献者许可协议(CLA)

什么是CLA

签署协议链接:vesoft inc. Contributor License Agreement

单击按钮Sign in with GitHub to agree签署协议。

如果有任何问题,请发送邮件至info@vesoft.com

Step 1:通过GitHub fork仓库

Nebula Graph项目有很多仓库,以nebula-graph仓库为例:

  1. 访问https://github.com/vesoft-inc/nebula-graph

  2. 在右上角单击按钮Fork,然后单击用户名,即可fork出nebula-graph仓库。

Step 2:将分支克隆到本地

  1. 定义本地工作目录。

    1. # 定义工作目录。
    2. working_dir=$HOME/Workspace
  2. user设置为GitHub的用户名。

    1. user={GitHub用户名}
  3. 克隆代码。

    1. mkdir -p $working_dir
    2. cd $working_dir
    3. git clone https://github.com/$user/nebula-graph.git
    4. # 或:git clone git@github.com:$user/nebula-graph.git
    5. cd $working_dir/nebula
    6. git remote add upstream https://github.com/vesoft-inc/nebula-graph.git
    7. # 或:git remote add upstream git@github.com:vesoft-inc/nebula-graph.git
    8. # 由于没有写访问权限,请勿推送至上游主分支。
    9. git remote set-url --push upstream no_push
    10. # 确认远程分支有效。
    11. # 正确的格式为:
    12. # origin git@github.com:$(user)/nebula-graph.git (fetch)
    13. # origin git@github.com:$(user)/nebula-graph.git (push)
    14. # upstream https://github.com/vesoft-inc/nebula-graph (fetch)
    15. # upstream no_push (push)
    16. git remote -v

定义pre-commit hook

请将Nebula Graph的pre-commit hook连接到.git目录。

hook将检查commit,包括格式、构建、文档生成等。

  1. cd $working_dir/nebula-graph/.git/hooks
  2. ln -s $working_dir/nebula-graph/.linters/cpp/hooks/pre-commit.sh .

pre-commit hook有时候可能无法正常执行,用户必须手动执行。

  1. cd $working_dir/nebula-graph/.git/hooks
  2. chmod +x pre-commit

Step 3:分支

  1. 更新本地主分支。

    1. cd $working_dir/nebula
    2. git fetch upstream
    3. git checkout master
    4. git rebase upstream/master
  2. 从主分支创建并切换分支:

    1. git checkout -b myfeature

Step 4:开发

代码风格

Nebula Graph采用cpplint来确保代码符合Google的代码风格指南。检查器将在提交代码之前执行。

单元测试要求

请为新功能或Bug修复添加单元测试。

构建代码时开启单元测试

详情请参见使用源码安装Nebula Graph

运行所有单元测试

nebula根目录执行如下命令:

  1. cd nebula/build
  2. ctest -j$(nproc)

Step 5:保持分支同步

  1. # 当处于myfeature分支时。
  2. git fetch upstream
  3. git rebase upstream/master

在其他贡献者将PR合并到基础分支之后,用户需要更新head分支。

Step 6:Commit

提交代码更改:

  1. git commit -a

用户可以使用命令--amend重新编辑之前的代码。

Step 7:Push

需要审核或离线备份代码时,可以将本地仓库创建的分支push到GitHub的远程仓库。

  1. git push origin myfeature

Step 8:创建pull request

  1. 访问fork出的仓库https://github.com/$user/nebula-graph (替换此处的用户名$user)。

  2. 单击myfeature分支旁的按钮Compare & pull request

Step 9:代码审查

pull request创建后,至少需要两人审查。审查人员将进行彻底的代码审查,以确保变更满足存储库的贡献准则和其他质量标准。