Commit 5562f716 authored by Markus Koller's avatar Markus Koller

Merge branch...

Merge branch '324251-fetching-jira-issue-types-via-services-jira-test-returns-500-error-when-using-a-self-hosted' into 'master'

Match issue types schema using project key on JIRA Server

See merge request gitlab-org/gitlab!58665
parents bc9f8942 e98eae64
...@@ -89,6 +89,8 @@ module EE ...@@ -89,6 +89,8 @@ module EE
# #
# @return [Array] the array of IDs # @return [Array] the array of IDs
def project_issuetype_scheme_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 = Addressable::URI.join("#{client.options[:rest_base_path]}/", 'issuetypescheme/', 'project')
query_url.query_values = { 'projectId' => jira_project_id } query_url.query_values = { 'projectId' => jira_project_id }
...@@ -103,13 +105,24 @@ module EE ...@@ -103,13 +105,24 @@ module EE
# @return [Array] the array of IDs # @return [Array] the array of IDs
def project_issuetype_ids def project_issuetype_ids
strong_memoize(:project_issuetype_ids) do strong_memoize(:project_issuetype_ids) do
query_url = Addressable::URI.join("#{client.options[:rest_base_path]}/", 'issuetypescheme/', 'mapping') if data_fields.deployment_server?
query_url.query_values = { 'issueTypeSchemeId' => project_issuetype_scheme_ids } query_url = Addressable::URI.join("#{client.options[:rest_base_path]}/", 'project/', project_key)
client client
.get(query_url.to_s) .get(query_url.to_s)
.fetch('values', []) .fetch('issueTypes', [])
.map { |schemes| schemes['issueTypeId'] } .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
end end
......
...@@ -15,6 +15,11 @@ RSpec.describe JiraService do ...@@ -15,6 +15,11 @@ RSpec.describe JiraService do
} }
end end
before do
allow(jira_service.data_fields).to receive(:deployment_cloud?).and_return(true)
allow(jira_service.data_fields).to receive(:deployment_server?).and_return(false)
end
describe 'validations' do describe 'validations' do
it 'validates presence of project_key if issues_enabled' do it 'validates presence of project_key if issues_enabled' do
jira_service.project_key = '' jira_service.project_key = ''
...@@ -111,80 +116,150 @@ RSpec.describe JiraService do ...@@ -111,80 +116,150 @@ RSpec.describe JiraService do
end end
context 'when vulnerabilities integration is enabled' do context 'when vulnerabilities integration is enabled' do
let(:project_info_result) { { 'id' => '10000' } } before do
allow(jira_service.project).to receive(:jira_vulnerabilities_integration_enabled?).and_return(true)
end
let(:issue_type_scheme_response) do context 'when deployment type is cloud' do
{ let(:project_info_result) { { 'id' => '10000' } }
values: [
{ let(:issue_type_scheme_response) do
issueTypeScheme: { {
id: '10126', values: [
name: 'GV: Software Development Issue Type Scheme', {
defaultIssueTypeId: '10001' issueTypeScheme: {
id: '10126',
name: 'GV: Software Development Issue Type Scheme',
defaultIssueTypeId: '10001'
},
projectIds: [
'10000'
]
}
]
}
end
let(:issue_type_mapping_response) do
{
values: [
{
issueTypeSchemeId: '10126',
issueTypeId: '10003'
}, },
projectIds: [ {
'10000' issueTypeSchemeId: '10126',
] issueTypeId: '10001'
} }
] ]
} }
end end
let(:issue_type_mapping_response) do let(:issue_types_response) do
{ [
values: [ {
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
},
{ {
issueTypeSchemeId: '10126', id: '10001',
issueTypeId: '10003' description: 'Jira Bug',
name: 'Bug',
untranslatedName: 'Bug',
subtask: false,
avatarId: 10303
}, },
{ {
issueTypeSchemeId: '10126', id: '10003',
issueTypeId: '10001' description: 'A small piece of work thats part of a larger task.',
name: 'Sub-task',
untranslatedName: 'Sub-task',
subtask: true,
avatarId: 10316
} }
] ]
} end
before do
WebMock.stub_request(:get, /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, /api\/2\/project\/GL\z/).with(basic_auth: %w(gitlab_jira_username gitlab_jira_password)).to_return(body: { 'id' => '10000' }.to_json, headers: headers)
WebMock.stub_request(:get, /api\/2\/issuetype\z/).to_return(body: issue_types_response.to_json, headers: headers)
WebMock.stub_request(:get, /api\/2\/issuetypescheme\/project\?projectId\=10000\z/).to_return(body: issue_type_scheme_response.to_json, headers: headers)
WebMock.stub_request(:get, /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' }] }) }
end end
let(:issue_types_response) do context 'when deployment type is server' do
[ let(:project_info_result) do
{ {
id: '10004', "id": "10000",
description: 'A new feature of the product, which has yet to be developed.', "issueTypes": issue_types_response
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',
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 let(:issue_types_response) do
allow(jira_service.project).to receive(:jira_vulnerabilities_integration_enabled?).and_return(true) [
{
"avatarId": 10318,
"description": "A task that needs to be done.",
"iconUrl": "http://jira.reali.sh:8080/secure/viewavatar?size=xsmall&avatarId=10318&avatarType=issuetype",
"id": "10003",
"name": "Task",
"self": "http://jira.reali.sh:8080/rest/api/2/issuetype/10003",
"subtask": false
},
{
"description": "The sub-task of the issue",
"iconUrl": "http://jira.reali.sh:8080/images/icons/issuetypes/subtask_alternate.png",
"id": "10000",
"name": "Sub-task",
"self": "http://jira.reali.sh:8080/rest/api/2/issuetype/10000",
"subtask": true
},
{
"description": "Created by Jira Software - do not edit or delete. Issue type for a user story.",
"iconUrl": "http://jira.reali.sh:8080/images/icons/issuetypes/story.svg",
"id": "10002",
"name": "Story",
"self": "http://jira.reali.sh:8080/rest/api/2/issuetype/10002",
"subtask": false
},
{
"avatarId": 10303,
"description": "A problem which impairs or prevents the functions of the product.",
"iconUrl": "http://jira.reali.sh:8080/secure/viewavatar?size=xsmall&avatarId=10303&avatarType=issuetype",
"id": "10004",
"name": "Bug",
"self": "http://jira.reali.sh:8080/rest/api/2/issuetype/10004",
"subtask": false
},
{
"description": "Created by Jira Software - do not edit or delete. Issue type for a big user story that needs to be broken down.",
"iconUrl": "http://jira.reali.sh:8080/images/icons/issuetypes/epic.svg",
"id": "10001",
"name": "Epic",
"self": "http://jira.reali.sh:8080/rest/api/2/issuetype/10001",
"subtask": false
}
]
end
WebMock.stub_request(:get, /api\/2\/project\/GL/).with(basic_auth: %w(gitlab_jira_username gitlab_jira_password)).to_return(body: project_info_result.to_json ) before do
WebMock.stub_request(:get, /api\/2\/project\/GL\z/).with(basic_auth: %w(gitlab_jira_username gitlab_jira_password)).to_return(body: { 'id' => '10000' }.to_json, headers: headers) allow(jira_service.data_fields).to receive(:deployment_cloud?).and_return(false)
WebMock.stub_request(:get, /api\/2\/issuetype\z/).to_return(body: issue_types_response.to_json, headers: headers) allow(jira_service.data_fields).to receive(:deployment_server?).and_return(true)
WebMock.stub_request(:get, /api\/2\/issuetypescheme\/project\?projectId\=10000\z/).to_return(body: issue_type_scheme_response.to_json, headers: headers)
WebMock.stub_request(:get, /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' }] }) } WebMock.stub_request(:get, /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, /api\/2\/issuetype\z/).to_return(body: issue_types_response.to_json, headers: headers)
end
it { is_expected.to eq(success: true, result: { jira: true }, data: { issuetypes: [{ description: "A task that needs to be done.", id: "10003", name: "Task" }, { description: "Created by Jira Software - do not edit or delete. Issue type for a user story.", id: "10002", name: "Story" }, { description: "A problem which impairs or prevents the functions of the product.", id: "10004", name: "Bug" }, { description: "Created by Jira Software - do not edit or delete. Issue type for a big user story that needs to be broken down.", id: "10001", name: "Epic" }] }) }
end
end end
end end
end end
......
...@@ -62,6 +62,7 @@ FactoryBot.define do ...@@ -62,6 +62,7 @@ FactoryBot.define do
project_key { nil } project_key { nil }
vulnerabilities_enabled { false } vulnerabilities_enabled { false }
vulnerabilities_issuetype { nil } vulnerabilities_issuetype { nil }
deployment_type { 'cloud' }
end end
before(:create) do |service, evaluator| before(:create) do |service, evaluator|
...@@ -72,7 +73,7 @@ FactoryBot.define do ...@@ -72,7 +73,7 @@ FactoryBot.define do
jira_issue_transition_id: evaluator.jira_issue_transition_id, jira_issue_transition_id: evaluator.jira_issue_transition_id,
username: evaluator.username, password: evaluator.password, issues_enabled: evaluator.issues_enabled, username: evaluator.username, password: evaluator.password, issues_enabled: evaluator.issues_enabled,
project_key: evaluator.project_key, vulnerabilities_enabled: evaluator.vulnerabilities_enabled, project_key: evaluator.project_key, vulnerabilities_enabled: evaluator.vulnerabilities_enabled,
vulnerabilities_issuetype: evaluator.vulnerabilities_issuetype vulnerabilities_issuetype: evaluator.vulnerabilities_issuetype, deployment_type: evaluator.deployment_type
) )
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