Commit 42356201 authored by Patrick Derichs's avatar Patrick Derichs Committed by Sean McGivern

Add related merge request count to api response

parent 197641c7
---
title: Add related merge request count to api response
merge_request: 24974
author:
type: added
......@@ -110,6 +110,7 @@ Example response:
"labels" : [],
"upvotes": 4,
"downvotes": 0,
"merge_requests_count": 0,
"user_notes_count": 1,
"due_date": "2016-07-22",
"web_url": "http://example.com/example/example/issues/6",
......@@ -219,6 +220,7 @@ Example response:
"labels" : [],
"upvotes": 4,
"downvotes": 0,
"merge_requests_count": 0,
"id" : 41,
"title" : "Ut commodi ullam eos dolores perferendis nihil sunt.",
"updated_at" : "2016-01-04T15:31:46.176Z",
......@@ -334,6 +336,7 @@ Example response:
"labels" : [],
"upvotes": 4,
"downvotes": 0,
"merge_requests_count": 0,
"id" : 41,
"title" : "Ut commodi ullam eos dolores perferendis nihil sunt.",
"updated_at" : "2016-01-04T15:31:46.176Z",
......@@ -430,6 +433,7 @@ Example response:
"labels" : [],
"upvotes": 4,
"downvotes": 0,
"merge_requests_count": 0,
"id" : 41,
"title" : "Ut commodi ullam eos dolores perferendis nihil sunt.",
"updated_at" : "2016-01-04T15:31:46.176Z",
......@@ -505,6 +509,7 @@ Example response:
],
"upvotes": 4,
"downvotes": 0,
"merge_requests_count": 0,
"author" : {
"name" : "Alexandra Bashirian",
"avatar_url" : null,
......@@ -604,6 +609,7 @@ Example response:
],
"upvotes": 4,
"downvotes": 0,
"merge_requests_count": 0,
"id" : 85,
"assignees" : [],
"assignee" : null,
......@@ -690,6 +696,7 @@ Example response:
"labels": [],
"upvotes": 4,
"downvotes": 0,
"merge_requests_count": 0,
"milestone": null,
"assignees": [{
"name": "Miss Monserrate Beier",
......@@ -774,6 +781,7 @@ Example response:
"labels": [],
"upvotes": 4,
"downvotes": 0,
"merge_requests_count": 0,
"milestone": null,
"assignees": [{
"name": "Miss Monserrate Beier",
......@@ -856,6 +864,7 @@ Example response:
"labels": [],
"upvotes": 4,
"downvotes": 0,
"merge_requests_count": 0,
"milestone": null,
"assignee": {
"name": "Edwardo Grady",
......@@ -973,6 +982,7 @@ Example response:
"user_notes_count": 7,
"upvotes": 0,
"downvotes": 0,
"merge_requests_count": 0,
"due_date": null,
"web_url": "http://example.com/example/example/issues/110",
"confidential": false,
......
......@@ -557,6 +557,15 @@ module API
expose :time_stats, using: 'API::Entities::IssuableTimeStats' do |issue|
issue
end
expose :merge_requests_count do |issue, options|
if options[:issuable_metadata]
# Avoids an N+1 query when metadata is included
options[:issuable_metadata][issue.id].merge_requests_count
else
issue.merge_requests_closing_issues.count
end
end
end
class Issue < IssueBasic
......
......@@ -421,6 +421,24 @@ describe API::Issues do
expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('public_api/v4/issues')
end
it 'returns a related merge request count of 0 if there are no related merge requests' do
get api('/issues', user)
expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('public_api/v4/issues')
expect(json_response.first).to include('merge_requests_count' => 0)
end
it 'returns a related merge request count > 0 if there are related merge requests' do
create(:merge_requests_closing_issues, issue: issue)
get api('/issues', user)
expect(response).to have_gitlab_http_status(200)
expect(response).to match_response_schema('public_api/v4/issues')
expect(json_response.first).to include('merge_requests_count' => 1)
end
end
end
......
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