Commit 0807bd51 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'skakirill/gitlab-ce-api-merge-request-setup-milestone' into 'master'

API: Allow to set or update a merge-request's milestone

_Originally opened at !2107 by @ skakirill._

- - -


See merge request !2755
parents dd4171eb 2d59a0ff
...@@ -39,6 +39,7 @@ v 8.5.0 (unreleased) ...@@ -39,6 +39,7 @@ v 8.5.0 (unreleased)
- Prevent parse error when name of project ends with .atom and prevent path issues - Prevent parse error when name of project ends with .atom and prevent path issues
- Mark inline difference between old and new paths when a file is renamed - Mark inline difference between old and new paths when a file is renamed
- Support Akismet spam checking for creation of issues via API (Stan Hu) - Support Akismet spam checking for creation of issues via API (Stan Hu)
- API: Allow to set or update a merge-request's milestone (Kirill Skachkov)
- Improve UI consistency between projects and groups lists - Improve UI consistency between projects and groups lists
- Add sort dropdown to dashboard projects page - Add sort dropdown to dashboard projects page
- Fixed logo animation on Safari (Roman Rott) - Fixed logo animation on Safari (Roman Rott)
......
...@@ -259,6 +259,7 @@ Parameters: ...@@ -259,6 +259,7 @@ Parameters:
- `description` (optional) - Description of MR - `description` (optional) - Description of MR
- `target_project_id` (optional) - The target project (numeric id) - `target_project_id` (optional) - The target project (numeric id)
- `labels` (optional) - Labels for MR as a comma-separated list - `labels` (optional) - Labels for MR as a comma-separated list
- `milestone_id` (optional) - Milestone ID
```json ```json
{ {
...@@ -328,6 +329,7 @@ Parameters: ...@@ -328,6 +329,7 @@ Parameters:
- `description` - Description of MR - `description` - Description of MR
- `state_event` - New state (close|reopen|merge) - `state_event` - New state (close|reopen|merge)
- `labels` (optional) - Labels for MR as a comma-separated list - `labels` (optional) - Labels for MR as a comma-separated list
- `milestone_id` (optional) - Milestone ID
```json ```json
{ {
......
...@@ -71,6 +71,7 @@ module API ...@@ -71,6 +71,7 @@ module API
# title (required) - Title of MR # title (required) - Title of MR
# description - Description of MR # description - Description of MR
# labels (optional) - Labels for MR as a comma-separated list # labels (optional) - Labels for MR as a comma-separated list
# milestone_id (optional) - Milestone ID
# #
# Example: # Example:
# POST /projects/:id/merge_requests # POST /projects/:id/merge_requests
...@@ -78,7 +79,7 @@ module API ...@@ -78,7 +79,7 @@ module API
post ":id/merge_requests" do post ":id/merge_requests" do
authorize! :create_merge_request, user_project authorize! :create_merge_request, user_project
required_attributes! [:source_branch, :target_branch, :title] required_attributes! [:source_branch, :target_branch, :title]
attrs = attributes_for_keys [:source_branch, :target_branch, :assignee_id, :title, :target_project_id, :description] attrs = attributes_for_keys [:source_branch, :target_branch, :assignee_id, :title, :target_project_id, :description, :milestone_id]
# Validate label names in advance # Validate label names in advance
if (errors = validate_label_params(params)).any? if (errors = validate_label_params(params)).any?
...@@ -163,11 +164,12 @@ module API ...@@ -163,11 +164,12 @@ module API
# state_event - Status of MR. (close|reopen|merge) # state_event - Status of MR. (close|reopen|merge)
# description - Description of MR # description - Description of MR
# labels (optional) - Labels for a MR as a comma-separated list # labels (optional) - Labels for a MR as a comma-separated list
# milestone_id (optional) - Milestone ID
# Example: # Example:
# PUT /projects/:id/merge_requests/:merge_request_id # PUT /projects/:id/merge_requests/:merge_request_id
# #
put path do put path do
attrs = attributes_for_keys [:target_branch, :assignee_id, :title, :state_event, :description] attrs = attributes_for_keys [:target_branch, :assignee_id, :title, :state_event, :description, :milestone_id]
merge_request = user_project.merge_requests.find(params[:merge_request_id]) merge_request = user_project.merge_requests.find(params[:merge_request_id])
authorize! :update_merge_request, merge_request authorize! :update_merge_request, merge_request
......
...@@ -10,6 +10,7 @@ describe API::API, api: true do ...@@ -10,6 +10,7 @@ describe API::API, api: true do
let!(:merge_request_merged) { create(:merge_request, state: "merged", author: user, assignee: user, source_project: project, target_project: project, title: "Merged test", created_at: base_time + 2.seconds) } let!(:merge_request_merged) { create(:merge_request, state: "merged", author: user, assignee: user, source_project: project, target_project: project, title: "Merged test", created_at: base_time + 2.seconds) }
let!(:note) { create(:note_on_merge_request, author: user, project: project, noteable: merge_request, note: "a comment on a MR") } let!(:note) { create(:note_on_merge_request, author: user, project: project, noteable: merge_request, note: "a comment on a MR") }
let!(:note2) { create(:note_on_merge_request, author: user, project: project, noteable: merge_request, note: "another comment on a MR") } let!(:note2) { create(:note_on_merge_request, author: user, project: project, noteable: merge_request, note: "another comment on a MR") }
let(:milestone) { create(:milestone, title: '1.0.0', project: project) }
before do before do
project.team << [user, :reporters] project.team << [user, :reporters]
...@@ -170,10 +171,12 @@ describe API::API, api: true do ...@@ -170,10 +171,12 @@ describe API::API, api: true do
source_branch: 'feature_conflict', source_branch: 'feature_conflict',
target_branch: 'master', target_branch: 'master',
author: user, author: user,
labels: 'label, label2' labels: 'label, label2',
milestone_id: milestone.id
expect(response.status).to eq(201) expect(response.status).to eq(201)
expect(json_response['title']).to eq('Test merge_request') expect(json_response['title']).to eq('Test merge_request')
expect(json_response['labels']).to eq(['label', 'label2']) expect(json_response['labels']).to eq(['label', 'label2'])
expect(json_response['milestone']['id']).to eq(milestone.id)
end end
it "should return 422 when source_branch equals target_branch" do it "should return 422 when source_branch equals target_branch" do
...@@ -374,18 +377,24 @@ describe API::API, api: true do ...@@ -374,18 +377,24 @@ describe API::API, api: true do
end end
describe "PUT /projects/:id/merge_requests/:merge_request_id" do describe "PUT /projects/:id/merge_requests/:merge_request_id" do
it "should return merge_request" do it "updates title and returns merge_request" do
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), title: "New title" put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), title: "New title"
expect(response.status).to eq(200) expect(response.status).to eq(200)
expect(json_response['title']).to eq('New title') expect(json_response['title']).to eq('New title')
end end
it "should return merge_request" do it "updates description and returns merge_request" do
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), description: "New description" put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), description: "New description"
expect(response.status).to eq(200) expect(response.status).to eq(200)
expect(json_response['description']).to eq('New description') expect(json_response['description']).to eq('New description')
end end
it "updates milestone_id and returns merge_request" do
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), milestone_id: milestone.id
expect(response.status).to eq(200)
expect(json_response['milestone']['id']).to eq(milestone.id)
end
it "should return 400 when source_branch is specified" do it "should return 400 when source_branch is specified" do
put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user), put api("/projects/#{project.id}/merge_requests/#{merge_request.id}", user),
source_branch: "master", target_branch: "master" source_branch: "master", target_branch: "master"
......
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