Commit 784f240a authored by Lin Jen-Shin's avatar Lin Jen-Shin

Merge branch 'skip-enqueue-jira-connect-sync-workers' into 'master'

Only enqueue Jira workers when integration is configured

See merge request gitlab-org/gitlab!76134
parents ec228892 fd52c435
......@@ -235,6 +235,12 @@ module Ci
pipeline.run_after_commit do
PipelineHooksWorker.perform_async(pipeline.id)
if pipeline.project.jira_subscription_exists?
# Passing the seq-id ensures this is idempotent
seq_id = ::Atlassian::JiraConnect::Client.generate_update_sequence_id
::JiraConnect::SyncBuildsWorker.perform_async(pipeline.id, seq_id)
end
if Feature.enabled?(:expire_job_and_pipeline_cache_synchronously, pipeline.project, default_enabled: :yaml)
Ci::ExpirePipelineCacheService.new.execute(pipeline) # rubocop: disable CodeReuse/ServiceClass
else
......@@ -274,14 +280,6 @@ module Ci
end
end
after_transition any => any do |pipeline|
pipeline.run_after_commit do
# Passing the seq-id ensures this is idempotent
seq_id = ::Atlassian::JiraConnect::Client.generate_update_sequence_id
::JiraConnect::SyncBuildsWorker.perform_async(pipeline.id, seq_id)
end
end
after_transition any => ::Ci::Pipeline.completed_statuses do |pipeline|
pipeline.run_after_commit do
::Ci::TestFailureHistoryService.new(pipeline).async.perform_if_needed # rubocop: disable CodeReuse/ServiceClass
......
......@@ -119,6 +119,8 @@ class Deployment < ApplicationRecord
next if transition.loopback?
deployment.run_after_commit do
next unless deployment.project.jira_subscription_exists?
::JiraConnect::SyncDeploymentsWorker.perform_async(id)
end
end
......@@ -126,6 +128,8 @@ class Deployment < ApplicationRecord
after_create unless: :importing? do |deployment|
run_after_commit do
next unless deployment.project.jira_subscription_exists?
::JiraConnect::SyncDeploymentsWorker.perform_async(deployment.id)
end
end
......
......@@ -43,6 +43,7 @@ module FeatureFlags
def sync_to_jira(feature_flag)
return unless feature_flag.present?
return unless project.jira_subscription_exists?
seq_id = ::Atlassian::JiraConnect::Client.generate_update_sequence_id
feature_flag.run_after_commit do
......
......@@ -1356,6 +1356,19 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
describe 'synching status to Jira' do
let(:worker) { ::JiraConnect::SyncBuildsWorker }
context 'when Jira Connect subscription does not exist' do
it 'does not trigger a Jira synch worker' do
expect(worker).not_to receive(:perform_async)
pipeline.prepare!
end
end
context 'when Jira Connect subscription exists' do
before_all do
create(:jira_connect_subscription, namespace: project.namespace)
end
%i[prepare! run! skip! drop! succeed! cancel! block! delay!].each do |event|
context "when we call pipeline.#{event}" do
it 'triggers a Jira synch worker' do
......@@ -1366,6 +1379,7 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
end
end
end
end
describe '#duration', :sidekiq_inline do
context 'when multiple builds are finished' do
......
......@@ -269,10 +269,24 @@ RSpec.describe Deployment do
end
describe 'synching status to Jira' do
let(:deployment) { create(:deployment) }
let_it_be(:project) { create(:project, :repository) }
let(:deployment) { create(:deployment, project: project) }
let(:worker) { ::JiraConnect::SyncDeploymentsWorker }
context 'when Jira Connect subscription does not exist' do
it 'does not call the worker' do
expect(worker).not_to receive(:perform_async)
deployment
end
end
context 'when Jira Connect subscription exists' do
before_all do
create(:jira_connect_subscription, namespace: project.namespace)
end
it 'calls the worker on creation' do
expect(worker).to receive(:perform_async).with(Integer)
......@@ -298,6 +312,7 @@ RSpec.describe Deployment do
end
end
end
end
describe '#success?' do
subject { deployment.success? }
......
......@@ -62,11 +62,25 @@ RSpec.describe FeatureFlags::CreateService do
expect { subject }.to change { Operations::FeatureFlag.count }.by(1)
end
context 'when Jira Connect subscription does not exist' do
it 'does not sync the feature flag to Jira' do
expect(::JiraConnect::SyncFeatureFlagsWorker).not_to receive(:perform_async)
subject
end
end
context 'when Jira Connect subscription exists' do
before do
create(:jira_connect_subscription, namespace: project.namespace)
end
it 'syncs the feature flag to Jira' do
expect(::JiraConnect::SyncFeatureFlagsWorker).to receive(:perform_async).with(Integer, Integer)
subject
end
end
it 'creates audit event' do
expect { subject }.to change { AuditEvent.count }.by(1)
......
......@@ -27,11 +27,25 @@ RSpec.describe FeatureFlags::UpdateService do
expect(subject[:status]).to eq(:success)
end
context 'when Jira Connect subscription does not exist' do
it 'does not sync the feature flag to Jira' do
expect(::JiraConnect::SyncFeatureFlagsWorker).not_to receive(:perform_async)
subject
end
end
context 'when Jira Connect subscription exists' do
before do
create(:jira_connect_subscription, namespace: project.namespace)
end
it 'syncs the feature flag to Jira' do
expect(::JiraConnect::SyncFeatureFlagsWorker).to receive(:perform_async).with(Integer, Integer)
subject
end
end
it 'creates audit event with correct message' do
name_was = feature_flag.name
......
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