Inconsistencies in push rules API responses
Summary
Using this issue to document several inconsistencies found while working on automating group or project level "push rules" settings using the API.
Issue 1: The GET request returns different results depending on initial config
Steps to reproduce:
- Either create a brand new project or an choose an existing one where push rule was never configured
- Use the Get project push rules API
$ curl --silent --request GET --header "PRIVATE-TOKEN: ${GITLAB_API_TOKEN}" --url "${GITLAB_API_URL}/projects/root%2Ftest-project/push_rule"
null
- Either create a brand new group or an choose an existing one where push rule was never configured
- Use the Get group push rules API
$ curl --silent --request GET --header "PRIVATE-TOKEN: ${GITLAB_API_TOKEN}" --url "${GITLAB_API_URL}/groups/test-group/push_rule"
{"message":"404 Not Found"}
Notice how the response is different between group vs project level push rules. The project level push rule should return a 404 Not Found error similar to group level push rules API.
Issue 2: Inconsistent value for boolean type attributes
Steps to reproduce:
- Configure push rules for a group or project but make sure to turn off (or disable) boolean type attributes
- Use the Get project push rules API or Get group push rules API
# get project level push rules
$ curl --silent --request GET --header "PRIVATE-TOKEN: ${GITLAB_API_TOKEN}" --url "${GITLAB_API_URL}/projects/root%2Ftest-project/push_rule" | jq .
{
"id": 1,
"project_id": 1,
"created_at": "2025-01-15T15:28:41.984Z",
"commit_message_regex": "",
"commit_message_negative_regex": "",
"branch_name_regex": "",
"deny_delete_tag": false,
"member_check": false,
"prevent_secrets": false,
"author_email_regex": "",
"file_name_regex": "",
"max_file_size": 0,
"commit_committer_check": null,
"commit_committer_name_check": false,
"reject_unsigned_commits": null,
"reject_non_dco_commits": null
}
# get group level push rules
$ curl --silent --request GET --header "PRIVATE-TOKEN: ${GITLAB_API_TOKEN}" --url "${GITLAB_API_URL}/groups/test-group/push_rule" | jq .
{
"id": 2,
"created_at": "2025-01-15T15:50:31.297Z",
"commit_message_regex": "",
"commit_message_negative_regex": "",
"branch_name_regex": "",
"author_email_regex": "",
"file_name_regex": "",
"deny_delete_tag": false,
"member_check": false,
"prevent_secrets": false,
"max_file_size": 0,
"commit_committer_check": null,
"commit_committer_name_check": false,
"reject_unsigned_commits": null,
"reject_non_dco_commits": null
}
In the API responses above, notice how some of the boolean attributes are set to false and some of them are set to null. The API should be returning false to be consistent.
I've tried this in couple of different GitLab versions (17.6.2, 17.7.1)
Steps to reproduce
See the previous section
Example Project
N/A
What is the current bug behavior?
The push rules API responses for GET request is inconsistent. See the previous section for details.
What is the expected correct behavior?
See the previous section for details.
Relevant logs and/or screenshots
N/A
Output of checks
Results of GitLab environment info
Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of: `sudo gitlab-rake gitlab:env:info`) (For installations from source run and paste the output of: `sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)
Results of GitLab application Check
Expand for output related to the GitLab application check
(For installations with omnibus-gitlab package run and paste the output of:
sudo gitlab-rake gitlab:check SANITIZE=true)(For installations from source run and paste the output of:
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true)(we will only investigate if the tests are passing)