Gitlab per-recive预处理配置

摘要:
添加gitlab_Shell['custom_hooks_dir']参数以配置自定义配置文件的存储位置,'merge']regex=re。file(“(”+“|”.doin(match_pattern)+“)”)line=sys。标准输入。read()(基,

背景:通过git提交规约对开发者的提交进行限制,为了后期对开发者提交动作进行分析与相关数据的报表展示。

Gitlab提供的钩子

          1.1 单一仓库

              通过此模式,我们可以将自定义的预处理代码部署到指定的仓库。

          1.2 激活方式

                源码安装的配置目录,通常如下:

             /home/git/repositories/<group>/<project>.git

                官方源安装的配置目录,通常如下:

             /var/opt/gitlab/git-data/repositories/<group>/<project>.git

                在项目目录下创建custom_hooks目录:

                   mkdir -pv /var/opt/gitlab/git-data/repositories/<group>/<project>.git/custom_hooks

                 新建一个名为"pre-receive"的开发文件,这个是官方规定。接下来可以进行自定义编码。

               

          2.1 全局

              通过此模式,我们可以将自定义的预处理代码应用到整个仓库。

      2.2 激活方式:

              通过编辑/etc/gitlab/gitlab.rb配置文件,增加gitlab_shell['custom_hooks_dir']参数来配置自定义配置文件存放位置,如下是我的配置:

              gitlab_shell['custom_hooks_dir'] = "/opt/gitlab/embedded/service/gitlab-shell/hooks/custom_hooks_dir"

              刷新Gitlab配置(重启库操作,生产环境需要评估操作时间)

          gitlab-ctl reconfigure

          gitlab-ctl restart

        配置更新成功后,需要在自定义钩子的目录下创建其中一个文件夹pre-receive.dpost-receive.dupdate.d  这个是官方的规定:

                mkdir -pv /opt/gitlab/embedded/service/gitlab-shell/hooks/custom_hooks_dir/pre-receive.d

              新建一个名为"pre-receive"的开发文件,这个是官方规定。接下来可以进行自定义编码。

             

二、实现DEMO

Gitlab per-recive预处理配置第1张Gitlab per-recive预处理配置第2张
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import sys
import re
import subprocess
import json

match_pattern=['feat', 'fix', 'docs', 'style', 'refactor', 'perf', 'test', 'build', 'ci', 'chore', 'revert', 'merge']
regex = re.compile("(" + "|".join(match_pattern) + ")")
line = sys.stdin.read()
(base, commit, ref) = line.strip().split()
new_branch_push = re.match(r'[^1-9A-Za-z]+', base)
branch_deleted = re.match(r'[^1-9A-Za-z]+', commit)
contains_commit_msg = False
if not new_branch_push:
    revs = base + "..." + commit
    #proc = subprocess.Popen(['git', 'rev-list','--oneline','--first-parent', revs], stdout=subprocess.PIPE)
    proc = subprocess.Popen(['git', 'log', '--first-parent', revs, '--pretty=format:{"author":"%cn","subject":"%s"}'], stdout=subprocess.PIPE)
    lines = proc.stdout.readlines()
    if lines:
        for line in lines:
            rev = json.loads(str(line))
            print(rev)
            try:
                subject_type, subject_message = rev['subject'].split(':', 1)
            except:
                contains_commit_msg = False
                break
            subject_message = subject_message.strip()
            print subject_message
            match = regex.search(subject_type.lower())
            if match:
                contains_commit_msg = True
if contains_commit_msg or new_branch_push or branch_deleted:
    print "Commit success"
    exit(0)
else:
    print('

免责声明:内容来源于网络,仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇【转载】Iptables详解1.初识nginx下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

解决正则表达式中用中文匹配的方法

例如在网页源代码中有如下中文字段(charset=‘utf-8’): 发布: 2016-7-27 11:18 |  作者:  |   查看: 63次据新华社电全球最大太阳能飞机“阳光动力”2号当地时间26日凌晨在阿联酋首都阿布扎比巴廷商务机场平稳降落,完成全程约3.5万公里的环球飞行,创造了全球不耗费任何燃料、完全依靠太阳能作为动力的飞机环球飞行纪录。...

Halcon 识别车牌学习笔记

有一张车牌照片如下: read_image (Image, 'C:/Users/LiZhiqiang/Desktop/车牌2.jpg')//读取照片 rgb1_to_gray (Image, GrayImage)//转化成灰度图像 threshold (GrayImage, Regions, 21, 163)//设定阈值 connection (Reg...

RobotFramework框架做自动化的过程中,遇到不能选择下拉框问题

1.描述 使用RobotFramework框架做自动化的过程中,遇到不能选择下拉框问题。 2.遇到的问题 关于下拉框的使用,网上都是这么使用的 select From List By Value Xpath=//* [@] vlaue # select From List By Value 关键字用于选择下拉框。 Xpath=//* [@] 定位下拉框;...

jQuery----1

简介   jQuery可以像CSS一样选择页面内的元素。比如:$('p')会选中所有的段落。   使用$(document).ready()就可以添加文档载入完毕之后执行的代码。   使用$.fn.func = function(){}的方式可以扩展jQuery。   选择器   简单示例:   <script type="text/JavaSc...

量化学习 | Tushare 基本面选股 (二)

量化投资比较重要的是策略,可是你得先选个好股,价值投资需要认同他的价值,值得投资的股票才有投资的机会,现在简单介绍一下基于基本面的选股,其实我现实生活中也有炒股,都是经验之说的选股原则。 首先从tushare中获取每日指标 pro.daily_basic last_year = '20190101' start_date = '20200313' myto...

vue3.0用vue-awesome-swiper

使用新版vue-awesome-swiper出现了一些bug vue-awesome-swiper组件pagination小圆点不显示问题 不会自动播放 swiper没有css 参考如下配置 基本使用方法 1.安装 cnpm install vue-awesome-swiper --save 2.引用 /*全局引入*/ import VueAwes...