• Gerrit 与 SSH command line tools


    我们以通过ssh上传我们的代码修改,Gerrit 支持两种形式的身份验证:用户的公钥或 kerberos

    【注册公钥

    如果要注册新的 SSH 密钥以与 Gerrit 一起使用, 要将id_rsa.pub 或 id_dsa.pub文件的内容粘贴到Settings的SSH Public Keys文本框中,然后单击“Add”按钮。如果文件内容不存在,可以创建一个新密钥。

    1. ssh-keygen -t rsa
    2. cat ~/.ssh/id_rsa.pub

    【配置Kerberos】

    Ubuntu在本地 SSH 配置中使用以下条目为 Gerrit 启用它:

    1. Host gerrit.mydomain.tld
    2. GSSAPIAuthentication yes

    【测试链接】

    ssh -p 29418 username@gerritlocalhost

    29418是Gerrit的运行端口。如果不清楚,可以访问获取

    1. curl http://gerritlocalhost/ssh_info
    2. gerritlocalhost 29418

    经常需要上传的话,考虑添加 Gerrit 服务器到SSH Host添加到OpenSSH 客户端的配置文件(~/.ssh/config)中。如果需要开发一个自动化工具来执行向 Gerrit 的上传,推荐使用ssh来执行。

    1. cat ~/.ssh/config
    2. # ...
    3. # Host gerritlocalhost
    4. # Hostname gerritlocalhost
    5. # Port 29418
    6. # User yourname

    Command Line Tools

    由于 Gerrit 不提供交互式 shell,因此必须从 ssh 客户端触发命令,可协助自动化开发:link

    1. ssh -p 29418 username@gerritlocalhost gerrit –help
    2. gerrit [COMMAND] [ARG ...] [--] [--help (-h)]
    3. -- : end of options
    4. --help (-h) : display this help text
    5. Available commands of gerrit are:
    6. apropos Search in Gerrit documentation
    7. ban-commit Ban a commit from a project's repository
    8. close-connection Close the specified SSH connection
    9. create-account Create a new batch/role account
    10. create-branch Create a new branch
    11. create-group Create a new account group
    12. create-project Create a new project and associated Git repository
    13. flush-caches Flush some/all server caches from memory
    14. gc Run Git garbage collection
    15. gsql Administrative interface to active database
    16. index
    17. logging
    18. ls-groups List groups visible to the caller
    19. ls-members List the members of a given group
    20. ls-projects List projects visible to the caller
    21. ls-user-refs List refs visible to a specific user
    22. plugin
    23. query Query the change database
    24. receive-pack Standard Git server side command for client side git push
    25. rename-group Rename an account group
    26. review Apply reviews to one or more patch sets
    27. set-account Change an account's settings
    28. set-head Change HEAD reference for a project
    29. set-members Modify members of specific group or number of groups
    30. set-project Change a project's settings
    31. set-project-parent Change the project permissions are inherited from
    32. set-reviewers Add or remove reviewers on a change
    33. show-caches Display current cache statistics
    34. show-connections Display active client SSH connections
    35. show-queue Display the background work queues
    36. stream-events Monitor events occurring in real time
    37. test-submit
    38. version Display gerrit version

    举例:

    1. ​# 查看某条提交的详细信息
    2. ssh -p 29418 username@gerritlocalhost gerrit query change:<GerritID>
    3. # 查看GerritID change提交到的project&&branch信息::
    4. ssh -p 29418 username@gerritlocalhost gerrit query change:<GerritID> | grep "project" | awk -F ": " '{print$2}'
    5. ssh -p 29418 username@gerritlocalhost gerrit query change:<GerritID> | grep "branch" | awk -F ": " '{print$2}'
    6. # 针对Iac6b2ac2 change 添加reviewer alice和bob 并删除reviewer eve
    7. ssh -p 29418 review.example.com gerrit set-reviewers \
    8. -a alice@example.com -a bob@example.com -r eve@example.com Iac6b2ac2
    9. # 针对Iac6b2ac2 change 添加所有的project owners为reviewer
    10. ssh -p 29418 review.example.com gerrit set-reviewers -a "'Project Owners'" Iac6b2ac2
    11. # 再myproject 的特定的1935 change 添加eve作为reviewer????
    12. ssh -p 29418 review.example.com gerrit set-reviewers --project myproject -a eve@example.com 1935
    13. # verity +1命令:
    14. ssh -p 29418 username@gerritlocalhost gerrit review --verified +1 -m "......" <GerritID>,<PATCHSET_NUM>
    15. # SLTApproved: --sltapproved +1
    16. # SME granted: --sme-granted +1
    17. # Submit approved: --sumbit-approved +1
    18. # code review:--code-review +2
    19. # abandon change:--abandon
    20. # delete:--delete
    21. #添加comment信息:
    22. ssh -p 29418 username@gerritlocalhost gerrit review -m '"......"' <GerritID>,<PATCHSET_NUM>
    23. # 添加tag: --tag or -t
    24. # 将分支“master”上“MyProject”中的更改“I6686e64a788365bd252df69ae5b3ec9d65aaf068”的主题设置为“MyTopic”。
    25. ssh -p 29418 username@gerritlocalhost gerrit set-topic MyProject~master~I6686e64a788365bd252df69ae5b3ec9d65aaf068 --topic MyTopic
    26. # 查看所有匹配 tools的项目名:
    27. ssh -p 29418 gerritlocalhost gerrit ls-projects --match "tools"
    28. # ssh -p 29418 username@gerritlocalhost gerrit ls-projects
    29. # 等效于:curl http://gerritlocalhost/projects/
    30. # 添加forest:curl http://gerritlocalhost/projects/tools
    31. # 跳过2条,查询tools/gerrit库的待合入2条changes:
    32. ssh -p 29418 username@gerritlocalhost gerrit query --format=JSON status:open project:tools/gerrit limit:2 --start 2
    33. # 从项目“myproject”的“master”分支或者f06124a这个revision切出,创建一个名为“newbranch”的新分支。
    34. ssh -p 29418 gerritlocalhost gerrit create-branch myproject newbranch master
    35. ssh -p 29418 gerritlocalhost gerrit create-branch myproject newbranch f06124a
    36. # 查看ssh连接数(可用于查看有多少人在做代码拉取或推送操作,有利于判断服务器的压力):
    37. ssh -p 29418 username@gerritlocalhost gerrit show-queue -w
    38. # 查看所有缓存(分析服务器缓存情况):
    39. ssh -p 29418 username@gerritlocalhost gerrit show-caches
    40. # 查看可刷新缓存(更新数据):
    41. ssh -p 29418 username@gerritlocalhost gerrit flush-caches --list
    42. # 刷新指定缓存——项目列表:
    43. ssh -p 29418 username@gerritlocalhost gerrit flush-caches --cache projects
    44. # 设置项目合并commit方式(merge->rebase)
    45. ssh -p 29418 username@gerritlocalhost gerrit set-project example --submit-type REBASE_IF_NECESSARY
    46. # 针对myproject代码库需要更改ID时候,选择rebase方式合并
    47. ssh -p 29418 gerritlocalhost gerrit set-project myproject --submit-type MERGE_IF_NECESSARY --change-id true --content-merge false --project-state HIDDEN

    参考链接:

    https://gerrit-review.googlesource.com/Documentation/cmd-index.html

  • 相关阅读:
    企业架构LNMP学习笔记25
    C#Word上传和转成Pdf实现
    python的常用random库
    海思3559万能平台搭建:串口编程
    R-CNN 详解
    【洛谷 P1478】陶陶摘苹果(升级版)题解(多重集合+贪心算法)
    【汇编 C++】多态底层---虚表、__vfptr指针
    外文论文的格式规范要求有哪些?
    TSINGSEE智慧加油站可视化监管与风险预警方案
    Dockerfile(基于jdk17)
  • 原文地址:https://blog.csdn.net/Solei_sun/article/details/132581328