summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGal Schlezinger <galstar@spitfire.co.il>2016-01-31 11:05:47 +0200
committerRémy Coutable <remy@rymai.me>2016-02-11 09:34:07 +0100
commit78e36780be31257a59cb3076ba5402e380ca240f (patch)
treec51ae129173c76bd1e808731f8f63dc9e999ae40
parentbce482a59a235edf1607dab73dff88aba4300012 (diff)
downloadgitlab-ce-78e36780be31257a59cb3076ba5402e380ca240f.tar.gz
Added '/api/v3/projects/:id/merge_requests/:merge_request_id/closes_issues' route in the API
Added some documentation for it Added to changelog Added curl example and an attribute table Moved the api route definition from "lib/api/issues.rb" to "lib/api/merge_requests.rb" Fixed the attributes and changed the documentation to be at "merge_requests.md" too Changed generic titles to more specific titles added an underscore added tests. it depends on a newer version of gitlab-test project I'm doing a since I need to add a branch to the `gitlab-test` repo removed the before using 'iid' instead of 'id' in the description to reference the issues. that makes the tests pass Removed the 'closes-issues' key from test_env. so it should pass the tests Moved the two initializations to the describe block Changed the changelog
-rw-r--r--CHANGELOG1
-rw-r--r--doc/api/merge_requests.md62
-rw-r--r--lib/api/merge_requests.rb13
-rw-r--r--spec/factories/merge_requests.rb6
-rw-r--r--spec/requests/api/merge_requests_spec.rb26
5 files changed, 108 insertions, 0 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 50b27e25492..8f5a861d23e 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -11,6 +11,7 @@ v 8.5.0 (unreleased)
- New UI for pagination
- Don't prevent sign out when 2FA enforcement is enabled and user hasn't yet
set it up
+ - API: Added "merge_requests/:merge_request_id/closes_issues" (Gal Schlezinger)
- Fix diff comments loaded by AJAX to load comment with diff in discussion tab
- Whitelist raw "abbr" elements when parsing Markdown (Benedict Etzel)
- Fix label links for a merge request pointing to issues list
diff --git a/doc/api/merge_requests.md b/doc/api/merge_requests.md
index 85ed31320b9..2df244f3935 100644
--- a/doc/api/merge_requests.md
+++ b/doc/api/merge_requests.md
@@ -412,3 +412,65 @@ Parameters:
## Comments on merge requets
Comments are done via the [notes](notes.md) resource.
+
+## List issues that will close on merge
+
+Get all the issues that would be closed by merging the provided merge request.
+
+```
+GET /projects/:id/merge_requests/:merge_request_id/closes_issues
+```
+
+| Attribute | Type | Required | Description |
+| --------- | ---- | -------- | ----------- |
+| `id` | integer | yes | The ID of a project |
+| `merge_request_id` | integer | yes | The ID of the merge request |
+
+```bash
+curl -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/projects/76/merge_requests/1/closes_issues
+```
+
+Example response:
+
+```json
+[
+ {
+ "state" : "opened",
+ "description" : "Ratione dolores corrupti mollitia soluta quia.",
+ "author" : {
+ "state" : "active",
+ "id" : 18,
+ "web_url" : "https://gitlab.example.com/u/eileen.lowe",
+ "name" : "Alexandra Bashirian",
+ "avatar_url" : null,
+ "username" : "eileen.lowe"
+ },
+ "milestone" : {
+ "project_id" : 1,
+ "description" : "Ducimus nam enim ex consequatur cumque ratione.",
+ "state" : "closed",
+ "due_date" : null,
+ "iid" : 2,
+ "created_at" : "2016-01-04T15:31:39.996Z",
+ "title" : "v4.0",
+ "id" : 17,
+ "updated_at" : "2016-01-04T15:31:39.996Z"
+ },
+ "project_id" : 1,
+ "assignee" : {
+ "state" : "active",
+ "id" : 1,
+ "name" : "Administrator",
+ "web_url" : "https://gitlab.example.com/u/root",
+ "avatar_url" : null,
+ "username" : "root"
+ },
+ "updated_at" : "2016-01-04T15:31:51.081Z",
+ "id" : 76,
+ "title" : "Consequatur vero maxime deserunt laboriosam est voluptas dolorem.",
+ "created_at" : "2016-01-04T15:31:51.081Z",
+ "iid" : 6,
+ "labels" : []
+ },
+]
+```
diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb
index dd7f24f3279..004ff52c1d3 100644
--- a/lib/api/merge_requests.rb
+++ b/lib/api/merge_requests.rb
@@ -300,6 +300,19 @@ module API
render_api_error!("Failed to save note #{note.errors.messages}", 400)
end
end
+
+ # List issues that will close on merge
+ #
+ # Parameters:
+ # id (required) - The ID of a project
+ # merge_request_id (required) - ID of MR
+ # Examples:
+ # GET /projects/:id/merge_requests/:merge_request_id/closes_issues
+ get "#{path}/closes_issues" do
+ merge_request = user_project.merge_requests.find(params[:merge_request_id])
+ issues = ::Kaminari.paginate_array(merge_request.closes_issues)
+ present paginate(issues), with: Entities::Issue
+ end
end
end
end
diff --git a/spec/factories/merge_requests.rb b/spec/factories/merge_requests.rb
index 0c6a881f868..777bdb95008 100644
--- a/spec/factories/merge_requests.rb
+++ b/spec/factories/merge_requests.rb
@@ -73,6 +73,12 @@ FactoryGirl.define do
merge_user author
end
+ trait :with_closes_issues do
+ source_branch "markdown"
+ target_branch "master"
+ state :opened
+ end
+
factory :closed_merge_request, traits: [:closed]
factory :reopened_merge_request, traits: [:reopened]
factory :merge_request_with_diffs, traits: [:with_diffs]
diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb
index d7bfa17b0b1..90faf82fc01 100644
--- a/spec/requests/api/merge_requests_spec.rb
+++ b/spec/requests/api/merge_requests_spec.rb
@@ -448,6 +448,32 @@ describe API::API, api: true do
end
end
+ describe "GET :id/merge_requests/:merge_request_id/closes_issues" do
+ let(:merge_request_with_closes_issues) { create(:merge_request, :with_closes_issues, author: user, assignee: user, source_project: project, target_project: project, title: "Closed ##{issue.id}", created_at: base_time + 3.seconds, description: "This should close ##{issue.iid}") }
+ let(:issue) do
+ create :issue,
+ author: user,
+ assignee: user,
+ project: project,
+ milestone: nil
+ end
+
+ it "should return the issues that will be closed on merge" do
+ get api("/projects/#{project.id}/merge_requests/#{merge_request_with_closes_issues.id}/closes_issues", user)
+ expect(response.status).to eq(200)
+ expect(json_response).to be_an Array
+ expect(json_response.length).to eq(1)
+ expect(json_response.first['id']).to eq(issue.id)
+ end
+
+ it "should return an empty array when there are no issues to be closed" do
+ get api("/projects/#{project.id}/merge_requests/#{merge_request.id}/closes_issues", user)
+ expect(response.status).to eq(200)
+ expect(json_response).to be_an Array
+ expect(json_response.length).to eq(0)
+ end
+ end
+
def mr_with_later_created_and_updated_at_time
merge_request
merge_request.created_at += 1.hour