GitLab机器人,用于自定义过梁工具以注释
nittymcpick的Python项目详细描述
尼蒂姆皮克
你这个爱挑剔的GitLab机器人
目的
此bot在从接收webhook时运行自定义linting工具 GitLab并将其结果作为注释报告给合并请求 差异
先决条件
- python 3.6+
- GitLab CE/EE公司
设置
将刀具安装到机器上
GitLab服务器必须可以通过网络访问此计算机。在 下面我们将假设在GitLab服务器上进行本地安装 本身(127.0.0.1)
通过pypi安装
pip3 install nittymcpick
在
创建GitLab用户
- 使用可以创建用户的帐户(例如root)
- admin/users/new
- Name=nity McPick
- Username=nitymcpick
- Email=foo@localhost(或任何其他不存在的邮件 地址)
- Access Level=常规
- admin/users/nitymcpick/impersonation_令牌
- Name=例如,Nitty McPick Bot
- Scopes=api,read榍存储库
- IMPORTANT复制新模拟的内容 代币
- admin/users/new
将bot添加到项目中
- 使用可以更改项目设置的帐户转到Gitlab
- [username]/[project]/-project_成员/
- 搜索Nitty McPick,地址:**GitLabd member or Email address*
- 单击Invite
- 将级别Nitty McPick从Guest更改为Reporter
- [username]/[project]/-project_成员/
创建GitLab webhook
- 使用可以更改项目设置的帐户转到Gitlab
- **[用户名]/[项目]/-/settings/integrations
- URL:http://127.0.0.1:8888
- Trigger:合并请求事件
- SSL verification:取消选中该框
- 单击Add webhook
- **[用户名]/[项目]/-/settings/integrations
为bot创建配置
创建一个json文件,如 config.json.sample。文件可以包含任何 项目数量
linter节
attribute | description |
---|---|
name | name of the linting tool |
path | absolute path of binary of the linting tool |
args | list of additional arguments to be passed to the linter |
ret_regex | regular expression for evaluation of the output of the linter (see Return Regex) |
tweaks.lin e_count_ad just | Add number of lines to the reported output line number |
tweaks.sin gle_file_e xec | Run each matching file in a single linter instance, otherwise all files will be run by a single instance |
matches部分
^{tb2}$返回正则表达式
用于提取所有所需数据的正则表达式应包含 以下命名组
- severity-表示发现的严重性(可选)
- line-发现的行
- message-一条有意义的消息
- file-查找的
运行工具
^{pr2}$例如,跑步
exportGL_ACCESS_TOKEN=<Impersonation Token from gitlab> nittymcpick config.json
现在,每当合并请求被打开或更改时,工具将运行所有 配置好的线切割工具。一旦发现,它会直接对其进行评论 像这样的先生
Nitty McPick @nittymcpick · just now Reporter mytool found a potential error - the code is absolutely insecure
Docker
下面有一个已准备好的容器 privkweihmann/nittymcpick:latest
关于安全的一句话
强烈建议在gitlab服务器上运行bot,因为 目前只支持http://作为webhook协议。在
欢迎使用PRs启用https://!在
- 项目
标签: