Commit 4f3d004e authored by Sean McGivern's avatar Sean McGivern

Merge branch...

Merge branch '330932-vulnerabilities-jira-integration-doesn-t-work-with-jira-next-gen-projects' into 'master'

Handle team-managed (next-gen) Jira projects

See merge request gitlab-org/gitlab!66250
parents e3b511aa 514e4dab
...@@ -87,59 +87,22 @@ module EE ...@@ -87,59 +87,22 @@ module EE
end end
end end
# Returns list of Issue Type Scheme IDs in selected JIRA Project # Returns list of available Issue types in selected JIRA Project
#
# @return [Array] the array of IDs
def project_issuetype_scheme_ids
raise NotImplementedError unless data_fields.deployment_cloud?
query_url = Addressable::URI.join("#{client.options[:rest_base_path]}/", 'issuetypescheme/', 'project')
query_url.query_values = { 'projectId' => jira_project_id }
client
.get(query_url.to_s)
.fetch('values', [])
.map { |schemes| schemes.dig('issueTypeScheme', 'id') }
end
# Returns list of Issue Type IDs available in active Issue Type Scheme in selected JIRA Project
#
# @return [Array] the array of IDs
def project_issuetype_ids
strong_memoize(:project_issuetype_ids) do
if data_fields.deployment_server?
query_url = Addressable::URI.join("#{client.options[:rest_base_path]}/", 'project/', project_key)
client
.get(query_url.to_s)
.fetch('issueTypes', [])
.map { |issue_type| issue_type['id'] }
elsif data_fields.deployment_cloud?
query_url = Addressable::URI.join("#{client.options[:rest_base_path]}/", 'issuetypescheme/', 'mapping')
query_url.query_values = { 'issueTypeSchemeId' => project_issuetype_scheme_ids }
client
.get(query_url.to_s)
.fetch('values', [])
.map { |schemes| schemes['issueTypeId'] }
else
raise NotImplementedError
end
end
end
# Returns list of available Issue tTpes in selected JIRA Project
# #
# @return [Array] the array of objects with JIRA Issuetype ID, Name and Description # @return [Array] the array of objects with JIRA Issuetype ID, Name and Description
def issue_types def issue_types
return [] if jira_project.blank? return [] if jira_project.blank?
client jira_project
.Issuetype .issuetypes
.all
.select { |issue_type| issue_type.id.in?(project_issuetype_ids) }
.reject { |issue_type| issue_type.subtask } .reject { |issue_type| issue_type.subtask }
.map { |issue_type| { id: issue_type.id, name: issue_type.name, description: issue_type.description } } .map do |issue_type|
{
id: issue_type.id,
name: issue_type.name,
description: issue_type.description
}
end
end end
end end
end end
......
...@@ -103,78 +103,93 @@ RSpec.describe Integrations::Jira do ...@@ -103,78 +103,93 @@ RSpec.describe Integrations::Jira do
end end
context 'when deployment type is cloud' do context 'when deployment type is cloud' do
let(:project_info_result) { { 'id' => '10000' } } let(:project_info_result) do
let(:issue_type_scheme_response) do
{ {
values: [ 'id' => '10000',
'style' => jira_project_style,
'issueTypes' => project_issue_types
}
end
context 'when JIRA project style is classic' do
let(:jira_project_style) { 'classic' }
let(:project_issue_types) do
[
{ {
issueTypeScheme: { id: '10001',
id: '10126', description: 'Jira Bug',
name: 'GV: Software Development Issue Type Scheme', name: 'Bug',
defaultIssueTypeId: '10001' untranslatedName: 'Bug',
}, subtask: false,
projectIds: [ avatarId: 10303
'10000' },
] {
id: '10003',
description: 'A small piece of work thats part of a larger task.',
name: 'Sub-task',
untranslatedName: 'Sub-task',
subtask: true,
avatarId: 10316
} }
] ]
} end
let(:expected_data) do
{
issuetypes: project_issue_types.select { |it| !it[:subtask] }.map { |it| it.slice(*%i[id name description]) }
}
end
before do
WebMock.stub_request(:get, %r{api/2/project/GL}).with(basic_auth: %w(gitlab_jira_username gitlab_jira_password)).to_return(body: project_info_result.to_json )
end
it { is_expected.to eq(success: true, result: { jira: true }, data: { issuetypes: [{ id: '10001', name: 'Bug', description: 'Jira Bug' }] }) }
end end
let(:issue_type_mapping_response) do context 'when JIRA project style is next-gen' do
{ let(:jira_project_style) { 'next-gen' }
values: [ let(:project_issue_types) do
[
{ {
issueTypeSchemeId: '10126', id: '2137',
issueTypeId: '10003' description: 'Very new, yes',
name: 'Next Gen Issue Type 1',
untranslatedName: 'Next Gen Issue Type 1',
subtask: false,
avatarId: 10311
}, },
{ {
issueTypeSchemeId: '10126', id: '2138',
issueTypeId: '10001' description: 'Something',
name: 'Next Gen Issue Type 2',
untranslatedName: 'Next Gen Issue Type 2',
subtask: false,
avatarId: 10303
},
{
id: '2139',
description: 'Subtasks? Meh.',
name: 'Next Gen Issue Type 3',
untranslatedName: 'Next Gen Issue Type 3',
subtask: true,
avatarId: 10316
} }
] ]
} end
end
let(:issue_types_response) do let(:expected_data) do
[
{
id: '10004',
description: 'A new feature of the product, which has yet to be developed.',
name: 'New Feature',
untranslatedName: 'New Feature',
subtask: false,
avatarId: 10311
},
{
id: '10001',
description: 'Jira Bug',
name: 'Bug',
untranslatedName: 'Bug',
subtask: false,
avatarId: 10303
},
{ {
id: '10003', issuetypes: project_issue_types.select { |it| !it[:subtask] }.map { |it| it.slice(*%i[id name description]) }
description: 'A small piece of work thats part of a larger task.',
name: 'Sub-task',
untranslatedName: 'Sub-task',
subtask: true,
avatarId: 10316
} }
] end
end
before do before do
WebMock.stub_request(:get, %r{api/2/project/GL}).with(basic_auth: %w(gitlab_jira_username gitlab_jira_password)).to_return(body: project_info_result.to_json ) WebMock.stub_request(:get, %r{api/2/project/GL}).with(basic_auth: %w(gitlab_jira_username gitlab_jira_password)).to_return(body: project_info_result.to_json, headers: headers)
WebMock.stub_request(:get, %r{api/2/project/GL\z}).with(basic_auth: %w(gitlab_jira_username gitlab_jira_password)).to_return(body: { 'id' => '10000' }.to_json, headers: headers) end
WebMock.stub_request(:get, %r{api/2/issuetype\z}).to_return(body: issue_types_response.to_json, headers: headers)
WebMock.stub_request(:get, %r{api/2/issuetypescheme/project\?projectId\=10000\z}).to_return(body: issue_type_scheme_response.to_json, headers: headers)
WebMock.stub_request(:get, %r{api/2/issuetypescheme/mapping\?issueTypeSchemeId\=10126\z}).to_return(body: issue_type_mapping_response.to_json, headers: headers)
end
it { is_expected.to eq(success: true, result: { jira: true }, data: { issuetypes: [{ id: '10001', name: 'Bug', description: 'Jira Bug' }] }) } it { is_expected.to eq(success: true, result: { jira: true }, data: expected_data) }
end
end end
context 'when deployment type is server' do context 'when deployment type is server' 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