Merge branch '26437-closed-by' into 'master'

Add issues/:iid/closed_by api endpoint

Closes #26437

See merge request !10511
This commit is contained in:
Rémy Coutable 2017-04-26 11:45:10 +00:00
commit f8f49cf516
6 changed files with 122 additions and 1 deletions

View file

@ -0,0 +1,4 @@
---
title: Add issues/:iid/closed_by api endpoint
merge_request:
author: mhasbini

View file

@ -823,6 +823,67 @@ Example response:
}
```
## List merge requests that will close issue on merge
Get all the merge requests that will close issue when merged.
```
GET /projects/:id/issues/:issue_iid/closed_by
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `id` | integer | yes | The ID of a project |
| `issue_iid` | integer | yes | The internal ID of a project issue |
```bash
curl --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/projects/1/issues/11/closed_by
```
Example response:
```json
[
{
"id": 6471,
"iid": 6432,
"project_id": 1,
"title": "add a test for cgi lexer options",
"description": "closes #11",
"state": "opened",
"created_at": "2017-04-06T18:33:34.168Z",
"updated_at": "2017-04-09T20:10:24.983Z",
"target_branch": "master",
"source_branch": "feature.custom-highlighting",
"upvotes": 0,
"downvotes": 0,
"author": {
"name": "Administrator",
"username": "root",
"id": 1,
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
"web_url": "https://gitlab.example.com/root"
},
"assignee": null,
"source_project_id": 1,
"target_project_id": 1,
"labels": [],
"work_in_progress": false,
"milestone": null,
"merge_when_pipeline_succeeds": false,
"merge_status": "unchecked",
"sha": "5a62481d563af92b8e32d735f2fa63b94e806835",
"merge_commit_sha": null,
"user_notes_count": 1,
"should_remove_source_branch": null,
"force_remove_source_branch": false,
"web_url": "https://gitlab.example.com/gitlab-org/gitlab-test/merge_requests/6432"
}
]
```
## Comments on issues
Comments are done via the [notes](notes.md) resource.

View file

@ -219,6 +219,21 @@ module API
authorize!(:destroy_issue, issue)
issue.destroy
end
desc 'List merge requests closing issue' do
success Entities::MergeRequestBasic
end
params do
requires :issue_iid, type: Integer, desc: 'The internal ID of a project issue'
end
get ':id/issues/:issue_iid/closed_by' do
issue = find_project_issue(params[:issue_iid])
merge_request_ids = MergeRequestsClosingIssues.where(issue_id: issue).select(:merge_request_id)
merge_requests = MergeRequestsFinder.new(current_user, project_id: user_project.id).execute.where(id: merge_request_ids)
present paginate(merge_requests), with: Entities::MergeRequestBasic, current_user: current_user, project: user_project
end
end
end
end

View file

@ -0,0 +1,6 @@
FactoryGirl.define do
factory :merge_requests_closing_issues do
issue
merge_request
end
end

View file

@ -68,7 +68,7 @@ describe 'issuable list', feature: true do
source_project: project,
source_branch: generate(:branch))
MergeRequestsClosingIssues.create!(issue: issue, merge_request: merge_request)
create(:merge_requests_closing_issues, issue: issue, merge_request: merge_request)
end
end
end

View file

@ -1344,6 +1344,41 @@ describe API::Issues do
include_examples 'time tracking endpoints', 'issue'
end
describe 'GET :id/issues/:issue_iid/closed_by' do
let(:merge_request) do
create(:merge_request,
:simple,
author: user,
source_project: project,
target_project: project,
description: "closes #{issue.to_reference}")
end
before do
create(:merge_requests_closing_issues, issue: issue, merge_request: merge_request)
end
it 'returns merge requests that will close issue on merge' do
get api("/projects/#{project.id}/issues/#{issue.iid}/closed_by", user)
expect_paginated_array_response(size: 1)
end
context 'when no merge requests will close issue' do
it 'returns empty array' do
get api("/projects/#{project.id}/issues/#{closed_issue.iid}/closed_by", user)
expect_paginated_array_response(size: 0)
end
end
it "returns 404 when issue doesn't exists" do
get api("/projects/#{project.id}/issues/9999/closed_by", user)
expect(response).to have_http_status(404)
end
end
def expect_paginated_array_response(size: nil)
expect(response).to have_http_status(200)
expect(response).to include_pagination_headers