Commit b669b9d6 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'remove-resource-state-event-feature-flag' into 'master'

Remove track_resource_state_change_events flag

See merge request gitlab-org/gitlab!41287
parents 0fd618ff cba296b7
......@@ -1511,6 +1511,7 @@ class MergeRequest < ApplicationRecord
metrics&.merged_at ||
merge_event&.created_at ||
resource_state_events.find_by(state: :merged)&.created_at ||
notes.system.reorder(nil).find_by(note: 'merged')&.created_at
end
end
......
......@@ -242,19 +242,7 @@ module SystemNotes
#
# Returns the created Note object
def change_status(status, source = nil)
body = status.dup
body << " via #{source.gfm_reference(project)}" if source
action = status == 'reopened' ? 'opened' : status
# A state event which results in a synthetic note will be
# created by EventCreateService if change event tracking
# is enabled.
if state_change_tracking_enabled?
create_resource_state_event(status: status, mentionable_source: source)
else
create_note(NoteSummary.new(noteable, project, author, body, action: action))
end
create_resource_state_event(status: status, mentionable_source: source)
end
# Check if a cross reference to a noteable from a mentioner already exists
......@@ -312,23 +300,11 @@ module SystemNotes
end
def close_after_error_tracking_resolve
if state_change_tracking_enabled?
create_resource_state_event(status: 'closed', close_after_error_tracking_resolve: true)
else
body = 'resolved the corresponding error and closed the issue.'
create_note(NoteSummary.new(noteable, project, author, body, action: 'closed'))
end
create_resource_state_event(status: 'closed', close_after_error_tracking_resolve: true)
end
def auto_resolve_prometheus_alert
if state_change_tracking_enabled?
create_resource_state_event(status: 'closed', close_auto_resolve_prometheus_alert: true)
else
body = 'automatically closed this issue because the alert resolved.'
create_note(NoteSummary.new(noteable, project, author, body, action: 'closed'))
end
create_resource_state_event(status: 'closed', close_auto_resolve_prometheus_alert: true)
end
private
......@@ -361,11 +337,6 @@ module SystemNotes
.execute(params)
end
def state_change_tracking_enabled?
noteable.respond_to?(:resource_state_events) &&
::Feature.enabled?(:track_resource_state_change_events, noteable.project, default_enabled: true)
end
def issue_activity_counter
Gitlab::UsageDataCounters::IssueActivityUniqueCounter
end
......
---
name: track_resource_state_change_events
introduced_by_url:
rollout_issue_url:
group:
type: development
default_enabled: true
......@@ -42,33 +42,12 @@ RSpec.describe Epics::CloseService do
expect { subject.execute(epic) }.to change { epic.closed_at }
end
context 'when state event tracking is enabled' do
before do
stub_feature_flags(track_resource_state_change_events: true)
end
it 'creates a resource state event' do
expect { subject.execute(epic) }.to change { epic.resource_state_events.count }.by(1)
it 'creates a resource state event' do
expect { subject.execute(epic) }.to change { epic.resource_state_events.count }.by(1)
event = epic.resource_state_events.last
event = epic.resource_state_events.last
expect(event.state).to eq('closed')
end
end
context 'when state event tracking is disabled' do
before do
stub_feature_flags(track_resource_state_change_events: false)
end
it 'creates a system note about epic close' do
expect { subject.execute(epic) }.to change { epic.notes.count }.by(1)
note = epic.notes.last
expect(note.note).to eq('closed')
expect(note.system_note_metadata.action).to eq('closed')
end
expect(event.state).to eq('closed')
end
it 'notifies the subscribers' do
......
......@@ -42,33 +42,12 @@ RSpec.describe Epics::ReopenService do
expect { subject.execute(epic) }.to change { epic.closed_at }.to(nil)
end
context 'when state event tracking is enabled' do
before do
stub_feature_flags(track_resource_state_change_events: true)
end
it 'creates a resource state event' do
expect { subject.execute(epic) }.to change { epic.resource_state_events.count }.by(1)
it 'creates a resource state event' do
expect { subject.execute(epic) }.to change { epic.resource_state_events.count }.by(1)
event = epic.resource_state_events.last
event = epic.resource_state_events.last
expect(event.state).to eq('opened')
end
end
context 'when state event tracking is disabled' do
before do
stub_feature_flags(track_resource_state_change_events: false)
end
it 'creates a system note about epic reopen' do
expect { subject.execute(epic) }.to change { epic.notes.count }.by(1)
note = epic.notes.last
expect(note.note).to eq('opened')
expect(note.system_note_metadata.action).to eq('opened')
end
expect(event.state).to eq('opened')
end
it 'notifies the subscribers' do
......
......@@ -65,24 +65,15 @@ RSpec.describe Gitlab::Email::Handler::CreateNoteHandler do
end
end
[true, false].each do |state_tracking_enabled|
context "and current user can update noteable #{state_tracking_enabled ? 'enabled' : 'disabled'}" do
before do
stub_feature_flags(track_resource_state_change_events: state_tracking_enabled)
project.add_developer(user)
end
context "and current user can update noteable" do
before do
project.add_developer(user)
end
it 'does not raise an error' do
if state_tracking_enabled
expect { receiver.execute }.to change { noteable.resource_state_events.count }.by(1)
else
# One system note is created for the 'close' event
expect { receiver.execute }.to change { noteable.notes.count }.by(1)
end
it 'does not raise an error' do
expect { receiver.execute }.to change { noteable.resource_state_events.count }.by(1)
expect(noteable.reload).to be_closed
end
expect(noteable.reload).to be_closed
end
end
end
......
......@@ -2358,48 +2358,43 @@ RSpec.describe MergeRequest, factory_default: :keep do
end
end
context 'when state event tracking is disabled' do
context 'when no metrics or merge event exists' do
let(:user) { create(:user) }
let(:merge_request) { create(:merge_request, :merged) }
before do
stub_feature_flags(track_resource_state_change_events: false)
merge_request.metrics.destroy!
end
context 'when merging note is persisted, but no metrics or merge event exists' do
let(:user) { create(:user) }
let(:merge_request) { create(:merge_request, :merged) }
context 'when resource event for the merge exists' do
before do
merge_request.metrics.destroy!
SystemNoteService.change_status(merge_request,
merge_request.target_project,
user,
merge_request.state, nil)
end
it 'returns merging note creation date' do
it 'returns the resource event creation date' do
expect(merge_request.reload.metrics).to be_nil
expect(merge_request.merge_event).to be_nil
expect(merge_request.notes.count).to eq(1)
expect(merge_request.merged_at).to eq(merge_request.notes.first.created_at)
expect(merge_request.resource_state_events.count).to eq(1)
expect(merge_request.merged_at).to eq(merge_request.resource_state_events.first.created_at)
end
end
end
context 'when state event tracking is enabled' do
let(:user) { create(:user) }
let(:merge_request) { create(:merge_request, :merged) }
before do
merge_request.metrics.destroy!
SystemNoteService.change_status(merge_request,
merge_request.target_project,
user,
merge_request.state, nil)
end
context 'when system note for the merge exists' do
before do
# We do not create these system notes anymore but we need this to work for existing MRs
# that used system notes instead of resource state events
create(:note, :system, noteable: merge_request, note: 'merged')
end
it 'does not create a system note' do
expect(merge_request.notes).to be_empty
it 'returns the merging note creation date' do
expect(merge_request.reload.metrics).to be_nil
expect(merge_request.merge_event).to be_nil
expect(merge_request.notes.count).to eq(1)
expect(merge_request.merged_at).to eq(merge_request.notes.first.created_at)
end
end
end
end
......
......@@ -148,28 +148,20 @@ RSpec.describe AlertManagement::ProcessPrometheusAlertService do
expect { execute }.to change { alert.reload.resolved? }.to(true)
end
[true, false].each do |state_tracking_enabled|
context 'existing issue' do
before do
stub_feature_flags(track_resource_state_change_events: state_tracking_enabled)
end
let!(:alert) { create(:alert_management_alert, :with_issue, project: project, fingerprint: fingerprint) }
it 'closes the issue' do
issue = alert.issue
expect { execute }
.to change { issue.reload.state }
.from('opened')
.to('closed')
end
if state_tracking_enabled
specify { expect { execute }.to change(ResourceStateEvent, :count).by(1) }
else
specify { expect { execute }.to change(Note, :count).by(1) }
end
context 'existing issue' do
let!(:alert) { create(:alert_management_alert, :with_issue, project: project, fingerprint: fingerprint) }
it 'closes the issue' do
issue = alert.issue
expect { execute }
.to change { issue.reload.state }
.from('opened')
.to('closed')
end
it 'creates a resource state event' do
expect { execute }.to change(ResourceStateEvent, :count).by(1)
end
end
end
......
......@@ -233,26 +233,11 @@ RSpec.describe Issues::CloseService do
expect(email.subject).to include(issue.title)
end
context 'when resource state events are disabled' do
before do
stub_feature_flags(track_resource_state_change_events: false)
end
it 'creates system note about the issue being closed' do
close_issue
note = issue.notes.last
expect(note.note).to include "closed"
end
end
context 'when resource state events are enabled' do
it 'creates resource state event about the issue being closed' do
close_issue
it 'creates resource state event about the issue being closed' do
close_issue
event = issue.resource_state_events.last
expect(event.state).to eq('closed')
end
event = issue.resource_state_events.last
expect(event.state).to eq('closed')
end
it 'marks todos as done' do
......
......@@ -19,54 +19,45 @@ RSpec.describe MergeRequests::CloseService do
describe '#execute' do
it_behaves_like 'cache counters invalidator'
[true, false].each do |state_tracking_enabled|
context "valid params with state_tracking #{state_tracking_enabled ? 'enabled' : 'disabled'}" do
let(:service) { described_class.new(project, user, {}) }
context 'valid params' do
let(:service) { described_class.new(project, user, {}) }
before do
stub_feature_flags(track_resource_state_change_events: state_tracking_enabled)
allow(service).to receive(:execute_hooks)
before do
allow(service).to receive(:execute_hooks)
perform_enqueued_jobs do
@merge_request = service.execute(merge_request)
end
perform_enqueued_jobs do
@merge_request = service.execute(merge_request)
end
end
it { expect(@merge_request).to be_valid }
it { expect(@merge_request).to be_closed }
it { expect(@merge_request).to be_valid }
it { expect(@merge_request).to be_closed }
it 'executes hooks with close action' do
expect(service).to have_received(:execute_hooks)
.with(@merge_request, 'close')
end
it 'executes hooks with close action' do
expect(service).to have_received(:execute_hooks)
.with(@merge_request, 'close')
end
it 'sends email to user2 about assign of new merge_request', :sidekiq_might_not_need_inline do
email = ActionMailer::Base.deliveries.last
expect(email.to.first).to eq(user2.email)
expect(email.subject).to include(merge_request.title)
end
it 'sends email to user2 about assign of new merge_request', :sidekiq_might_not_need_inline do
email = ActionMailer::Base.deliveries.last
expect(email.to.first).to eq(user2.email)
expect(email.subject).to include(merge_request.title)
end
it 'creates system note about merge_request reassign' do
if state_tracking_enabled
event = @merge_request.resource_state_events.last
expect(event.state).to eq('closed')
else
note = @merge_request.notes.last
expect(note.note).to include 'closed'
end
end
it 'creates a resource event' do
event = @merge_request.resource_state_events.last
expect(event.state).to eq('closed')
end
it 'marks todos as done' do
expect(todo.reload).to be_done
end
it 'marks todos as done' do
expect(todo.reload).to be_done
end
context 'when auto merge is enabled' do
let(:merge_request) { create(:merge_request, :merge_when_pipeline_succeeds) }
context 'when auto merge is enabled' do
let(:merge_request) { create(:merge_request, :merge_when_pipeline_succeeds) }
it 'cancels the auto merge' do
expect(@merge_request).not_to be_auto_merge_enabled
end
it 'cancels the auto merge' do
expect(@merge_request).not_to be_auto_merge_enabled
end
end
end
......
......@@ -22,74 +22,65 @@ RSpec.describe MergeRequests::FfMergeService do
end
describe '#execute' do
[true, false].each do |state_tracking_enabled|
context "valid params with state_tracking #{state_tracking_enabled ? 'enabled' : 'disabled'}" do
let(:service) { described_class.new(project, user, valid_merge_params) }
def execute_ff_merge
perform_enqueued_jobs do
service.execute(merge_request)
end
end
before do
stub_feature_flags(track_resource_state_change_events: state_tracking_enabled)
context 'valid params' do
let(:service) { described_class.new(project, user, valid_merge_params) }
allow(service).to receive(:execute_hooks)
def execute_ff_merge
perform_enqueued_jobs do
service.execute(merge_request)
end
end
it "does not create merge commit" do
execute_ff_merge
before do
allow(service).to receive(:execute_hooks)
end
source_branch_sha = merge_request.source_project.repository.commit(merge_request.source_branch).sha
target_branch_sha = merge_request.target_project.repository.commit(merge_request.target_branch).sha
it "does not create merge commit" do
execute_ff_merge
expect(source_branch_sha).to eq(target_branch_sha)
end
source_branch_sha = merge_request.source_project.repository.commit(merge_request.source_branch).sha
target_branch_sha = merge_request.target_project.repository.commit(merge_request.target_branch).sha
it 'keeps the merge request valid' do
expect { execute_ff_merge }
.not_to change { merge_request.valid? }
end
expect(source_branch_sha).to eq(target_branch_sha)
end
it 'updates the merge request to merged' do
expect { execute_ff_merge }
.to change { merge_request.merged? }
.from(false)
.to(true)
end
it 'keeps the merge request valid' do
expect { execute_ff_merge }
.not_to change { merge_request.valid? }
end
it 'sends email to user2 about merge of new merge_request' do
execute_ff_merge
it 'updates the merge request to merged' do
expect { execute_ff_merge }
.to change { merge_request.merged? }
.from(false)
.to(true)
end
email = ActionMailer::Base.deliveries.last
expect(email.to.first).to eq(user2.email)
expect(email.subject).to include(merge_request.title)
end
it 'sends email to user2 about merge of new merge_request' do
execute_ff_merge
it 'creates system note about merge_request merge' do
execute_ff_merge
email = ActionMailer::Base.deliveries.last
expect(email.to.first).to eq(user2.email)
expect(email.subject).to include(merge_request.title)
end
if state_tracking_enabled
event = merge_request.resource_state_events.last
expect(event.state).to eq('merged')
else
note = merge_request.notes.last
expect(note.note).to include 'merged'
end
end
it 'creates resource event about merge_request merge' do
execute_ff_merge
it 'does not update squash_commit_sha if it is not a squash' do
expect { execute_ff_merge }.not_to change { merge_request.squash_commit_sha }
end
event = merge_request.resource_state_events.last
expect(event.state).to eq('merged')
end
it 'updates squash_commit_sha if it is a squash' do
merge_request.update!(squash: true)
it 'does not update squash_commit_sha if it is not a squash' do
expect { execute_ff_merge }.not_to change { merge_request.squash_commit_sha }
end
expect { execute_ff_merge }
.to change { merge_request.squash_commit_sha }
.from(nil)
end
it 'updates squash_commit_sha if it is a squash' do
merge_request.update!(squash: true)
expect { execute_ff_merge }
.to change { merge_request.squash_commit_sha }
.from(nil)
end
end
......
......@@ -20,11 +20,7 @@ RSpec.describe MergeRequests::MergeService do
end
context 'valid params' do
let(:state_tracking) { true }
before do
stub_feature_flags(track_resource_state_change_events: state_tracking)
allow(service).to receive(:execute_hooks)
perform_enqueued_jobs do
......@@ -47,20 +43,9 @@ RSpec.describe MergeRequests::MergeService do
end
context 'note creation' do
context 'when resource state event tracking is disabled' do
let(:state_tracking) { false }
it 'creates system note about merge_request merge' do
note = merge_request.notes.last
expect(note.note).to include 'merged'
end
end
context 'when resource state event tracking is enabled' do
it 'creates resource state event about merge_request merge' do
event = merge_request.resource_state_events.last
expect(event.state).to eq('merged')
end
it 'creates resource state event about merge_request merge' do
event = merge_request.resource_state_events.last
expect(event.state).to eq('merged')
end
end
......
......@@ -367,76 +367,58 @@ RSpec.describe MergeRequests::RefreshService do
end
end
[true, false].each do |state_tracking_enabled|
context "push to origin repo target branch with state tracking #{state_tracking_enabled ? 'enabled' : 'disabled'}", :sidekiq_might_not_need_inline do
context 'push to origin repo target branch', :sidekiq_might_not_need_inline do
context 'when all MRs to the target branch had diffs' do
before do
stub_feature_flags(track_resource_state_change_events: state_tracking_enabled)
service.new(@project, @user).execute(@oldrev, @newrev, 'refs/heads/feature')
reload_mrs
end
context 'when all MRs to the target branch had diffs' do
before do
service.new(@project, @user).execute(@oldrev, @newrev, 'refs/heads/feature')
reload_mrs
end
it 'updates the merge state' do
expect(@merge_request).to be_merged
expect(@fork_merge_request).to be_merged
expect(@build_failed_todo).to be_done
expect(@fork_build_failed_todo).to be_done
it 'updates the merge state' do
expect(@merge_request).to be_merged
expect(@fork_merge_request).to be_merged
expect(@build_failed_todo).to be_done
expect(@fork_build_failed_todo).to be_done
if state_tracking_enabled
expect(@merge_request.resource_state_events.last.state).to eq('merged')
expect(@fork_merge_request.resource_state_events.last.state).to eq('merged')
else
expect(@merge_request.notes.last.note).to include('merged')
expect(@fork_merge_request.notes.last.note).to include('merged')
end
end
expect(@merge_request.resource_state_events.last.state).to eq('merged')
expect(@fork_merge_request.resource_state_events.last.state).to eq('merged')
end
end
context 'when an MR to be closed was empty already' do
let!(:empty_fork_merge_request) do
create(:merge_request,
source_project: @fork_project,
source_branch: 'master',
target_branch: 'master',
target_project: @project)
end
context 'when an MR to be closed was empty already' do
let!(:empty_fork_merge_request) do
create(:merge_request,
source_project: @fork_project,
source_branch: 'master',
target_branch: 'master',
target_project: @project)
end
before do
# This spec already has a fake push, so pretend that we were targeting
# feature all along.
empty_fork_merge_request.update_columns(target_branch: 'feature')
before do
# This spec already has a fake push, so pretend that we were targeting
# feature all along.
empty_fork_merge_request.update_columns(target_branch: 'feature')
service.new(@project, @user).execute(@oldrev, @newrev, 'refs/heads/feature')
reload_mrs
empty_fork_merge_request.reload
end
service.new(@project, @user).execute(@oldrev, @newrev, 'refs/heads/feature')
reload_mrs
empty_fork_merge_request.reload
end
it 'only updates the non-empty MRs' do
expect(@merge_request).to be_merged
expect(@fork_merge_request).to be_merged
expect(empty_fork_merge_request).to be_open
expect(empty_fork_merge_request.merge_request_diff.state).to eq('empty')
expect(empty_fork_merge_request.notes).to be_empty
if state_tracking_enabled
expect(@merge_request.resource_state_events.last.state).to eq('merged')
expect(@fork_merge_request.resource_state_events.last.state).to eq('merged')
else
expect(@merge_request.notes.last.note).to include('merged')
expect(@fork_merge_request.notes.last.note).to include('merged')
end
end
it 'only updates the non-empty MRs' do
expect(@merge_request).to be_merged
expect(@fork_merge_request).to be_merged
expect(empty_fork_merge_request).to be_open
expect(empty_fork_merge_request.merge_request_diff.state).to eq('empty')
expect(empty_fork_merge_request.notes).to be_empty
expect(@merge_request.resource_state_events.last.state).to eq('merged')
expect(@fork_merge_request.resource_state_events.last.state).to eq('merged')
end
end
context "manual merge of source branch #{state_tracking_enabled ? 'enabled' : 'disabled'}", :sidekiq_might_not_need_inline do
context 'manual merge of source branch', :sidekiq_might_not_need_inline do
before do
stub_feature_flags(track_resource_state_change_events: state_tracking_enabled)
# Merge master -> feature branch
@project.repository.merge(@user, @merge_request.diff_head_sha, @merge_request, 'Test message')
commit = @project.repository.commit('feature')
......@@ -445,13 +427,8 @@ RSpec.describe MergeRequests::RefreshService do
end
it 'updates the merge state' do
if state_tracking_enabled
expect(@merge_request.resource_state_events.last.state).to eq('merged')
expect(@fork_merge_request.resource_state_events.last.state).to eq('merged')
else
expect(@merge_request.notes.last.note).to include('merged')
expect(@fork_merge_request.notes.last.note).to include('merged')
end
expect(@merge_request.resource_state_events.last.state).to eq('merged')
expect(@fork_merge_request.resource_state_events.last.state).to eq('merged')
expect(@merge_request).to be_merged
expect(@merge_request.diffs.size).to be > 0
......@@ -616,29 +593,21 @@ RSpec.describe MergeRequests::RefreshService do
end
end
[true, false].each do |state_tracking_enabled|
context "push to origin repo target branch after fork project was removed #{state_tracking_enabled ? 'enabled' : 'disabled'}" do
before do
stub_feature_flags(track_resource_state_change_events: state_tracking_enabled)
context 'push to origin repo target branch after fork project was removed' do
before do
@fork_project.destroy!
service.new(@project, @user).execute(@oldrev, @newrev, 'refs/heads/feature')
reload_mrs
end
@fork_project.destroy!
service.new(@project, @user).execute(@oldrev, @newrev, 'refs/heads/feature')
reload_mrs
end
it 'updates the merge request state' do
expect(@merge_request.resource_state_events.last.state).to eq('merged')
it 'updates the merge request state' do
if state_tracking_enabled
expect(@merge_request.resource_state_events.last.state).to eq('merged')
else
expect(@merge_request.notes.last.note).to include('merged')
end
expect(@merge_request).to be_merged
expect(@fork_merge_request).to be_open
expect(@fork_merge_request.notes).to be_empty
expect(@build_failed_todo).to be_done
expect(@fork_build_failed_todo).to be_done
end
expect(@merge_request).to be_merged
expect(@fork_merge_request).to be_open
expect(@fork_merge_request.notes).to be_empty
expect(@build_failed_todo).to be_done
expect(@fork_build_failed_todo).to be_done
end
end
......
......@@ -20,11 +20,8 @@ RSpec.describe MergeRequests::ReopenService do
context 'valid params' do
let(:service) { described_class.new(project, user, {}) }
let(:state_tracking) { true }
before do
stub_feature_flags(track_resource_state_change_events: state_tracking)
allow(service).to receive(:execute_hooks)
perform_enqueued_jobs do
......@@ -47,20 +44,9 @@ RSpec.describe MergeRequests::ReopenService do
end
context 'note creation' do
context 'when state event tracking is disabled' do
let(:state_tracking) { false }
it 'creates system note about merge_request reopen' do
note = merge_request.notes.last
expect(note.note).to include 'reopened'
end
end
context 'when state event tracking is enabled' do
it 'creates resource state event about merge_request reopen' do
event = merge_request.resource_state_events.last
expect(event.state).to eq('reopened')
end
it 'creates resource state event about merge_request reopen' do
event = merge_request.resource_state_events.last
expect(event.state).to eq('reopened')
end
end
end
......
......@@ -127,23 +127,8 @@ RSpec.describe Projects::Alerting::NotifyService do
let(:alert) { create(:alert_management_alert, :with_issue, project: project, fingerprint: fingerprint_sha) }
let(:issue) { alert.issue }
context 'state_tracking is enabled' do
before do
stub_feature_flags(track_resource_state_change_events: true)
end
it { expect { subject }.to change { issue.reload.state }.from('opened').to('closed') }
it { expect { subject }.to change(ResourceStateEvent, :count).by(1) }
end
context 'state_tracking is disabled' do
before do
stub_feature_flags(track_resource_state_change_events: false)
end
it { expect { subject }.to change { issue.reload.state }.from('opened').to('closed') }
it { expect { subject }.to change(Note, :count).by(1) }
end
it { expect { subject }.to change { issue.reload.state }.from('opened').to('closed') }
it { expect { subject }.to change(ResourceStateEvent, :count).by(1) }
end
end
end
......
......@@ -131,43 +131,11 @@ RSpec.describe ::SystemNotes::IssuablesService do
describe '#change_status' do
subject { service.change_status(status, source) }
context 'when resource state event tracking is enabled' do
let(:status) { 'reopened' }
let(:source) { nil }
let(:status) { 'reopened' }
let(:source) { nil }
it 'does not change note count' do
expect { subject }.not_to change { Note.count }
end
end
context 'with status reopened' do
before do
stub_feature_flags(track_resource_state_change_events: false)
end
let(:status) { 'reopened' }
let(:source) { nil }
it_behaves_like 'a note with overridable created_at'
it_behaves_like 'a system note' do
let(:action) { 'opened' }
end
end
context 'with a source' do
before do
stub_feature_flags(track_resource_state_change_events: false)
end
let(:status) { 'opened' }
let(:source) { double('commit', gfm_reference: 'commit 123456') }
it_behaves_like 'a note with overridable created_at'
it 'sets the note text' do
expect(subject.note).to eq "#{status} via commit 123456"
end
it 'creates a resource state event' do
expect { subject }.to change { ResourceStateEvent.count }.by(1)
end
end
......@@ -636,67 +604,26 @@ RSpec.describe ::SystemNotes::IssuablesService do
describe '#close_after_error_tracking_resolve' do
subject { service.close_after_error_tracking_resolve }
context 'when state tracking is enabled' do
before do
stub_feature_flags(track_resource_state_change_events: true)
end
it 'creates the expected state event' do
subject
it 'creates the expected state event' do
subject
event = ResourceStateEvent.last
event = ResourceStateEvent.last
expect(event.close_after_error_tracking_resolve).to eq(true)
expect(event.state).to eq('closed')
end
end
context 'when state tracking is disabled' do
before do
stub_feature_flags(track_resource_state_change_events: false)
end
it_behaves_like 'a system note' do
let(:action) { 'closed' }
end
it 'creates the expected system note' do
expect(subject.note)
.to eq('resolved the corresponding error and closed the issue.')
end
expect(event.close_after_error_tracking_resolve).to eq(true)
expect(event.state).to eq('closed')
end
end
describe '#auto_resolve_prometheus_alert' do
subject { service.auto_resolve_prometheus_alert }
context 'when state tracking is enabled' do
before do
stub_feature_flags(track_resource_state_change_events: true)
end
it 'creates the expected state event' do
subject
event = ResourceStateEvent.last
expect(event.close_auto_resolve_prometheus_alert).to eq(true)
expect(event.state).to eq('closed')
end
end
context 'when state tracking is disabled' do
before do
stub_feature_flags(track_resource_state_change_events: false)
end
it 'creates the expected state event' do
subject
it_behaves_like 'a system note' do
let(:action) { 'closed' }
end
event = ResourceStateEvent.last
it 'creates the expected system note' do
expect(subject.note).to eq('automatically closed this issue because the alert resolved.')
end
expect(event.close_auto_resolve_prometheus_alert).to eq(true)
expect(event.state).to eq('closed')
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