devops

gerrit设置必须俩审核人

gerrit安装参考

gerrit安装

gerrit ldap配置

gerrit ldap配置

官网文档:http://giturl/Documentation/prolog-cookbook.html#_example_13_112_code_review

获取工程代码,新增rules.pl

root@lili:~/test# git clone "ssh://zhangsan@192.168.72.135:29418/test" && scp -p -P 29418 zhangsan@192.168.72.135:hooks/commit-msg "test/.git/hooks/"
Cloning into 'test'...
remote: Counting objects: 5, done
remote: Finding sources: 100% (5/5)
remote: Total 5 (delta 0), reused 3 (delta 0)
Receiving objects: 100% (5/5), done.
commit-msg                                                                                                                                                                                                     100% 2272   863.9KB/s   00:00    
root@lili:~/test# ls -l
total 8
drwxr-xr-x 3 root root 4096 Oct 17 13:50 All-Projects
drwxr-xr-x 3 root root 4096 Oct 17 23:40 test
root@lili:~/test# cd test/
#此步骤 执行者必须有访问refs/meta/config权限
由于我是用admin操作的,所以有权限
root@lili:~/test/test# git fetch origin +refs/meta/config:refs/meta/config
remote: Counting objects: 18, done
remote: Finding sources: 100% (18/18)
Unpacking objects: 100% (18/18), 2.12 KiB | 54.00 KiB/s, done.
remote: Total 18 (delta 0), reused 0 (delta 0)
From ssh://192.168.72.135:29418/test
 * [new ref]         refs/meta/config -> refs/meta/config
root@lili:~/test/test# git checkout refs/meta/config
Note: switching to 'refs/meta/config'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
  git switch -c <new-branch-name>
Or undo this operation with:
  git switch -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at 6f5856b Modify access rules
root@lili:~/test/test# ls -l
total 8
-rw-r--r-- 1 root root 104 Oct 17 23:41 groups
-rw-r--r-- 1 root root 150 Oct 17 23:41 project.config
root@lili:~/test/test# vim rules.pl
此规则脚本实现的是 codeviwer 总值必须 >= 4;
增加如下内容
sum_list([], 0).
sum_list([H | Rest], Sum) :- sum_list(Rest,Tmp), Sum is H + Tmp.
add_category_min_score(In, Category, Min,  P) :-
    findall(X, gerrit:commit_label(label(Category,X),R),Z),
    sum_list(Z, Sum),
    Sum >= Min, !,
    gerrit:commit_label(label(Category, V), U),
    V >= 1,
    !,
    P = [label(Category,ok(U)) | In].
add_category_min_score(In, Category,Min,P) :-
    P = [label(Category,need(Min)) | In].
submit_rule(S) :-
    gerrit:default_submit(X),
    X =.. [submit | Ls],
    gerrit:remove_label(Ls,label('Code-Review',_),NoCR),
    add_category_min_score(NoCR,'Code-Review', 4, Labels),
    S =.. [submit | Labels].

root@lili:~/test/test# git add .
root@lili:~/test/test# git commit -am "wulili "
[detached HEAD fe495a0] wulili
 1 file changed, 21 insertions(+)
 create mode 100644 rules.pl
root@lili:~/test/test# git push  origin HEAD:refs/meta/config
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 646 bytes | 53.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: Processing changes: refs: 1, done    
To ssh://192.168.72.135:29418/test
   6f5856b..fe495a0  HEAD -> refs/meta/config

新增change测试

root@lili:~/test/test# git checkout master
Warning: you are leaving 1 commit behind, not connected to
any of your branches:

  fe495a0 wulili

If you want to keep it by creating a new branch, this may be a good time
to do so with:

 git branch <new-branch-name> fe495a0

Switched to branch 'master'
Your branch is up to date with 'origin/master'.
root@lili:~/test/test# ls -l
total 4
-rw-r--r-- 1 root root 3 Oct 17 23:52 file1
root@lili:~/test/test# git pull
remote: Counting objects: 4, done
remote: Finding sources: 100% (3/3)
remote: Total 3 (delta 0), reused 3 (delta 0)
Unpacking objects: 100% (3/3), 277 bytes | 277.00 KiB/s, done.
From ssh://192.168.72.135:29418/test
   36dc951..3af8313  master     -> origin/master
Updating 36dc951..3af8313
Fast-forward
 file2 | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 file2
root@lili:~/test/test# ls -l
total 8
-rw-r--r-- 1 root root 3 Oct 17 23:52 file1
-rw-r--r-- 1 root root 4 Oct 17 23:53 file2
root@lili:~/test/test# echo sds>file3
root@lili:~/test/test# git add .
root@lili:~/test/test# git commit -am "wulili add file3"
[master 4e3dd64] wulili add file3
 1 file changed, 1 insertion(+)
 create mode 100644 file3
root@lili:~/test/test# git push origin HEAD:refs/for/master
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 298 bytes | 49.00 KiB/s, done.
Total 2 (delta 0), reused 0 (delta 0)
remote: Processing changes: refs: 1, new: 1, done    
remote: 
remote: SUCCESS
remote: 
remote:   http://192.168.72.135:8802/c/test/+/42 wulili add file3 [NEW]
remote: 
To ssh://192.168.72.135:29418/test
 * [new branch]      HEAD -> refs/for/master
root@lili:~/test/test# 

也可在被继承的project里新增rules.pl,这样只要其他项目继承该项目,就会有改规则,不需要每个项目都新增该文件了

创建项目的时候,inherit from 一个父项目

留言

您的邮箱地址不会被公开。 必填项已用 * 标注

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。