diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-22 15:08:15 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-22 15:08:15 +0300 |
commit | 808c799a67a1cf2489a343a6976f55c74aec398b (patch) | |
tree | 4902ff7dbcdd7f3a9dde5ab3bd20dba94835a8a7 /app/services/resource_events | |
parent | 4a3ba3e5f261eb09e6b2b4fd44373e7a1c454a72 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/resource_events')
3 files changed, 59 insertions, 2 deletions
diff --git a/app/services/resource_events/change_state_service.rb b/app/services/resource_events/change_state_service.rb new file mode 100644 index 00000000000..8beb76d8aee --- /dev/null +++ b/app/services/resource_events/change_state_service.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module ResourceEvents + class ChangeStateService + attr_reader :resource, :user + + def initialize(user:, resource:) + @user, @resource = user, resource + end + + def execute(state) + ResourceStateEvent.create( + user: user, + issue: issue, + merge_request: merge_request, + state: ResourceStateEvent.states[state], + created_at: Time.zone.now) + + resource.expire_note_etag_cache + end + + private + + def issue + return unless resource.is_a?(Issue) + + resource + end + + def merge_request + return unless resource.is_a?(MergeRequest) + + resource + end + end +end diff --git a/app/services/resource_events/merge_into_notes_service.rb b/app/services/resource_events/merge_into_notes_service.rb index 4aa9bb80229..122bcb8550f 100644 --- a/app/services/resource_events/merge_into_notes_service.rb +++ b/app/services/resource_events/merge_into_notes_service.rb @@ -11,7 +11,8 @@ module ResourceEvents SYNTHETIC_NOTE_BUILDER_SERVICES = [ SyntheticLabelNotesBuilderService, - SyntheticMilestoneNotesBuilderService + SyntheticMilestoneNotesBuilderService, + SyntheticStateNotesBuilderService ].freeze attr_reader :resource, :current_user, :params @@ -23,7 +24,7 @@ module ResourceEvents end def execute(notes = []) - (notes + synthetic_notes).sort_by { |n| n.created_at } + (notes + synthetic_notes).sort_by(&:created_at) end private diff --git a/app/services/resource_events/synthetic_state_notes_builder_service.rb b/app/services/resource_events/synthetic_state_notes_builder_service.rb new file mode 100644 index 00000000000..763134d98d8 --- /dev/null +++ b/app/services/resource_events/synthetic_state_notes_builder_service.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module ResourceEvents + class SyntheticStateNotesBuilderService < BaseSyntheticNotesBuilderService + private + + def synthetic_notes + state_change_events.map do |event| + StateNote.from_event(event, resource: resource, resource_parent: resource_parent) + end + end + + def state_change_events + return [] unless resource.respond_to?(:resource_state_events) + + events = resource.resource_state_events.includes(user: :status) # rubocop: disable CodeReuse/ActiveRecord + since_fetch_at(events) + end + end +end |