Skip to content
Snippets Groups Projects
Commit eade74bf authored by Luke Duncalfe's avatar Luke Duncalfe Committed by Mayra Cabrera
Browse files

Move Jira integration model to `Integrations::` namespace [RUN AS-IF-FOSS] [RUN ALL RSPEC]

parent 6c203b47
No related branches found
No related tags found
No related merge requests found
Showing
with 42 additions and 40 deletions
Loading
@@ -71,7 +71,7 @@
Loading
@@ -71,7 +71,7 @@
expect(finder).to receive(:execute).and_return(jira_issues) expect(finder).to receive(:execute).and_return(jira_issues)
end end
   
expect_next_instance_of(Integrations::Jira::IssueSerializer) do |serializer| expect_next_instance_of(Integrations::JiraSerializers::IssueSerializer) do |serializer|
expect(serializer).to receive(:represent).with(jira_issues, project: project) expect(serializer).to receive(:represent).with(jira_issues, project: project)
end end
   
Loading
@@ -203,11 +203,11 @@
Loading
@@ -203,11 +203,11 @@
before do before do
stub_licensed_features(jira_issues_integration: true) stub_licensed_features(jira_issues_integration: true)
   
expect_next_found_instance_of(JiraService) do |service| expect_next_found_instance_of(Integrations::Jira) do |service|
expect(service).to receive(:find_issue).with('1', rendered_fields: true).and_return(jira_issue) expect(service).to receive(:find_issue).with('1', rendered_fields: true).and_return(jira_issue)
end end
   
expect_next_instance_of(Integrations::Jira::IssueDetailSerializer) do |serializer| expect_next_instance_of(Integrations::JiraSerializers::IssueDetailSerializer) do |serializer|
expect(serializer).to receive(:represent).with(jira_issue, project: project).and_return(issue_json) expect(serializer).to receive(:represent).with(jira_issue, project: project).and_return(issue_json)
end end
end end
Loading
Loading
Loading
@@ -15,7 +15,9 @@
Loading
@@ -15,7 +15,9 @@
context 'when Jira connection test succeeds' do context 'when Jira connection test succeeds' do
before do before do
stub_licensed_features(jira_issues_integration: true) stub_licensed_features(jira_issues_integration: true)
allow_any_instance_of(JiraService).to receive(:issues_enabled) { true } allow_next_instance_of(Integrations::Jira) do |instance|
allow(instance).to receive(:issues_enabled) { true }
end
   
visit_project_integration('Jira') visit_project_integration('Jira')
fill_form fill_form
Loading
Loading
Loading
@@ -184,7 +184,7 @@
Loading
@@ -184,7 +184,7 @@
describe '#create_jira_issue_url_for' do describe '#create_jira_issue_url_for' do
subject { helper.vulnerability_details(vulnerability, pipeline) } subject { helper.vulnerability_details(vulnerability, pipeline) }
   
let(:jira_service) { double('JiraService', new_issue_url_with_predefined_fields: 'https://jira.example.com/new') } let(:jira_service) { double('Integrations::Jira', new_issue_url_with_predefined_fields: 'https://jira.example.com/new') }
   
before do before do
allow(helper).to receive(:can?).and_return(true) allow(helper).to receive(:can?).and_return(true)
Loading
@@ -231,7 +231,7 @@
Loading
@@ -231,7 +231,7 @@
subject subject
end end
   
it 'delegates rendering URL to JiraService' do it 'delegates rendering URL to Integrations::Jira' do
expect(jira_service).to receive(:new_issue_url_with_predefined_fields).with("Investigate vulnerability: #{vulnerability.title}", expected_jira_issue_description) expect(jira_service).to receive(:new_issue_url_with_predefined_fields).with("Investigate vulnerability: #{vulnerability.title}", expected_jira_issue_description)
   
subject subject
Loading
Loading
Loading
@@ -12,7 +12,7 @@
Loading
@@ -12,7 +12,7 @@
subject { described_class.new(context) } subject { described_class.new(context) }
   
describe 'render?' do describe 'render?' do
context 'when issue tracker is not a JiraService' do context 'when issue tracker is not Jira' do
it 'returns false' do it 'returns false' do
create(:custom_issue_tracker_service, active: true, project: project, project_url: 'http://test.com') create(:custom_issue_tracker_service, active: true, project: project, project_url: 'http://test.com')
   
Loading
@@ -20,7 +20,7 @@
Loading
@@ -20,7 +20,7 @@
end end
end end
   
context 'when issue tracker is a JiraService' do context 'when issue tracker is Jira' do
let!(:jira) { create(:jira_service, project: project, project_key: 'GL') } let!(:jira) { create(:jira_service, project: project, project_key: 'GL') }
   
context 'when issues integration is disabled' do context 'when issues integration is disabled' do
Loading
Loading
Loading
@@ -2,7 +2,7 @@
Loading
@@ -2,7 +2,7 @@
   
require 'spec_helper' require 'spec_helper'
   
RSpec.describe JiraService do RSpec.describe Integrations::Jira do
let(:jira_service) { build(:jira_service, **options) } let(:jira_service) { build(:jira_service, **options) }
let(:headers) { { 'Content-Type' => 'application/json' } } let(:headers) { { 'Content-Type' => 'application/json' } }
   
Loading
@@ -167,11 +167,11 @@
Loading
@@ -167,11 +167,11 @@
end end
   
before do 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, %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, /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, %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)
WebMock.stub_request(:get, /api\/2\/issuetype\z/).to_return(body: issue_types_response.to_json, headers: headers) WebMock.stub_request(:get, %r{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, %r{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) WebMock.stub_request(:get, %r{api/2/issuetypescheme/mapping\?issueTypeSchemeId\=10126\z}).to_return(body: issue_type_mapping_response.to_json, headers: headers)
end 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: { issuetypes: [{ id: '10001', name: 'Bug', description: 'Jira Bug' }] }) }
Loading
@@ -236,8 +236,8 @@
Loading
@@ -236,8 +236,8 @@
allow(jira_service.data_fields).to receive(:deployment_cloud?).and_return(false) allow(jira_service.data_fields).to receive(:deployment_cloud?).and_return(false)
allow(jira_service.data_fields).to receive(:deployment_server?).and_return(true) allow(jira_service.data_fields).to receive(:deployment_server?).and_return(true)
   
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, %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, /api\/2\/issuetype\z/).to_return(body: issue_types_response.to_json, headers: headers) WebMock.stub_request(:get, %r{api/2/issuetype\z}).to_return(body: issue_types_response.to_json, headers: headers)
end 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" }] }) } 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" }] }) }
Loading
Loading
Loading
@@ -2,7 +2,7 @@
Loading
@@ -2,7 +2,7 @@
   
require 'spec_helper' require 'spec_helper'
   
RSpec.describe Integrations::Jira::IssueDetailEntity do RSpec.describe Integrations::JiraSerializers::IssueDetailEntity do
include JiraServiceHelper include JiraServiceHelper
   
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
Loading
Loading
Loading
@@ -2,7 +2,7 @@
Loading
@@ -2,7 +2,7 @@
   
require 'spec_helper' require 'spec_helper'
   
RSpec.describe Integrations::Jira::IssueEntity do RSpec.describe Integrations::JiraSerializers::IssueEntity do
include JiraServiceHelper include JiraServiceHelper
   
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
Loading
Loading
Loading
@@ -2,7 +2,7 @@
Loading
@@ -2,7 +2,7 @@
   
require 'spec_helper' require 'spec_helper'
   
RSpec.describe Integrations::Jira::IssueSerializer do RSpec.describe Integrations::JiraSerializers::IssueSerializer do
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
let_it_be(:jira_service) { create(:jira_service, project: project) } let_it_be(:jira_service) { create(:jira_service, project: project) }
   
Loading
Loading
Loading
@@ -102,7 +102,7 @@
Loading
@@ -102,7 +102,7 @@
   
before do before do
stub_licensed_features(jira_vulnerabilities_integration: true) stub_licensed_features(jira_vulnerabilities_integration: true)
allow_next_found_instance_of(JiraService) do |jira| allow_next_found_instance_of(Integrations::Jira) do |jira|
allow(jira).to receive(:jira_project_id).and_return('11223') allow(jira).to receive(:jira_project_id).and_return('11223')
end end
end end
Loading
Loading
Loading
@@ -784,6 +784,7 @@ def self.service_classes
Loading
@@ -784,6 +784,7 @@ def self.service_classes
::Integrations::Datadog, ::Integrations::Datadog,
::Integrations::EmailsOnPush, ::Integrations::EmailsOnPush,
::Integrations::Ewm, ::Integrations::Ewm,
::Integrations::Jira,
::Integrations::Redmine, ::Integrations::Redmine,
::Integrations::Youtrack, ::Integrations::Youtrack,
::BuildkiteService, ::BuildkiteService,
Loading
@@ -794,7 +795,6 @@ def self.service_classes
Loading
@@ -794,7 +795,6 @@ def self.service_classes
::HangoutsChatService, ::HangoutsChatService,
::IrkerService, ::IrkerService,
::JenkinsService, ::JenkinsService,
::JiraService,
::MattermostSlashCommandsService, ::MattermostSlashCommandsService,
::SlackSlashCommandsService, ::SlackSlashCommandsService,
::PackagistService, ::PackagistService,
Loading
Loading
Loading
@@ -5,7 +5,7 @@ module Integrations
Loading
@@ -5,7 +5,7 @@ module Integrations
class StiType < ActiveRecord::Type::String class StiType < ActiveRecord::Type::String
NAMESPACED_INTEGRATIONS = Set.new(%w( NAMESPACED_INTEGRATIONS = Set.new(%w(
Asana Assembla Bamboo Bugzilla Campfire Confluence CustomIssueTracker Datadog Asana Assembla Bamboo Bugzilla Campfire Confluence CustomIssueTracker Datadog
EmailsOnPush Ewm IssueTracker Redmine Youtrack EmailsOnPush Ewm IssueTracker Jira Redmine Youtrack
)).freeze )).freeze
   
def cast(value) def cast(value)
Loading
Loading
Loading
@@ -227,7 +227,7 @@ def jira_service_data
Loading
@@ -227,7 +227,7 @@ def jira_service_data
} }
   
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
JiraService.active.includes(:jira_tracker_data).find_in_batches(batch_size: 100) do |services| ::Integrations::Jira.active.includes(:jira_tracker_data).find_in_batches(batch_size: 100) do |services|
counts = services.group_by do |service| counts = services.group_by do |service|
# TODO: Simplify as part of https://gitlab.com/gitlab-org/gitlab/issues/29404 # TODO: Simplify as part of https://gitlab.com/gitlab-org/gitlab/issues/29404
service_url = service.data_fields&.url || (service.properties && service.properties['url']) service_url = service.data_fields&.url || (service.properties && service.properties['url'])
Loading
Loading
Loading
@@ -18662,6 +18662,9 @@ msgstr ""
Loading
@@ -18662,6 +18662,9 @@ msgstr ""
msgid "JiraService|GitLab for Jira Configuration" msgid "JiraService|GitLab for Jira Configuration"
msgstr "" msgstr ""
   
msgid "JiraService|IDs must be a list of numbers that can be split with , or ;"
msgstr ""
msgid "JiraService|If different from Web URL." msgid "JiraService|If different from Web URL."
msgstr "" msgstr ""
   
Loading
@@ -18677,10 +18680,10 @@ msgstr ""
Loading
@@ -18677,10 +18680,10 @@ msgstr ""
msgid "JiraService|Jira Issues" msgid "JiraService|Jira Issues"
msgstr "" msgstr ""
   
msgid "JiraService|Jira comments will be created when an issue gets referenced in a commit." msgid "JiraService|Jira comments are created when an issue is referenced in a commit."
msgstr "" msgstr ""
   
msgid "JiraService|Jira comments will be created when an issue gets referenced in a merge request." msgid "JiraService|Jira comments are created when an issue is referenced in a merge request."
msgstr "" msgstr ""
   
msgid "JiraService|Jira issue type" msgid "JiraService|Jira issue type"
Loading
@@ -18770,9 +18773,6 @@ msgstr ""
Loading
@@ -18770,9 +18773,6 @@ msgstr ""
msgid "JiraService|You need to configure Jira before enabling this integration. For more details, read the %{jira_doc_link_start}Jira integration documentation%{link_end}." msgid "JiraService|You need to configure Jira before enabling this integration. For more details, read the %{jira_doc_link_start}Jira integration documentation%{link_end}."
msgstr "" msgstr ""
   
msgid "JiraService|transition ids can have only numbers which can be split with , or ;"
msgstr ""
msgid "Job" msgid "Job"
msgstr "" msgstr ""
   
Loading
Loading
Loading
@@ -93,8 +93,8 @@
Loading
@@ -93,8 +93,8 @@
end end
   
it 'deletes the integration and all inheriting integrations' do it 'deletes the integration and all inheriting integrations' do
expect { subject }.to change { JiraService.for_instance.count }.by(-1) expect { subject }.to change { Integrations::Jira.for_instance.count }.by(-1)
.and change { JiraService.inherit_from_id(integration.id).count }.by(-1) .and change { Integrations::Jira.inherit_from_id(integration.id).count }.by(-1)
end end
end end
end end
Loading
@@ -124,8 +124,8 @@
Loading
@@ -124,8 +124,8 @@
end end
   
it 'deletes the integration and all inheriting integrations' do it 'deletes the integration and all inheriting integrations' do
expect { subject }.to change { JiraService.for_group(group.id).count }.by(-1) expect { subject }.to change { Integrations::Jira.for_group(group.id).count }.by(-1)
.and change { JiraService.inherit_from_id(integration.id).count }.by(-1) .and change { Integrations::Jira.inherit_from_id(integration.id).count }.by(-1)
end end
end end
end end
Loading
Loading
Loading
@@ -45,7 +45,7 @@
Loading
@@ -45,7 +45,7 @@
token { 'test' } token { 'test' }
end end
   
factory :jira_service do factory :jira_service, class: 'Integrations::Jira' do
project project
active { true } active { true }
type { 'JiraService' } type { 'JiraService' }
Loading
Loading
Loading
@@ -43,7 +43,7 @@
Loading
@@ -43,7 +43,7 @@
context 'When external issue tracker is enabled and issues enabled on project settings' do context 'When external issue tracker is enabled and issues enabled on project settings' do
it 'does not hide issues tab and hides labels tab' do it 'does not hide issues tab and hides labels tab' do
allow_next_instance_of(Project) do |instance| allow_next_instance_of(Project) do |instance|
allow(instance).to receive(:external_issue_tracker).and_return(JiraService.new) allow(instance).to receive(:external_issue_tracker).and_return(Integrations::Jira.new)
end end
   
visit project_path(project) visit project_path(project)
Loading
@@ -58,7 +58,7 @@
Loading
@@ -58,7 +58,7 @@
project.issues_enabled = false project.issues_enabled = false
project.save! project.save!
allow_next_instance_of(Project) do |instance| allow_next_instance_of(Project) do |instance|
allow(instance).to receive(:external_issue_tracker).and_return(JiraService.new) allow(instance).to receive(:external_issue_tracker).and_return(Integrations::Jira.new)
end end
end end
   
Loading
Loading
Loading
@@ -2,7 +2,7 @@
Loading
@@ -2,7 +2,7 @@
   
require 'spec_helper' require 'spec_helper'
   
RSpec.describe JiraService do RSpec.describe Integrations::Jira do
include AssetsHelpers include AssetsHelpers
   
let_it_be(:project) { create(:project, :repository) } let_it_be(:project) { create(:project, :repository) }
Loading
@@ -493,7 +493,7 @@
Loading
@@ -493,7 +493,7 @@
before do before do
jira_service.jira_issue_transition_id = '999' jira_service.jira_issue_transition_id = '999'
   
# These stubs are needed to test JiraService#close_issue. # These stubs are needed to test Integrations::Jira#close_issue.
# We close the issue then do another request to API to check if it got closed. # We close the issue then do another request to API to check if it got closed.
# Here is stubbed the API return with a closed and an opened issues. # Here is stubbed the API return with a closed and an opened issues.
open_issue = JIRA::Resource::Issue.new(jira_service.client, attrs: issue_fields.deep_stringify_keys) open_issue = JIRA::Resource::Issue.new(jira_service.client, attrs: issue_fields.deep_stringify_keys)
Loading
@@ -829,7 +829,7 @@ def close_issue
Loading
@@ -829,7 +829,7 @@ def close_issue
   
context 'when disabled' do context 'when disabled' do
before do before do
allow_next_instance_of(JiraService) do |instance| allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:commit_events) { false } allow(instance).to receive(:commit_events) { false }
end end
end end
Loading
@@ -847,7 +847,7 @@ def close_issue
Loading
@@ -847,7 +847,7 @@ def close_issue
   
context 'when disabled' do context 'when disabled' do
before do before do
allow_next_instance_of(JiraService) do |instance| allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:merge_requests_events) { false } allow(instance).to receive(:merge_requests_events) { false }
end end
end end
Loading
Loading
Loading
@@ -100,7 +100,7 @@
Loading
@@ -100,7 +100,7 @@
   
context 'when service and data_fields are not persisted' do context 'when service and data_fields are not persisted' do
let(:service) do let(:service) do
JiraService.new Integrations::Jira.new
end end
   
describe 'data_fields_present?' do describe 'data_fields_present?' do
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment