Rest API v4 commits/<sha>/merge_requests missing content
Summary
Gitlab Rest Api v4 fails to list all commit's merge requests in certain situations when a merge request has no commit on top of its root commit.
Steps to reproduce
Repository https://gitlab.com/Urpelainen/reproduce-gitlab-api-failure is in state where the issue appears. The following is copied from that repository's readme:
This repository has a merged merge request with a single commit, mr-1. After mr-1 was rebased and merged, another branch and merge request, mr-2, were opened on the same commit. This procedure of first merging a merge request, then opening a new one on the same commit leads to situation where the merge request is not visible in Rest Api v4 call commits/<sha>/merge_requests.
To reproduce:
- Create a gitlab.com user and api token
- Fetch merge requests of the relevant commit: curl --header "PRIVATE-TOKEN: <your token here>" "https://gitlab.com/api/v4/projects/22779992/repository/commits/c4b05f424dd4caf564eece73cbec71daced4ce23/merge_requests"
- Observe that the merge request mr-1 was included
- But that mr-2 was not (WRONG!)
- Check from GitLab web ui that actually merge request mr-2 points to commit c4b05f42
To reproduce in another repository:
- Initalize a new repository
- Configure to use only fast-forward merges
- Create a branch, a commit and a merge request on top of _master.
- Merge the merge request to master
- Create a new merge request on top of master
- List merge requests of current master commit using the v4 Api
- Observe that the new merge request is not listed
Example Project
https://gitlab.com/Urpelainen/reproduce-gitlab-api-failure
What is the current bug behavior?
A merge request is missing from the list of commit's merge requests.
What is the expected correct behavior?
All merge requests pointing to a commit should be returned from commits/<sha>/merge_requests api call, including ones that point to a commit that is also pointed to by a another, merged merge request.
Relevant logs and/or screenshots
Api response missing merge request !2 (merged):
[
{
"id": 79928963,
"iid": 1,
"project_id": 22779992,
"title": "mr-1",
"description": "",
"state": "merged",
"created_at": "2020-11-30T07:52:35.005Z",
"updated_at": "2020-11-30T07:52:45.570Z",
"merged_by": {
"id": 7192855,
"name": "Otto",
"username": "Urpelainen",
"state": "active",
"avatar_url": "https://secure.gravatar.com/avatar/083117f2fab331f82c53cfe4662ed3fa?s=80&d=identicon",
"web_url": "https://gitlab.com/Urpelainen"
},
"merged_at": "2020-11-30T07:52:45.600Z",
"closed_by": null,
"closed_at": null,
"target_branch": "master",
"source_branch": "branch-1",
"user_notes_count": 0,
"upvotes": 0,
"downvotes": 0,
"author": {
"id": 7192855,
"name": "Otto",
"username": "Urpelainen",
"state": "active",
"avatar_url": "https://secure.gravatar.com/avatar/083117f2fab331f82c53cfe4662ed3fa?s=80&d=identicon",
"web_url": "https://gitlab.com/Urpelainen"
},
"assignees": [],
"assignee": null,
"source_project_id": 22779992,
"target_project_id": 22779992,
"labels": [],
"work_in_progress": false,
"milestone": null,
"merge_when_pipeline_succeeds": false,
"merge_status": "can_be_merged",
"sha": "c4b05f424dd4caf564eece73cbec71daced4ce23",
"merge_commit_sha": null,
"squash_commit_sha": null,
"discussion_locked": null,
"should_remove_source_branch": null,
"force_remove_source_branch": true,
"reference": "!1",
"references": {
"short": "!1",
"relative": "!1",
"full": "Urpelainen/reproduce-gitlab-api-failure!1"
},
"web_url": "https://gitlab.com/Urpelainen/reproduce-gitlab-api-failure/-/merge_requests/1",
"time_stats": {
"time_estimate": 0,
"total_time_spent": 0,
"human_time_estimate": null,
"human_total_time_spent": null
},
"squash": false,
"task_completion_status": {
"count": 0,
"completed_count": 0
},
"has_conflicts": false,
"blocking_discussions_resolved": true,
"approvals_before_merge": null
}
]
Output of checks
This bug happens on GitLab.com
Results of GitLab environment info
Results of GitLab application Check
Possible fixes
???