gitlab配置webhook限制提交注释

一、打开gitlab相关配置项

vim /etc/gitlab/gitlab.rb

gitlab_shell['custom_hooks_dir'] = "/etc/gitlab/custom_hooks"

二、创建相关文件夹

mkdir -p /etc/gitlab/custom_hooks

mkdir -p /etc/gitlab/custom_hooks/post-receive.d

mkdir -p /etc/gitlab/custom_hooks/pre-receive.d

mkdir -p /etc/gitlab/custom_hooks/update.d

#将相关脚本放入对应目录

#!/usr/bin/env  python3
import sys
import re
import subprocess
#import redis
refname = sys.argv[1]
oldrev  = sys.argv[2]
newrev  = sys.argv[3]
 
 
 
regex='([a-zA-Z0-9]+-\\d+)\\,\\s+.{10,}'
 
 
def check_message_format():
    cmd='git rev-list '+oldrev+'..'+newrev
    print(cmd)
    p = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE)
    l= p.stdout.readlines()
    for rev in l:
        cmdsub="git cat-file commit "+rev.decode().strip('''\n''')+"  | sed '1,/^$/d'"
        p1 = subprocess.Popen(cmdsub,shell=True,stdout=subprocess.PIPE)
        l1 = p1.stdout.readline()
        print(l1)
        result = re.match('([a-zA-Z0-9]+-\\d+)\\,\\s+.{10,}',l1.decode())
        if result == None:
             print("your commit msg should like : TEST-123,  fix the wrong caution")
             sys.exit(1)
    sys.exit(0)
check_message_format()

三、使配置生效

gitlab-ctl reconfigure

效果:

一、提交代码格式为“jira项目问题编号, 注释信息”,例如

git commit -m "SMGJ-120, 测试提交代码"

#注释信息可以中文也可以英文,但是标红处的字符不得少于10个字符。

 

由于注释信息为6个字,所以被拦截,并且在报错中也给出样例“remote: your commit msg should like : TEST-123,  fix the wrong caution”。

二、修改注释,重新提交代码

使用git commit --amend

修改注释信息为"SMGJ-120, 测试提交代码测试提交代码"

 

三、重新推送代码

直接推送代码,完成。

 

 golang实现gitlab commit注释校验hook - 简书

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
GitLabWebhook 是一种机制,用于在GitLab中的事件发生时触发外部服务的操作。GitLab通过向预先配置的URL发送HTTP请求来触发Webhook。 当GitLab事件发生时,它将向该URL发送包含事件信息的POST请求。 在配置GitLabWebhook时,需要提供一个有效的URL。 这个URL是指接收GitLab事件的外部服务的地址。 这个URL可以是任何可以处理HTTP请求的服务,例如一个API端点、一个Web应用程序或者一个消息队列。 具体地说,当在GitLab配置Webhook时,需要提供一个URL配置项,这个URL应该指向一个能够接收和处理GitLab发送的POST请求的服务。这个服务可以是一个自己搭建的应用程序,或者是使用现有的集成工具,如企业微信消息发送接口。 总结起来,GitLabWebhook是一种用于在GitLab事件发生时触发外部服务操作的机制。在配置Webhook时,需要提供一个有效的URL,该URL应指向一个能够接收和处理GitLab发送的POST请求的服务。可以根据具体需求选择不同的服务来处理Webhook请求。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [GitLab基础:webhook的使用方法](https://blog.csdn.net/liumiaocn/article/details/108087029)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [GitLabWebhook配置和开发](https://blog.csdn.net/qq_18515155/article/details/110820286)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

0X码上链

你的鼓将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值