Commit d12901d0 authored by Max Woolf's avatar Max Woolf

Merge branch 'sy-create-incidents-via-api' into 'master'

Add issue_type support for REST API

See merge request gitlab-org/gitlab!60687
parents 90dcc626 d847e797
......@@ -25,7 +25,7 @@
# updated_after: datetime
# updated_before: datetime
# confidential: boolean
# issue_type: array of strings (one of Issue.issue_types)
# issue_types: array of strings (one of Issue.issue_types)
#
class IssuesFinder < IssuableFinder
CONFIDENTIAL_ACCESS_LEVEL = Gitlab::Access::REPORTER
......
---
title: Add support for create, updating, and filtering issues based on issue type
in REST API
merge_request: 60687
author:
type: added
This diff is collapsed.
......@@ -471,7 +471,7 @@ RSpec.describe API::Issues, :mailer do
end
end
describe 'PUT /projects/:id/issues/:issue_id to update weight' do
describe 'PUT /projects/:id/issues/:issue_iid to update weight' do
let!(:issue) { create :issue, author: user, project: project }
it 'updates an issue with no weight' do
......@@ -531,14 +531,14 @@ RSpec.describe API::Issues, :mailer do
end
end
describe 'PUT /projects/:id/issues/:issue_id to update epic' do
describe 'PUT /projects/:id/issues/:issue_iid to update epic' do
it_behaves_like 'with epic parameter' do
let(:issue_with_epic) { create(:issue, project: target_project) }
let(:request) { put api("/projects/#{target_project.id}/issues/#{issue_with_epic.iid}", user), params: params }
end
end
describe 'POST /projects/:id/issues/:issue_id/metric_images' do
describe 'POST /projects/:id/issues/:issue_iid/metric_images' do
include WorkhorseHelpers
using RSpec::Parameterized::TableSyntax
......@@ -643,7 +643,7 @@ RSpec.describe API::Issues, :mailer do
end
end
describe 'GET /projects/:id/issues/:issue_id/metric_images' do
describe 'GET /projects/:id/issues/:issue_iid/metric_images' do
using RSpec::Parameterized::TableSyntax
let_it_be(:project) do
......@@ -701,7 +701,7 @@ RSpec.describe API::Issues, :mailer do
end
end
describe 'DELETE /projects/:id/issues/:issue_id/metric_images/:metric_image_id' do
describe 'DELETE /projects/:id/issues/:issue_iid/metric_images/:metric_image_id' do
using RSpec::Parameterized::TableSyntax
let_it_be(:project) do
......
......@@ -36,6 +36,7 @@ module API
expose :due_date
expose :confidential
expose :discussion_locked
expose :issue_type
expose :web_url do |issue|
Gitlab::UrlBuilder.build(issue)
......
......@@ -28,7 +28,8 @@ module API
:remove_labels,
:milestone_id,
:state_event,
:title
:title,
:issue_type
]
end
......@@ -47,6 +48,7 @@ module API
args[:not][:label_name] ||= args[:not]&.delete(:labels)
args[:scope] = args[:scope].underscore if args[:scope]
args[:sort] = "#{args[:order_by]}_#{args[:sort]}"
args[:issue_types] ||= args.delete(:issue_type)
IssuesFinder.new(current_user, args)
end
......
......@@ -74,6 +74,7 @@ module API
desc: 'Return issues sorted in `asc` or `desc` order.'
optional :due_date, type: String, values: %w[0 overdue week month next_month_and_previous_two_weeks] << '',
desc: 'Return issues that have no due date (`0`), or whose due date is this week, this month, between two weeks ago and next month, or which are overdue. Accepts: `overdue`, `week`, `month`, `next_month_and_previous_two_weeks`, `0`'
optional :issue_type, type: String, values: Issue.issue_types.keys, desc: "The type of the issue. Accepts: #{Issue.issue_types.keys.join(', ')}"
use :issues_stats_params
use :pagination
......@@ -90,6 +91,7 @@ module API
optional :due_date, type: String, desc: 'Date string in the format YEAR-MONTH-DAY'
optional :confidential, type: Boolean, desc: 'Boolean parameter if the issue should be confidential'
optional :discussion_locked, type: Boolean, desc: " Boolean parameter indicating if the issue's discussion is locked"
optional :issue_type, type: String, values: Issue.issue_types.keys, desc: "The type of the issue. Accepts: #{Issue.issue_types.keys.join(', ')}"
use :optional_issue_params_ee
end
......
......@@ -115,6 +115,7 @@ RSpec.describe API::Issues do
expect(response).to have_gitlab_http_status(:ok)
expect(json_response.dig('author', 'id')).to eq(issue.author.id)
expect(json_response['description']).to eq(issue.description)
expect(json_response['issue_type']).to eq('issue')
end
end
......@@ -378,6 +379,14 @@ RSpec.describe API::Issues do
expect_paginated_array_response([issue.id, closed_issue.id])
end
it 'returns issues with a given issue_type' do
issue2 = create(:incident, project: project)
get api('/issues', user), params: { issue_type: 'incident' }
expect_paginated_array_response(issue2.id)
end
it 'returns issues matching given search string for title' do
get api('/issues', user), params: { search: issue.title }
......@@ -939,7 +948,17 @@ RSpec.describe API::Issues do
end
end
describe 'PUT /projects/:id/issues/:issue_id' do
describe "POST /projects/:id/issues" do
it 'creates a new project issue' do
post api("/projects/#{project.id}/issues", user), params: { title: 'new issue' }
expect(response).to have_gitlab_http_status(:created)
expect(json_response['title']).to eq('new issue')
expect(json_response['issue_type']).to eq('issue')
end
end
describe 'PUT /projects/:id/issues/:issue_iid' do
it_behaves_like 'issuable update endpoint' do
let(:entity) { issue }
end
......@@ -971,6 +990,14 @@ RSpec.describe API::Issues do
expect(ResourceLabelEvent.last.created_at).to be_like_time(fixed_time)
end
end
describe 'issue_type param' do
it 'allows issue type to be converted' do
put api("/projects/#{project.id}/issues/#{issue.iid}", user), params: { issue_type: 'incident' }
expect(issue.reload.incident?).to be(true)
end
end
end
describe 'DELETE /projects/:id/issues/:issue_iid' do
......
......@@ -3,7 +3,7 @@
RSpec.shared_examples 'issuable update endpoint' do
let(:area) { entity.class.name.underscore.pluralize }
describe 'PUT /projects/:id/issues/:issue_id' do
describe 'PUT /projects/:id/issues/:issue_iid' do
let(:url) { "/projects/#{project.id}/#{area}/#{entity.iid}" }
it 'clears labels when labels param is nil' do
......
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