本文整理向openstack社區提交代碼的基本流程,以及社區一些介紹資料。如有轉載,請注明出處!
先放張圖說明一下OpenStack的code review的大體流程:
對OpenStack提交代碼更改的流程主要如下:
- 配置Git與Gerrit環境
- 克隆目標項目的代碼並在新branch上進行更改
- commit到本地的repo后推送給遠端Gerrit,然后由reviewer給出意見
- 根據reviewer的修改意見不斷更新patch
其中OpenStack使用Gerrit作為代碼review系統,使用Jenkins系統對代碼進行自動測試,使用tox工具可以在本地進行相同的代碼測試。
基本前提
- 創建一個Launchpad賬號(Gerrit使用Launchpad進行SSO)
- 登錄Gerrit,完成基本配置
- 加入OpenStack基金會
- 簽署Contributor License Agreement
- 安裝 Git 和 git review
本文所有操作在Ubuntu Server 14.04 LTS上進行
配置Git
首先配置Git命令行工具,便於以后的操作
$ git config --global user.name 'YourName' $ git config --global user.email example@example.com $ git config --global gitreview.username YourName
如果需要查看Git的配置:
$ gir config --list
安裝配置Git-Review
1. git-review工具是一組Git子命令,主要用於和OpenStack的代碼review系統Gerrit交互,git-review和Gerrit的交互是一組Git命令,在每個git review命令后添加-v選項可以打印所有運行的Git命令。
$ sudo apt-get install git-review
2. 在你要提交代碼的機器上生成一個SSH key:
$ ssh-keygen –t rsa
如果創建RSA密鑰時設置了口令,該口令需要妥善保管,因為以后每一次提交都需要驗證該口令。
3. 查看公鑰部分並將其復制到git-review:
$ less ~/.ssh/id_rsa.pub
將公鑰部分的內容添加到git-review即可。
在本地克隆代碼庫
- 克隆源碼
$ git clone https://github.com/openstack/YourTargetProjectName.git
- 進入到克隆后的目錄
$ cd YourTargetProjectName
- 建立git review 環境
$ git review -s This repository is now set up for use with git-review. You can set the default username for future repositories with: git config --global --add gitreview.username yourgerritusername
- 可以在Git中設置Gerrit/Launchpad的用戶名,
$ git config --global --add gitreview.username YourName
- check out 到master分支,更新遠端並將其pull到本地的master分支
$ git checkout master; git remote update; git pull origin master
6. 在Launchpad上report 一個新的bug, 或者找一個尚未被解決的bug然后將它assign給自己,將bug的狀態改為In progress, OpenStack使用Launchpad記錄Blueprints和報告bugs。
7. 想要fix某個bug,就必須新建一個分支,然后在這個分支里對源代碼進行修改,例如:
$ git checkout -b fix-bug-#123456
- 上述命令創建並切換到新分支“fix-bug-#123456”,接下來所有的本地工作在這個分支里進行,直到所有fixation都完成后再commit,
$ git commit -a
提交時會要求輸入commit message,commit message可以有下面的字段:
Implements: blueprint BLUEPRINT
Closes-Bug: #123456
Partial-Bug: #123456
Related-Bug: #123456
通過這些字段來標識自己工作相關的bug或者blueprint,一旦注明,CI系統會自動將你的commit和相同ID的bug對應起來。
- 上面的命令提交到本地repo后接下來就是push到Gerrit了。
$ git review -v
Gerrit是OpenStack遠端Git倉庫的一道大門,所有的submission都要在這里經過review后才能被merge到master分支中,因此之前的工作一定不能在master分支進行,這樣會產生一個merge commit,Gerrit默認是不接受merge commit的。
如果提交成功,Gerrit將返回一個顯示你此次提交內容的URL,打開它就可以查看commit以及reviewer的評價了:http://review.openstack.org/nnnnnn
如果需要修改commit怎么辦?
此時需要到http://review.openstack.org上查找自己的patch記錄,然后記下這一個patch的review number,就是review.openstack.org對應patch頁面的后幾位數字:https://review.openstack.org/#/c/nnnnnn/
$ cd ourTargetProjectName #切換到項目源碼目錄
$ git review -d nnnnnn #把patch給check out,然后就可以編輯了
接着根據reviewer們的意見重新編輯patch,然后提交
$ git commit -a --amend #在本地commit
$ git review
對上一次的commit進行了修改,或者commit message沒有寫標准,都可以重新提交commit,但是一定要切換到自己上次提交commit的分支執行上面的命令。如果希望查看完整的git命令流,可以在git review命令后添加 -v選項。
2015-04-01 12:24:50.927128 Running: git log --color=never --oneline HEAD^1..HEAD 2015-04-01 12:24:50.930189 Running: git remote 2015-04-01 12:24:50.932609 Running: git branch -a --color=never 2015-04-01 12:24:50.935309 Running: git rev-parse --show-toplevel --git-dir 2015-04-01 12:24:50.937601 Running: git remote update gerrit Fetching gerrit 2015-04-01 12:25:04.406800 Running: git rebase -i remotes/gerrit/master 2015-04-01 12:25:04.507110 Running: git reset --hard ORIG_HEAD 2015-04-01 12:25:04.514952 Running: git config --get color.ui 2015-04-01 12:25:04.517383 Running: git log --color=always --decorate --oneline HEAD --not remotes/gerrit/master -- 2015-04-01 12:25:04.523654 Running: git branch --color=never 2015-04-01 12:25:04.526527 Running: git log HEAD^1..HEAD Using local branch name "fix-bug-123456" for the topic of the change submitted 2015-04-01 12:25:04.530764 Running: git push gerrit HEAD:refs/publish/master/fix-bug-123456 remote: Processing changes: updated: 1, refs: 1, done remote: (W) 81a1233: commit subject >65 characters; use shorter first paragraph remote: (W) 81a1233: no files changed, message updated To ssh://YourName@review.openstack.org:29418/openstack/TargetProject.git * [new branch] HEAD -> refs/publish/master/fix-bug-123456 2015-04-01 12:25:11.126958 Running: git rev-parse --show-toplevel --git-dir
一些Troubleshoot,
如果配置Git或Gerrit的過程中遇到了問題,https://wiki.openstack.org/wiki/Documentation/HowTo/FirstTimers的最后提供了常見問題的troubleshoot,可以參考。
OpenStack的Commit Message風格,
這里對於每一次提交commit時commit message的風格有一定的介紹:https://wiki.openstack.org/wiki/GitCommitMessages
OpenStack的bug分流,
這里有OpenStack對不同程度的bug進行分流的介紹:https://wiki.openstack.org/wiki/BugTriage
OpenStack的bug分類,
OpneStack根據狀態、重要程度等指標對Bug進行分類:https://wiki.openstack.org/wiki/Bugs
OpenStack的blueprints,
WIKI介紹:https://wiki.openstack.org/wiki/Blueprints
Launchpad上的OpenStack項目首頁:https://blueprints.launchpad.net/openstack
OpenStack所有項目的Spec,
specifications記錄了每個項目的設計規范,這里是所有項目的Specs:http://specs.openstack.org/
OpenStack的發行周期,
這里是關於發行周期的一些介紹,https://wiki.openstack.org/wiki/ReleaseCycle
所有OpenStack項目的分支tar包:http://tarballs.openstack.org/
OpenStack代碼分支模型,
這里是代碼分支模型的介紹,https://wiki.openstack.org/wiki/Branch_Model