File: project_push_rules.md

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (118 lines) | stat: -rw-r--r-- 5,972 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
---
stage: Create
group: Source Code
info: "To determine the technical writer assigned to the Stage/Group associated with this page, see https://handbook.gitlab.com/handbook/product/ux/technical-writing/#assignments"
---

# Project push rules API

DETAILS:
**Tier:** Premium, Ultimate
**Offering:** GitLab.com, Self-managed, GitLab Dedicated

You can manage [push rules](../user/project/repository/push_rules.md) for projects by using the REST API.

## Get project push rules

Get the push rules of a project.

```plaintext
GET /projects/:id/push_rule
```

Supported attributes:

| Attribute | Type              | Required | Description |
|:----------|:------------------|:---------|:------------|
| `id`      | integer or string | Yes      | The ID or [URL-encoded path of the project](rest/index.md#namespaced-paths) |

Example response:

```json
{
  "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
}
```

## Add a project push rule

Add a push rule to a specified project.

```plaintext
POST /projects/:id/push_rule
```

Supported attributes:

| Attribute                       | Type              | Required | Description |
|:--------------------------------|:------------------|:---------|:------------|
| `id`                            | integer or string | Yes      | The ID or [URL-encoded path of the project](rest/index.md#namespaced-paths). |
| `author_email_regex`            | string            | No       | All commit author emails must match this regular expression. |
| `branch_name_regex`             | string            | No       | All branch names must match this regular expression. |
| `commit_message_negative_regex` | string            | No       | No commit message is allowed to match this regular expression. |
| `commit_message_regex`          | string            | No       | All commit messages must match this regular expression. |
| `deny_delete_tag`               | boolean           | No       | Deny deleting a tag. |
| `file_name_regex`               | string            | No       | All committed filenames must **not** match this regular expression. |
| `max_file_size`                 | integer           | No       | Maximum file size (MB). |
| `member_check`                  | boolean           | No       | Restrict commits by author (email) to existing GitLab users. |
| `prevent_secrets`               | boolean           | No       | GitLab rejects any files that are likely to contain secrets. |
| `commit_committer_check`        | boolean           | No       | Users can only push commits to this repository if the committer email is one of their own verified emails. |
| `commit_committer_name_check`   | boolean           | No       | Users can only push commits to this repository if the commit author name is consistent with their GitLab account name. |
| `reject_unsigned_commits`       | boolean           | No       | Reject commit when it's not signed. |
| `reject_non_dco_commits`        | boolean           | No       | Reject commit when it's not DCO certified. |

## Edit project push rule

Edit a push rule for a specified project.

```plaintext
PUT /projects/:id/push_rule
```

Supported attributes:

| Attribute                       | Type              | Required | Description |
|:--------------------------------|:------------------|:---------|:------------|
| `id`                            | integer or string | Yes      | The ID or [URL-encoded path of the project](rest/index.md#namespaced-paths). |
| `author_email_regex`            | string            | No       | All commit author emails must match this regular expression. |
| `branch_name_regex`             | string            | No       | All branch names must match this regular expression. |
| `commit_message_negative_regex` | string            | No       | No commit message is allowed to match this regular expression. |
| `commit_message_regex`          | string            | No       | All commit messages must match this regular expression. |
| `deny_delete_tag`               | boolean           | No       | Deny deleting a tag. |
| `file_name_regex`               | string            | No       | All committed filenames must **not** match this regular expression. |
| `max_file_size`                 | integer           | No       | Maximum file size (MB). |
| `member_check`                  | boolean           | No       | Restrict commits by author (email) to existing GitLab users. |
| `prevent_secrets`               | boolean           | No       | GitLab rejects any files that are likely to contain secrets. |
| `commit_committer_check`        | boolean           | No       | Users can only push commits to this repository if the committer email is one of their own verified emails. |
| `commit_committer_name_check`   | boolean           | No       | Users can only push commits to this repository if the commit author name is consistent with their GitLab account name. |
| `reject_unsigned_commits`       | boolean           | No       | Reject commits when they are not signed. |
| `reject_non_dco_commits`        | boolean           | No       | Reject commit when it's not DCO certified. |

## Delete project push rule

Delete a push rule from a project.

```plaintext
DELETE /projects/:id/push_rule
```

Supported attributes:

| Attribute | Type              | Required | Description |
|:----------|:------------------|:---------|:------------|
| `id`      | integer or string | Yes      | The ID or [URL-encoded path of the project](rest/index.md#namespaced-paths). |