Help us learn about your current experience with the documentation. Take the survey.

项目推送规则 API

  • Tier: Premium, Ultimate
  • Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated

使用项目推送规则 API 来管理项目的推送规则

GitLab 在推送规则的所有正则表达式中使用 RE2 语法

获取项目推送规则

获取项目的推送规则。

GET /projects/:id/push_rule

支持的属性:

属性 类型 是否必需 描述
id integer or string 项目的 ID 或 URL 编码的路径

示例响应:

{
  "id": 1,
  "project_id": 3,
  "commit_message_regex": "Fixes \d+\..*",
  "commit_message_negative_regex": "ssh\:\/\/",
  "branch_name_regex": "",
  "deny_delete_tag": false,
  "created_at": "2012-10-12T17:04:47Z",
  "member_check": false,
  "prevent_secrets": false,
  "author_email_regex": "",
  "file_name_regex": "",
  "max_file_size": 5,
  "commit_committer_check": false,
  "commit_committer_name_check": false,
  "reject_unsigned_commits": false,
  "reject_non_dco_commits": false
}

添加项目推送规则

为指定项目添加一条推送规则。

POST /projects/:id/push_rule

支持的属性:

属性 类型 是否必需 描述
id integer or string 项目的 ID 或 URL 编码的路径
author_email_regex string 所有提交作者邮箱必须匹配此正则表达式。
branch_name_regex string 所有分支名称必须匹配此正则表达式。
commit_message_negative_regex string 不允许任何提交信息与此正则表达式匹配。
commit_message_regex string 所有提交信息必须匹配此正则表达式。
deny_delete_tag boolean 禁止删除标签。
file_name_regex string 所有已提交的文件名不得与此正则表达式匹配。
max_file_size integer 最大文件大小(MB)。
member_check boolean 将提交作者(邮箱)限制为现有的 GitLab 用户。
prevent_secrets boolean GitLab 会拒绝任何可能包含密钥的文件。
commit_committer_check boolean 只有提交者的邮箱是其本人已验证的邮箱之一时,用户才能向此仓库推送提交。
commit_committer_name_check boolean 只有提交作者名称与其 GitLab 账户名称一致时,用户才能向此仓库推送提交。
reject_unsigned_commits boolean 当提交未签名时,拒绝该提交。
reject_non_dco_commits boolean 当提交未通过 DCO 认证时,拒绝该提交。

编辑项目推送规则

编辑指定项目的推送规则。

PUT /projects/:id/push_rule

支持的属性:

属性 类型 是否必需 描述
id integer or string 项目的 ID 或 URL 编码的路径
author_email_regex string 所有提交作者邮箱必须匹配此正则表达式。
branch_name_regex string 所有分支名称必须匹配此正则表达式。
commit_message_negative_regex string 不允许任何提交信息与此正则表达式匹配。
commit_message_regex string 所有提交信息必须匹配此正则表达式。
deny_delete_tag boolean 禁止删除标签。
file_name_regex string 所有已提交的文件名不得与此正则表达式匹配。
max_file_size integer 最大文件大小(MB)。
member_check boolean 将提交作者(邮箱)限制为现有的 GitLab 用户。
prevent_secrets boolean GitLab 会拒绝任何可能包含密钥的文件。
commit_committer_check boolean 只有提交者的邮箱是其本人已验证的邮箱之一时,用户才能向此仓库推送提交。
commit_committer_name_check boolean 只有提交作者名称与其 GitLab 账户名称一致时,用户才能向此仓库推送提交。
reject_unsigned_commits boolean 当提交未签名时,拒绝该提交。
reject_non_dco_commits boolean 当提交未通过 DCO 认证时,拒绝该提交。

删除项目推送规则

从项目中删除一条推送规则。

DELETE /projects/:id/push_rule

支持的属性:

属性 类型 是否必需 描述
id integer or string 项目的 ID 或 URL 编码的路径