diff options
author | Alexandru Croitor <acroitor@gitlab.com> | 2019-04-05 19:17:13 +0300 |
---|---|---|
committer | Alexandru Croitor <acroitor@gitlab.com> | 2019-04-05 22:17:07 +0300 |
commit | c56970e3f72192bf02a0cae535b45357981a848a (patch) | |
tree | ef5ccf38db8ec76127e42d2811ddaac893c2e3df | |
parent | 941e00121c30baf0bf4e348d0d2b9b28891754d7 (diff) | |
download | gitlab-ce-c56970e3f72192bf02a0cae535b45357981a848a.tar.gz |
Remove duplicates from issue related merge requestsduplicate-related-mrs
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.
-rw-r--r-- | changelogs/unreleased/duplicate-related-mrs.yml | 5 | ||||
-rw-r--r-- | lib/api/issues.rb | 2 | ||||
-rw-r--r-- | spec/requests/api/issues_spec.rb | 12 |
3 files changed, 18 insertions, 1 deletions
diff --git a/changelogs/unreleased/duplicate-related-mrs.yml b/changelogs/unreleased/duplicate-related-mrs.yml new file mode 100644 index 00000000000..0f5f6ede9f8 --- /dev/null +++ b/changelogs/unreleased/duplicate-related-mrs.yml @@ -0,0 +1,5 @@ +--- +title: Remove duplicates from issue related merge requests +merge_request: 27067 +author: +type: fixed diff --git a/lib/api/issues.rb b/lib/api/issues.rb index 3dd90502050..999a9cb5a82 100644 --- a/lib/api/issues.rb +++ b/lib/api/issues.rb @@ -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, diff --git a/spec/requests/api/issues_spec.rb b/spec/requests/api/issues_spec.rb index a5434d3ea80..86484ce62f8 100644 --- a/spec/requests/api/issues_spec.rb +++ b/spec/requests/api/issues_spec.rb @@ -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) |