phabricator + gitlab 강제 코드 리뷰

1. 차단 방식으로 코드 리뷰를 강제로 진행하는데 두 가지 방법이 있다.
      phabricator ,  herald      
           hook   
          gitlab ,             code review

2.gitlab 서버에서 hook 추가
gitlab  hook      :
        ,         
        ,        

2.1 부분적 구성
cd /srv/gitlab/data/git-data/repositories/root/pipeline-example-go.git ###gitlab serve            
mkdir custom_hooks  #     hook  
touch pre-receive   #  pre-receive   
chmod 755 pre-receive #      
pre-receive   ,     git push            ,     :
#!/usr/bin/env python
import sys,os
import fileinput
import re
import json
import requests
def has_been_reviewed(start_commit, end_commit):
    cmd = 'git rev-list %s...%s' % (start_commit, end_commit,)
    Flag = False
    commits = os.popen(cmd).readlines()
    pattern = re.compile(r'Differential Revision: (.*)')
    for commit in commits:
        cmd = 'git rev-list --format=' + '%s%b ' + '--max-count=1 %s' % commit
        res  = os.popen(cmd).readlines()[-2]
        match_str = pattern.match(res)
        if not  match_str:
            print("Please use 'arc diff' to commit")
            continue
        http_url = match_str.group(1)
        url = "https://xxx/api/differential.query?api.token=*****"
        info = json.loads(requests.get(url).text)
        for i in info['result']:
            if i['uri'] != http_url: continue
            if i['statusName'] == 'Accepted':
                Flag = True
            else:
                print("Current Status: %s, Need Review and Accepted" % i['statusName'])
            break
    if Flag:
        sys.exit(0)
    else:
        sys.exit(1)

if __name__  == "__main__":
    for line in fileinput.input():
        args = line.split(' ')
    start_commit = args[0]
    end_commit = args[1]
    if start_commit != '0000000000000000000000000000000000000000' and  end_commit != '0000000000000000000000000000000000000000':
        has_been_reviewed(start_commit, end_commit)
    :

1.git rev-list --format=%s%b  --max-count=1  ${commit_id} 
#  git commit      ,  git commit -m     ,    arc diff   ,arc diff         git commit    
2.requests.get("https://***/api/differential.query?api.token=***")
 #  ph api        differential   ,  token    https://***/conduit/login/   
3.#  differential     ,  uri      revision,   Accepted,    review  ,    ,     0,     
4.#       Accepted,       0,      ,  git push  

  ***
2.2 글로벌 구성
1.  gitlab    hook  
vim  /etc/gitlab/gitlab.rb   #     
gitlab_shell['custom_hooks_dir'] = "/opt/gitlab/embedded/service/gitlab-shell/hooks/custom_hooks" 
 #      ,     
2.mkdir -p  /opt/gitlab/embedded/service/gitlab-shell/hooks/custom_hooks/pre-receive.d  #     
3.touch /opt/gitlab/embedded/service/gitlab-shell/hooks/custom_hooks/pre-receive.d/pre-receive  #    pre-receive 
4.chmod 755 /opt/gitlab/embedded/service/gitlab-shell/hooks/custom_hooks/pre-receive.d/pre-receive 
5.pre-receive #      
6.gitlab-ctl reconfigure  #    gitlab   ,      

Ref:
   [1]  https://github.com/geeeeeeeeek/git-recipes/wiki
   [2] https://www.cnblogs.com/zhangshiwen/p/7747864.html

좋은 웹페이지 즐겨찾기