Commit dcd62987 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch '219381-issue-type-param-when-creating-issues' into 'master'

Set issue_type to incident for new incidents

See merge request gitlab-org/gitlab!38760
parents 7491f8b9 06969ef3
......@@ -88,6 +88,7 @@ export default {
'projectPath',
'newIssuePath',
'incidentTemplateName',
'incidentType',
'issuePath',
'publishedAvailable',
],
......@@ -179,7 +180,13 @@ export default {
};
},
newIncidentPath() {
return mergeUrlParams({ issuable_template: this.incidentTemplateName }, this.newIssuePath);
return mergeUrlParams(
{
issuable_template: this.incidentTemplateName,
'issue[issue_type]': this.incidentType,
},
this.newIssuePath,
);
},
availableFields() {
return this.publishedAvailable
......
......@@ -12,6 +12,7 @@ export default () => {
projectPath,
newIssuePath,
incidentTemplateName,
incidentType,
issuePath,
publishedAvailable,
} = domEl.dataset;
......@@ -25,6 +26,7 @@ export default () => {
provide: {
projectPath,
incidentTemplateName,
incidentType,
newIssuePath,
issuePath,
publishedAvailable,
......
......@@ -90,7 +90,7 @@ class Projects::IssuesController < Projects::ApplicationController
params[:issue] ||= ActionController::Parameters.new(
assignee_ids: ""
)
build_params = issue_params.merge(
build_params = issue_create_params.merge(
merge_request_to_resolve_discussions_of: params[:merge_request_to_resolve_discussions_of],
discussion_to_resolve: params[:discussion_to_resolve],
confidential: !!Gitlab::Utils.to_boolean(params[:issue][:confidential])
......@@ -110,7 +110,7 @@ class Projects::IssuesController < Projects::ApplicationController
end
def create
create_params = issue_params.merge(spammable_params).merge(
create_params = issue_create_params.merge(spammable_params).merge(
merge_request_to_resolve_discussions_of: params[:merge_request_to_resolve_discussions_of],
discussion_to_resolve: params[:discussion_to_resolve]
)
......@@ -293,6 +293,16 @@ class Projects::IssuesController < Projects::ApplicationController
] + [{ label_ids: [], assignee_ids: [], update_task: [:index, :checked, :line_number, :line_source] }]
end
def issue_create_params
create_params = %i[
issue_type
]
params.require(:issue).permit(
*create_params
).merge(issue_params)
end
def reorder_params
params.permit(:move_before_id, :move_after_id, :group_full_path)
end
......
......@@ -6,6 +6,7 @@ module Projects::IncidentsHelper
'project-path' => project.full_path,
'new-issue-path' => new_project_issue_path(project),
'incident-template-name' => 'incident',
'incident-type' => 'incident',
'issue-path' => project_issues_path(project)
}
end
......
......@@ -66,7 +66,7 @@ module Issues
def whitelisted_issue_params
base_params = [:title, :description, :confidential]
admin_params = [:milestone_id]
admin_params = [:milestone_id, :issue_type]
if can?(current_user, :admin_issue, project)
params.slice(*(base_params + admin_params))
......
......@@ -83,4 +83,7 @@
= render_if_exists 'shared/issuable/remove_approver'
- if issuable.respond_to?(:issue_type)
= form.hidden_field :issue_type
= form.hidden_field :lock_version
---
title: Set Incident issue type when creating issue
merge_request: 38760
author:
type: added
......@@ -16,6 +16,7 @@ RSpec.describe Projects::IncidentsHelper do
'project-path' => project_path,
'new-issue-path' => new_issue_path,
'incident-template-name' => 'incident',
'incident-type' => 'incident',
'issue-path' => issue_path
}
end
......
......@@ -181,10 +181,11 @@ RSpec.describe Projects::IssuesController do
project.add_developer(user)
end
it 'builds a new issue' do
it 'builds a new issue', :aggregate_failures do
get :new, params: { namespace_id: project.namespace, project_id: project }
expect(assigns(:issue)).to be_a_new(Issue)
expect(assigns(:issue).issue_type).to eq('issue')
end
where(:conf_value, :conf_result) do
......@@ -214,6 +215,24 @@ RSpec.describe Projects::IssuesController do
end
end
context 'setting issue type' do
let(:issue_type) { 'issue' }
before do
get :new, params: { namespace_id: project.namespace, project_id: project, issue: { issue_type: issue_type } }
end
subject { assigns(:issue).issue_type }
it { is_expected.to eq('issue') }
context 'incident issue' do
let(:issue_type) { 'incident' }
it { is_expected.to eq(issue_type) }
end
end
it 'fills in an issue for a merge request' do
project_with_repository = create(:project, :repository)
project_with_repository.add_developer(user)
......@@ -1049,6 +1068,14 @@ RSpec.describe Projects::IssuesController do
project.issues.first
end
it 'creates the issue successfully', :aggregate_failures do
issue = post_new_issue
expect(issue).to be_a(Issue)
expect(issue.persisted?).to eq(true)
expect(issue.issue_type).to eq('issue')
end
context 'resolving discussions in MergeRequest' do
let(:discussion) { create(:diff_note_on_merge_request).to_discussion }
let(:merge_request) { discussion.noteable }
......@@ -1289,6 +1316,20 @@ RSpec.describe Projects::IssuesController do
end
end
end
context 'setting issue type' do
let(:issue_type) { 'issue' }
subject { post_new_issue(issue_type: issue_type)&.issue_type }
it { is_expected.to eq('issue') }
context 'incident issue' do
let(:issue_type) { 'incident' }
it { is_expected.to eq(issue_type) }
end
end
end
describe 'POST #mark_as_spam' do
......
......@@ -10,7 +10,7 @@ import {
GlTabs,
GlBadge,
} from '@gitlab/ui';
import { visitUrl, joinPaths } from '~/lib/utils/url_utility';
import { visitUrl, joinPaths, mergeUrlParams } from '~/lib/utils/url_utility';
import IncidentsList from '~/incidents/components/incidents_list.vue';
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
import { I18N, INCIDENT_STATUS_TABS } from '~/incidents/constants';
......@@ -26,6 +26,7 @@ describe('Incidents List', () => {
let wrapper;
const newIssuePath = 'namespace/project/-/issues/new';
const incidentTemplateName = 'incident';
const incidentType = 'incident';
const incidentsCount = {
opened: 14,
closed: 1,
......@@ -66,6 +67,7 @@ describe('Incidents List', () => {
projectPath: '/project/path',
newIssuePath,
incidentTemplateName,
incidentType,
issuePath: '/project/isssues',
publishedAvailable: true,
},
......@@ -167,8 +169,13 @@ describe('Incidents List', () => {
});
});
it('shows the button linking to new incidents page with prefilled incident template', () => {
it('shows the button linking to new incidents page with prefilled incident template when clicked', () => {
expect(findCreateIncidentBtn().exists()).toBe(true);
findCreateIncidentBtn().trigger('click');
expect(mergeUrlParams).toHaveBeenCalledWith(
{ issuable_template: incidentTemplateName, 'issue[issue_type]': incidentType },
newIssuePath,
);
});
it('sets button loading on click', () => {
......
......@@ -18,6 +18,7 @@ RSpec.describe Projects::IncidentsHelper do
'project-path' => project_path,
'new-issue-path' => new_issue_path,
'incident-template-name' => 'incident',
'incident-type' => 'incident',
'issue-path' => issue_path
)
end
......
......@@ -147,5 +147,19 @@ RSpec.describe Issues::BuildService do
expect(issue.milestone).to be_nil
end
context 'setting issue type' do
it 'sets the issue_type on the issue' do
issue = build_issue(issue_type: 'incident')
expect(issue.issue_type).to eq('incident')
end
it 'defaults to issue if issue_type not given' do
issue = build_issue
expect(issue.issue_type).to eq('issue')
end
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