Unable to query API for merge_requests if Fast-forward merge is enabled in settings
Summary
Users are unable to query the API for merge requests if they have Fast-forward merge
checked in Settings > Merge Requests
. For example https://gitlab.com/api/v4/projects/<project_id>/deployments/<deployment_id>/merge_requests
will return blank json in a browser, but will return merge requests if Merge commit
is checked instead.
Steps to reproduce
- Create a project
- Add a merge request
- check
Fast-forward merge
- Query API for
/merge_requests
- Empty json
- Check
Merge commit
- Returns results
Example Project
https://gitlab.com/gitlab-gold/jfarmiloe-agent-test2/spring-test
What is the current bug behavior?
The API is not picking up merge requests if Fast-forward merge is enabled
What is the expected correct behavior?
The API should return merge requests when queried, regardless if Fast-forward merge is enabled or not
Relevant logs and/or screenshots
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)
Possible fixes
Deployments::LinkMergeRequestsService
, which is a service to associate deployments with merge requests, seeks a merge request by merge_commit_sha
. However, when FF-merge enabled, the merge_commit_sha
doesn't exist, so we need to find by diff_head_sha
instead.
Release Notes
When Fast Forward merge is enabled use the diff_head_sha
to determine if a merge request is associated with a deployment, this allows to be able to link Merge Request to deployments regardless if Fast Forward merge is enabled or not