Commit c56970e3 authored by Alexandru Croitor's avatar Alexandru Croitor

Remove duplicates from issue related merge requests

Remove duplicates returned by Issues#related_merge_requests API that
relies on ReferencedMergeRequestsService which returns 2 arrays one of
related MRs and one of related MRs that close the issue(i.e. a subset
of first one). We only need related MRs in this case so just pick the
first array.
parent 941e0012
---
title: Remove duplicates from issue related merge requests
merge_request: 27067
author:
type: fixed
......@@ -307,7 +307,7 @@ module API
merge_requests = ::Issues::ReferencedMergeRequestsService.new(user_project, current_user)
.execute(issue)
.flatten
.first
present paginate(::Kaminari.paginate_array(merge_requests)),
with: Entities::MergeRequest,
......
......@@ -2189,6 +2189,18 @@ describe API::Issues do
expect_paginated_array_response(related_mr.id)
end
context 'merge request closes an issue' do
let!(:closing_issue_mr_rel) do
create(:merge_requests_closing_issues, issue: issue, merge_request: related_mr)
end
it 'returns closing MR only once' do
get_related_merge_requests(project.id, issue.iid, user)
expect_paginated_array_response([related_mr.id])
end
end
context 'no merge request mentioned a issue' do
it 'returns empty array' do
get_related_merge_requests(project.id, closed_issue.iid, user)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment