Commit 05662f26 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'ld-move-ee-system-notes-classes-out-of-ee-namespace' into 'master'

Move some EE `SystemNotes` classes out of the `EE` namespace [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!62854
parents 6ab6c465 61d1061e
...@@ -119,15 +119,15 @@ module EE ...@@ -119,15 +119,15 @@ module EE
end end
def epics_service(noteable, author) def epics_service(noteable, author)
EE::SystemNotes::EpicsService.new(noteable: noteable, author: author) ::SystemNotes::EpicsService.new(noteable: noteable, author: author)
end end
def merge_trains_service(noteable, project, author) def merge_trains_service(noteable, project, author)
EE::SystemNotes::MergeTrainService.new(noteable: noteable, project: project, author: author) ::SystemNotes::MergeTrainService.new(noteable: noteable, project: project, author: author)
end end
def vulnerabilities_service(noteable, project, author) def vulnerabilities_service(noteable, project, author)
EE::SystemNotes::VulnerabilitiesService.new(noteable: noteable, project: project, author: author) ::SystemNotes::VulnerabilitiesService.new(noteable: noteable, project: project, author: author)
end end
end end
end end
# frozen_string_literal: true
module EE
module SystemNotes
class EpicsService < ::SystemNotes::BaseService
def epic_issue(issue, type)
return unless validate_epic_issue_action_type(type)
action = type == :added ? 'epic_issue_added' : 'epic_issue_removed'
body = "#{type} issue #{issue.to_reference(noteable.group)}"
create_note(NoteSummary.new(noteable, nil, author, body, action: action))
end
def epic_issue_moved(issue, to_epic)
epic_issue_moved_act(noteable, issue, to_epic, author, verb: 'added', direction: 'from')
epic_issue_moved_act(to_epic, issue, noteable, author, verb: 'moved', direction: 'to')
end
def issue_promoted(noteable_ref, direction:)
unless [:to, :from].include?(direction)
raise ArgumentError, "Invalid direction `#{direction}`"
end
project = noteable.project
cross_reference = noteable_ref.to_reference(project || noteable.group)
body = "promoted #{direction} #{noteable_ref.class.to_s.downcase} #{cross_reference}"
create_note(NoteSummary.new(noteable, project, author, body, action: 'moved'))
end
def issue_on_epic(issue, type)
return unless validate_epic_issue_action_type(type)
if type == :added
direction = 'to'
action = 'issue_added_to_epic'
else
direction = 'from'
action = 'issue_removed_from_epic'
end
body = "#{type} #{direction} epic #{noteable.to_reference(issue.project)}"
create_note(NoteSummary.new(issue, issue.project, author, body, action: action))
end
def issue_epic_change(issue)
body = "changed epic to #{noteable.to_reference(issue.project)}"
action = 'issue_changed_epic'
create_note(NoteSummary.new(issue, issue.project, author, body, action: action))
end
# Called when the start or end date of an Issuable is changed
#
# date_type - 'start date' or 'finish date'
# date - New date
#
# Example Note text:
#
# "changed start date to FIXME"
#
# Returns the created Note object
def change_epic_date_note(date_type, date)
body = if date
"changed #{date_type} to #{date.strftime('%b %-d, %Y')}"
else
"removed the #{date_type}"
end
create_note(NoteSummary.new(noteable, nil, author, body, action: 'epic_date_changed'))
end
def change_epics_relation(child_epic, type)
note_body = if type == 'relate_epic'
"added epic %{target_epic_ref} as %{direction} epic"
else
"removed %{direction} epic %{target_epic_ref}"
end
note_body_params = { direction: 'child', target_epic_ref: child_epic.to_reference(noteable.group) }
create_note(NoteSummary.new(noteable, nil, author, note_body % note_body_params, action: type))
note_body_params = { direction: 'parent', target_epic_ref: noteable.to_reference(child_epic.group) }
create_note(NoteSummary.new(child_epic, nil, author, note_body % note_body_params, action: type))
end
private
def epic_issue_moved_act(subject_epic, issue, object_epic, user, verb:, direction:)
action = 'epic_issue_moved'
body = "#{verb} issue #{issue.to_reference(subject_epic.group)} #{direction}" \
" epic #{subject_epic.to_reference(object_epic.group)}"
create_note(NoteSummary.new(object_epic, nil, user, body, action: action))
end
def validate_epic_issue_action_type(type)
[:added, :removed].include?(type)
end
end
end
end
# frozen_string_literal: true
module EE
module SystemNotes
class MergeTrainService < ::SystemNotes::BaseService
# Called when 'merge train' is executed
def enqueue(merge_train)
index = merge_train.index
body = if index == 0
'started a merge train'
else
"added this merge request to the merge train at position #{index + 1}"
end
create_note(NoteSummary.new(noteable, project, author, body, action: 'merge'))
end
# Called when 'merge train' is canceled
def cancel
body = 'removed this merge request from the merge train'
create_note(NoteSummary.new(noteable, project, author, body, action: 'merge'))
end
# Called when 'merge train' is aborted
def abort(reason)
::TodoService.new.merge_train_removed(noteable)
##
# TODO: Abort message should be sent by the system, not a particular user.
# See https://gitlab.com/gitlab-org/gitlab/issues/29467.
body = "removed this merge request from the merge train because #{reason}"
create_note(NoteSummary.new(noteable, project, author, body, action: 'merge'))
end
# Called when 'add to merge train when pipeline succeeds' is executed
def add_when_pipeline_succeeds(sha)
body = "enabled automatic add to merge train when the pipeline for #{sha} succeeds"
create_note(NoteSummary.new(noteable, project, author, body, action: 'merge'))
end
# Called when 'add to merge train when pipeline succeeds' is canceled
def cancel_add_when_pipeline_succeeds
body = 'cancelled automatic add to merge train'
create_note(NoteSummary.new(noteable, project, author, body, action: 'merge'))
end
# Called when 'add to merge train when pipeline succeeds' is aborted
def abort_add_when_pipeline_succeeds(reason)
::TodoService.new.merge_train_removed(noteable)
##
# TODO: Abort message should be sent by the system, not a particular user.
# See https://gitlab.com/gitlab-org/gitlab/issues/29467.
body = "aborted automatic add to merge train because #{reason}"
create_note(NoteSummary.new(noteable, project, author, body, action: 'merge'))
end
end
end
end
# frozen_string_literal: true
module EE
module SystemNotes
class VulnerabilitiesService < ::SystemNotes::BaseService
# Called when state is changed for 'vulnerability'
def change_vulnerability_state
type = noteable.detected? ? 'reverted' : 'changed'
body = "#{type} vulnerability status to #{noteable.state}"
create_note(NoteSummary.new(noteable, project, author, body, action: "vulnerability_#{noteable.state}"))
end
end
end
end
# frozen_string_literal: true
module SystemNotes
class EpicsService < ::SystemNotes::BaseService
def epic_issue(issue, type)
return unless validate_epic_issue_action_type(type)
action = type == :added ? 'epic_issue_added' : 'epic_issue_removed'
body = "#{type} issue #{issue.to_reference(noteable.group)}"
create_note(NoteSummary.new(noteable, nil, author, body, action: action))
end
def epic_issue_moved(issue, to_epic)
epic_issue_moved_act(noteable, issue, to_epic, author, verb: 'added', direction: 'from')
epic_issue_moved_act(to_epic, issue, noteable, author, verb: 'moved', direction: 'to')
end
def issue_promoted(noteable_ref, direction:)
unless [:to, :from].include?(direction)
raise ArgumentError, "Invalid direction `#{direction}`"
end
project = noteable.project
cross_reference = noteable_ref.to_reference(project || noteable.group)
body = "promoted #{direction} #{noteable_ref.class.to_s.downcase} #{cross_reference}"
create_note(NoteSummary.new(noteable, project, author, body, action: 'moved'))
end
def issue_on_epic(issue, type)
return unless validate_epic_issue_action_type(type)
if type == :added
direction = 'to'
action = 'issue_added_to_epic'
else
direction = 'from'
action = 'issue_removed_from_epic'
end
body = "#{type} #{direction} epic #{noteable.to_reference(issue.project)}"
create_note(NoteSummary.new(issue, issue.project, author, body, action: action))
end
def issue_epic_change(issue)
body = "changed epic to #{noteable.to_reference(issue.project)}"
action = 'issue_changed_epic'
create_note(NoteSummary.new(issue, issue.project, author, body, action: action))
end
# Called when the start or end date of an Issuable is changed
#
# date_type - 'start date' or 'finish date'
# date - New date
#
# Example Note text:
#
# "changed start date to FIXME"
#
# Returns the created Note object
def change_epic_date_note(date_type, date)
body = if date
"changed #{date_type} to #{date.strftime('%b %-d, %Y')}"
else
"removed the #{date_type}"
end
create_note(NoteSummary.new(noteable, nil, author, body, action: 'epic_date_changed'))
end
def change_epics_relation(child_epic, type)
note_body = if type == 'relate_epic'
"added epic %{target_epic_ref} as %{direction} epic"
else
"removed %{direction} epic %{target_epic_ref}"
end
note_body_params = { direction: 'child', target_epic_ref: child_epic.to_reference(noteable.group) }
create_note(NoteSummary.new(noteable, nil, author, note_body % note_body_params, action: type))
note_body_params = { direction: 'parent', target_epic_ref: noteable.to_reference(child_epic.group) }
create_note(NoteSummary.new(child_epic, nil, author, note_body % note_body_params, action: type))
end
private
def epic_issue_moved_act(subject_epic, issue, object_epic, user, verb:, direction:)
action = 'epic_issue_moved'
body = "#{verb} issue #{issue.to_reference(subject_epic.group)} #{direction}" \
" epic #{subject_epic.to_reference(object_epic.group)}"
create_note(NoteSummary.new(object_epic, nil, user, body, action: action))
end
def validate_epic_issue_action_type(type)
[:added, :removed].include?(type)
end
end
end
# frozen_string_literal: true
module SystemNotes
class MergeTrainService < ::SystemNotes::BaseService
# Called when 'merge train' is executed
def enqueue(merge_train)
index = merge_train.index
body = if index == 0
'started a merge train'
else
"added this merge request to the merge train at position #{index + 1}"
end
create_note(NoteSummary.new(noteable, project, author, body, action: 'merge'))
end
# Called when 'merge train' is canceled
def cancel
body = 'removed this merge request from the merge train'
create_note(NoteSummary.new(noteable, project, author, body, action: 'merge'))
end
# Called when 'merge train' is aborted
def abort(reason)
::TodoService.new.merge_train_removed(noteable)
##
# TODO: Abort message should be sent by the system, not a particular user.
# See https://gitlab.com/gitlab-org/gitlab/issues/29467.
body = "removed this merge request from the merge train because #{reason}"
create_note(NoteSummary.new(noteable, project, author, body, action: 'merge'))
end
# Called when 'add to merge train when pipeline succeeds' is executed
def add_when_pipeline_succeeds(sha)
body = "enabled automatic add to merge train when the pipeline for #{sha} succeeds"
create_note(NoteSummary.new(noteable, project, author, body, action: 'merge'))
end
# Called when 'add to merge train when pipeline succeeds' is canceled
def cancel_add_when_pipeline_succeeds
body = 'cancelled automatic add to merge train'
create_note(NoteSummary.new(noteable, project, author, body, action: 'merge'))
end
# Called when 'add to merge train when pipeline succeeds' is aborted
def abort_add_when_pipeline_succeeds(reason)
::TodoService.new.merge_train_removed(noteable)
##
# TODO: Abort message should be sent by the system, not a particular user.
# See https://gitlab.com/gitlab-org/gitlab/issues/29467.
body = "aborted automatic add to merge train because #{reason}"
create_note(NoteSummary.new(noteable, project, author, body, action: 'merge'))
end
end
end
# frozen_string_literal: true
module SystemNotes
class VulnerabilitiesService < ::SystemNotes::BaseService
# Called when state is changed for 'vulnerability'
def change_vulnerability_state
type = noteable.detected? ? 'reverted' : 'changed'
body = "#{type} vulnerability status to #{noteable.state}"
create_note(NoteSummary.new(noteable, project, author, body, action: "vulnerability_#{noteable.state}"))
end
end
end
...@@ -29,7 +29,7 @@ RSpec.describe SystemNoteService do ...@@ -29,7 +29,7 @@ RSpec.describe SystemNoteService do
let(:date) { double } let(:date) { double }
it 'calls EpicsService' do it 'calls EpicsService' do
expect_next_instance_of(EE::SystemNotes::EpicsService) do |service| expect_next_instance_of(SystemNotes::EpicsService) do |service|
expect(service).to receive(:change_epic_date_note).with(date_type, date) expect(service).to receive(:change_epic_date_note).with(date_type, date)
end end
...@@ -41,7 +41,7 @@ RSpec.describe SystemNoteService do ...@@ -41,7 +41,7 @@ RSpec.describe SystemNoteService do
let(:type) { double } let(:type) { double }
it 'calls EpicsService' do it 'calls EpicsService' do
expect_next_instance_of(EE::SystemNotes::EpicsService) do |service| expect_next_instance_of(SystemNotes::EpicsService) do |service|
expect(service).to receive(:epic_issue).with(noteable, type) expect(service).to receive(:epic_issue).with(noteable, type)
end end
...@@ -53,7 +53,7 @@ RSpec.describe SystemNoteService do ...@@ -53,7 +53,7 @@ RSpec.describe SystemNoteService do
let(:type) { double } let(:type) { double }
it 'calls EpicsService' do it 'calls EpicsService' do
expect_next_instance_of(EE::SystemNotes::EpicsService) do |service| expect_next_instance_of(SystemNotes::EpicsService) do |service|
expect(service).to receive(:issue_on_epic).with(noteable, type) expect(service).to receive(:issue_on_epic).with(noteable, type)
end end
...@@ -66,7 +66,7 @@ RSpec.describe SystemNoteService do ...@@ -66,7 +66,7 @@ RSpec.describe SystemNoteService do
let(:type) { double } let(:type) { double }
it 'calls EpicsService' do it 'calls EpicsService' do
expect_next_instance_of(EE::SystemNotes::EpicsService) do |service| expect_next_instance_of(SystemNotes::EpicsService) do |service|
expect(service).to receive(:change_epics_relation).with(child_epic, type) expect(service).to receive(:change_epics_relation).with(child_epic, type)
end end
...@@ -78,7 +78,7 @@ RSpec.describe SystemNoteService do ...@@ -78,7 +78,7 @@ RSpec.describe SystemNoteService do
let(:merge_train) { double } let(:merge_train) { double }
it 'calls MergeTrainService' do it 'calls MergeTrainService' do
expect_next_instance_of(EE::SystemNotes::MergeTrainService) do |service| expect_next_instance_of(SystemNotes::MergeTrainService) do |service|
expect(service).to receive(:enqueue).with(merge_train) expect(service).to receive(:enqueue).with(merge_train)
end end
...@@ -88,7 +88,7 @@ RSpec.describe SystemNoteService do ...@@ -88,7 +88,7 @@ RSpec.describe SystemNoteService do
describe '.cancel_merge_train' do describe '.cancel_merge_train' do
it 'calls MergeTrainService' do it 'calls MergeTrainService' do
expect_next_instance_of(EE::SystemNotes::MergeTrainService) do |service| expect_next_instance_of(SystemNotes::MergeTrainService) do |service|
expect(service).to receive(:cancel) expect(service).to receive(:cancel)
end end
...@@ -100,7 +100,7 @@ RSpec.describe SystemNoteService do ...@@ -100,7 +100,7 @@ RSpec.describe SystemNoteService do
let(:message) { double } let(:message) { double }
it 'calls MergeTrainService' do it 'calls MergeTrainService' do
expect_next_instance_of(EE::SystemNotes::MergeTrainService) do |service| expect_next_instance_of(SystemNotes::MergeTrainService) do |service|
expect(service).to receive(:abort).with(message) expect(service).to receive(:abort).with(message)
end end
...@@ -112,7 +112,7 @@ RSpec.describe SystemNoteService do ...@@ -112,7 +112,7 @@ RSpec.describe SystemNoteService do
let(:sha) { double } let(:sha) { double }
it 'calls MergeTrainService' do it 'calls MergeTrainService' do
expect_next_instance_of(EE::SystemNotes::MergeTrainService) do |service| expect_next_instance_of(SystemNotes::MergeTrainService) do |service|
expect(service).to receive(:add_when_pipeline_succeeds).with(sha) expect(service).to receive(:add_when_pipeline_succeeds).with(sha)
end end
...@@ -122,7 +122,7 @@ RSpec.describe SystemNoteService do ...@@ -122,7 +122,7 @@ RSpec.describe SystemNoteService do
describe '.cancel_add_to_merge_train_when_pipeline_succeeds' do describe '.cancel_add_to_merge_train_when_pipeline_succeeds' do
it 'calls MergeTrainService' do it 'calls MergeTrainService' do
expect_next_instance_of(EE::SystemNotes::MergeTrainService) do |service| expect_next_instance_of(SystemNotes::MergeTrainService) do |service|
expect(service).to receive(:cancel_add_when_pipeline_succeeds) expect(service).to receive(:cancel_add_when_pipeline_succeeds)
end end
...@@ -134,7 +134,7 @@ RSpec.describe SystemNoteService do ...@@ -134,7 +134,7 @@ RSpec.describe SystemNoteService do
let(:message) { double } let(:message) { double }
it 'calls MergeTrainService' do it 'calls MergeTrainService' do
expect_next_instance_of(EE::SystemNotes::MergeTrainService) do |service| expect_next_instance_of(SystemNotes::MergeTrainService) do |service|
expect(service).to receive(:abort_add_when_pipeline_succeeds).with(message) expect(service).to receive(:abort_add_when_pipeline_succeeds).with(message)
end end
...@@ -144,7 +144,7 @@ RSpec.describe SystemNoteService do ...@@ -144,7 +144,7 @@ RSpec.describe SystemNoteService do
describe '.change_vulnerability_state' do describe '.change_vulnerability_state' do
it 'calls VulnerabilitiesService' do it 'calls VulnerabilitiesService' do
expect_next_instance_of(EE::SystemNotes::VulnerabilitiesService) do |service| expect_next_instance_of(SystemNotes::VulnerabilitiesService) do |service|
expect(service).to receive(:change_vulnerability_state) expect(service).to receive(:change_vulnerability_state)
end end
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe EE::SystemNotes::EpicsService do RSpec.describe SystemNotes::EpicsService do
let_it_be(:group) { create(:group) } let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, :repository, group: group) } let_it_be(:project) { create(:project, :repository, group: group) }
let_it_be(:author) { create(:user) } let_it_be(:author) { create(:user) }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe EE::SystemNotes::MergeTrainService do RSpec.describe SystemNotes::MergeTrainService do
let_it_be(:author) { create(:user) } let_it_be(:author) { create(:user) }
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe EE::SystemNotes::VulnerabilitiesService do RSpec.describe SystemNotes::VulnerabilitiesService do
let_it_be(:project) { create(:project, :repository) } let_it_be(:project) { create(:project, :repository) }
let_it_be(:author) { create(:user) } let_it_be(:author) { create(:user) }
......
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