ROS小课堂gerrit代码审核系统简明教程
0x00 Gerrit系统介绍
Gerrit是一种免费、开放源代码的代码审查软件,使用网页浏览器,在同一项目同一个团队中的软件程序员,可以相互审阅彼此修改后的程序代码,决定是否能够提交,退回或者继续修改。算是大家提交代码到git服务器项目master主分支前的一道防火墙,所有提交的代码先会被gerrit系统拦截下来,只有经过review过的代码才能够合并到master主分支上,这样就可以在一定程度上保证提交代码的质量。
0x01 Gerrit系统登录
目前要想登录gerrit系统需要先给ROS小课堂打赏30块后才会得到登陆帐号,因为只有登录的用户才有权限来提交代码,当然不会免费让大家辛苦来解决bug提交代码的,现在拟定解决一个bug会得到1-3块钱的报酬,理论上大家只要解决10个bug就能把打赏的钱赚回去了,如果解决更多的bug这样还能多赚。现在之所以需要大家打赏、解决bug提交代码、review代码是为了提高大家参与开源项目的积极性,不然大家从github上都是直接git clone代码,然后就在一边冷冷的参观整个项目的开发进展,我认为这样不能很好的提高大家的coding能力,只有自己亲自参与到项目开发中才能切实的体会到整个项目开发流程,与此同时coding能力也会同步提升,顺便还能得到一点点报酬何乐而不为!当然如果有匿名用户不想参与到整个项目的开发流程中,只是单纯的想下载代码看看学习也是可以的,目前ROS小课堂已经将两轮小车mrobot的代码放到服务器上开源了,所有小伙伴都可以下载来看,如果要想参与到项目开发流程中就需要帐号登陆了,直接在终端中输入下面的命令即可下载:git clone http://www.corvin.cn:8081/gerrit/mrobot_ws 这次提交的代码是两轮小车的代码,接下来会开源三轮全向移动小车代码:下面是整个流程,首先clone下来整个项目代码,然后进入项目目录中,直接catkin_make即可编译整个项目,目前该代码在树莓派和x86的kinetic和indigo版本都经过编译测试,可以正常编译,如果编译中有任何问题请在公众号中给我发消息留言!
corvin@workspace:~/project$ git clone http://www.corvin.cn:8081/gerrit/mrobot_ws Cloning into 'mrobot_ws'... remote: Counting objects: 185, done remote: Finding sources: 100% (185/185) remote: Total 185 (delta 50), reused 185 (delta 50) Receiving objects: 100% (185/185), 35.09 MiB | 245.00 KiB/s, done. Resolving deltas: 100% (50/50), done. Checking connectivity... done. corvin@workspace:~/project$ ls mrobot_ws corvin@workspace:~/project$ cd mrobot_ws/ corvin@workspace:~/project/mrobot_ws$ ls src corvin@workspace:~/project/mrobot_ws$ catkin_make Base path: /home/corvin/project/mrobot_ws Source space: /home/corvin/project/mrobot_ws/src Build space: /home/corvin/project/mrobot_ws/build Devel space: /home/corvin/project/mrobot_ws/devel Install space: /home/corvin/project/mrobot_ws/install Removing symlink "/home/corvin/project/mrobot_ws/src/CMakeLists.txt" which points to non-existing file Creating symlink "/home/corvin/project/mrobot_ws/src/CMakeLists.txt" pointing to "/opt/ros/indigo/share/catkin/cmake/toplevel.cmake" #### #### Running command: "cmake /home/corvin/project/mrobot_ws/src -DCATKIN_DEVEL_PREFIX=/home/corvin/project/mrobot_ws/devel -DCMAKE_INSTALL_PREFIX=/home/corvin/project/mrobot_ws/install -G Unix Makefiles" in "/home/corvin/project/mrobot_ws/build" #### -- The C compiler identification is GNU 4.8.4 -- The CXX compiler identification is GNU 4.8.4 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Using CATKIN_DEVEL_PREFIX: /home/corvin/project/mrobot_ws/devel -- Using CMAKE_PREFIX_PATH: /opt/ros/indigo -- This workspace overlays: /opt/ros/indigo -- Found PythonInterp: /usr/bin/python (found version "2.7.6") -- Using PYTHON_EXECUTABLE: /usr/bin/python -- Using Debian Python package layout -- Using empy: /usr/bin/empy -- Using CATKIN_ENABLE_TESTING: ON -- Call enable_testing() -- Using CATKIN_TEST_RESULTS_DIR: /home/corvin/project/mrobot_ws/build/test_results -- Looking for include file pthread.h -- Looking for include file pthread.h - found -- Looking for pthread_create -- Looking for pthread_create - not found -- Looking for pthread_create in pthreads -- Looking for pthread_create in pthreads - not found -- Looking for pthread_create in pthread -- Looking for pthread_create in pthread - found -- Found Threads: TRUE -- Found gtest sources under '/usr/src/gtest': gtests will be built -- Using Python nosetests: /usr/bin/nosetests-2.7 -- catkin 0.6.19 -- BUILD_SHARED_LIBS is on -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- ~~ traversing 9 packages in topological order: -- ~~ - mrobot (metapackage) -- ~~ - mrobot_slam -- ~~ - startup -- ~~ - mrobot_teleop -- ~~ - mrobot_description -- ~~ - rplidar_ros -- ~~ - mrobot_bringup -- ~~ - mrobot_navigation -- ~~ - voice_system -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- +++ processing catkin metapackage: 'mrobot' -- ==> add_subdirectory(mrobot/mrobot) -- +++ processing catkin package: 'mrobot_slam' -- ==> add_subdirectory(mrobot/mrobot_slam) -- +++ processing catkin package: 'startup' -- ==> add_subdirectory(mrobot/startup) -- +++ processing catkin package: 'mrobot_teleop' -- ==> add_subdirectory(mrobot/mrobot_teleop) -- +++ processing catkin package: 'mrobot_description' -- ==> add_subdirectory(mrobot/mrobot_description) -- +++ processing catkin package: 'rplidar_ros' -- ==> add_subdirectory(mrobot/rplidar_ros) -- +++ processing catkin package: 'mrobot_bringup' -- ==> add_subdirectory(mrobot/mrobot_bringup) -- Using these message generators: gencpp;genlisp;genpy -- +++ processing catkin package: 'mrobot_navigation' -- ==> add_subdirectory(mrobot/mrobot_navigation) -- Using these message generators: gencpp;genlisp;genpy -- +++ processing catkin package: 'voice_system' -- ==> add_subdirectory(voice_system) -- Configuring done -- Generating done -- Build files have been written to: /home/corvin/project/mrobot_ws/build #### #### Running command: "make -j8 -l8" in "/home/corvin/project/mrobot_ws/build" #### Scanning dependencies of target mrobot_teleop_joystick Scanning dependencies of target mrobot_bringup_node Scanning dependencies of target rplidarNode Scanning dependencies of target rplidarNodeClient Scanning dependencies of target xf_tts_node [ 11%] [ 22%] [ 33%] [ 44%] [ 55%] [ 66%] Building CXX object voice_system/CMakeFiles/xf_tts_node.dir/src/xf_tts.cpp.o Building CXX object mrobot/mrobot_teleop/CMakeFiles/mrobot_teleop_joystick.dir/src/mrobot_teleop_joystick.cpp.o Building CXX object mrobot/rplidar_ros/CMakeFiles/rplidarNodeClient.dir/src/client.cpp.o [ 77%] Building CXX object mrobot/rplidar_ros/CMakeFiles/rplidarNode.dir/sdk/src/arch/linux/net_serial.cpp.o Building CXX object mrobot/rplidar_ros/CMakeFiles/rplidarNode.dir/sdk/src/arch/linux/timer.cpp.o Building CXX object mrobot/rplidar_ros/CMakeFiles/rplidarNode.dir/src/node.cpp.o Building CXX object mrobot/rplidar_ros/CMakeFiles/rplidarNode.dir/sdk/src/hal/thread.cpp.o [ 88%] Building CXX object mrobot/mrobot_bringup/CMakeFiles/mrobot_bringup_node.dir/src/serial_node.cpp.o [100%] Building CXX object mrobot/rplidar_ros/CMakeFiles/rplidarNode.dir/sdk/src/rplidar_driver.cpp.o Linking CXX executable /home/corvin/project/mrobot_ws/devel/lib/rplidar_ros/rplidarNodeClient Linking CXX executable /home/corvin/project/mrobot_ws/devel/lib/voice_system/xf_tts_node Linking CXX executable /home/corvin/project/mrobot_ws/devel/lib/rplidar_ros/rplidarNode /usr/bin/ld: skipping incompatible /home/corvin/project/mrobot_ws/src/voice_system/lib/libmsc.so when searching for -lmsc [100%] Built target rplidarNodeClient [100%] Built target xf_tts_node [100%] Built target rplidarNode Linking CXX executable /home/corvin/project/mrobot_ws/devel/lib/mrobot_teleop/mrobot_teleop_joystick [100%] Built target mrobot_teleop_joystick Linking CXX executable /home/corvin/project/mrobot_ws/devel/lib/mrobot_bringup/mrobot_bringup_node [100%] Built target mrobot_bringup_node
介绍完匿名用户如何下载代码后接下来介绍有帐号的用户如何登录gerrit系统,下面使用测试帐号test来做演示整个登录流程:当成功登录后会出现如下截图:当点击注册邮箱后,在自己的邮箱中会收到确认的邮件,如下图所示:下面来介绍如何添加ssh的public key,如下图所示:
0x02 配置本地git
配置本地的git是为提交代码做准备,当我们在gerrit上使用帐号登陆时由于注册了邮件和用户名,我们需要本地git配置跟gerrit上注册的相同这样才能提交代码,在这里我使用正式的gerrit帐号corvin_zhang来给大家做演示,首先登录gerrit帐号,查看自己帐号的设置信息,如下图所示:接下来我们来设置本地的git配置信息,里面的用户名和邮件地址需要根据自己的gerrit帐号来设置,打开终端如下图所示:
0x03 gerrit用户下载代码
使用帐号密码登录Gerrit后在Projects-->List, 选择相应工程mrobot_ws,进入该工程的General界面,选中“clone with commit-msg hook”和“SSH”,拷贝以上命令在自己本地终端中执行即可拉取mrobot_ws库代码。
0x04 修改并提交代码
我们通过修改一个简单的问题来演示如何修改代码并提交代码,这里我在mrobot_bringup的启动mrobot_mini.launch文件中,一启动就自动的加载科大讯飞在线语音合成节点,具体的修改过程如下:修改完代码后,准备将修改的代码提交至gerrit中,具体操作如下图所示:
0x05 在gerrit中review代码
所有提交的代码首先都会到达gerrit中,管理员会发现所有的代码提交请求,然后我会指派给相应人员来review这次代码,当相应reviewer同意本次代码提交后就会自动的合并到master分支上了,这次代码提交过程就结束了,具体操作如下图所示:
0x06 更新代码
当服务器上有新提交的代码时,项目组其他成员就需要将本地的代码与服务器上同步,直接通过git pull origin master即可,如下图所示:
0x07 问题反馈
由于本人能力有限,如果大家在此过程中有任何问题,可以直接给我评论或者可以关注ROS小课堂的官方微信公众号,在公众号中给我发消息,我基本上每天都会处理公众号中的留言!当然,如果你要是顺便给ROS小课堂打个赏,我也会感激不尽的!