Unable to query API for merge_requests if Fast-forward merge is enabled in settings
<!--- Please read this! Before opening a new issue, make sure to search for keywords in the issues filtered by the "regression" or "type::bug" label: - https://gitlab.com/gitlab-org/gitlab/issues?label_name%5B%5D=regression - https://gitlab.com/gitlab-org/gitlab/issues?label_name%5B%5D=type::bug and verify the issue you're about to submit isn't a duplicate. ---> ### 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 <!-- Paste any relevant logs - please use code blocks (```) to format console output, logs, and code as it's tough to read otherwise. --> ### Output of checks <!-- If you are reporting a bug on GitLab.com, uncomment below --> <!-- This bug happens on GitLab.com --> <!-- /label ~"reproduced on GitLab.com" --> #### Results of GitLab environment info <!-- Input any relevant GitLab environment information if needed. --> <details> <summary>Expand for output related to GitLab environment info</summary> <pre> (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`) </pre> </details> #### Results of GitLab application Check <!-- Input any relevant GitLab application check information if needed. --> <details> <summary>Expand for output related to the GitLab application check</summary> <pre> (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) </pre> </details> ### 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
issue