2020-05-11 11:09:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ResourceStateEvent < ResourceEvent
|
|
|
|
include IssueResourceEvent
|
|
|
|
include MergeRequestResourceEvent
|
2022-08-25 11:12:14 -04:00
|
|
|
include Importable
|
2020-05-11 11:09:37 -04:00
|
|
|
|
2022-08-25 11:12:14 -04:00
|
|
|
validate :exactly_one_issuable, unless: :importing?
|
2020-05-11 11:09:37 -04:00
|
|
|
|
2020-07-15 08:09:26 -04:00
|
|
|
belongs_to :source_merge_request, class_name: 'MergeRequest', foreign_key: :source_merge_request_id
|
|
|
|
|
2020-05-11 11:09:37 -04:00
|
|
|
# state is used for issue and merge request states.
|
|
|
|
enum state: Issue.available_states.merge(MergeRequest.available_states).merge(reopened: 5)
|
|
|
|
|
2020-12-10 07:09:43 -05:00
|
|
|
after_create :issue_usage_metrics
|
2020-09-28 08:10:02 -04:00
|
|
|
|
2020-05-11 11:09:37 -04:00
|
|
|
def self.issuable_attrs
|
|
|
|
%i(issue merge_request).freeze
|
|
|
|
end
|
2020-07-16 17:10:05 -04:00
|
|
|
|
|
|
|
def issuable
|
|
|
|
issue || merge_request
|
|
|
|
end
|
2020-09-28 08:10:02 -04:00
|
|
|
|
|
|
|
def for_issue?
|
|
|
|
issue_id.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-12-10 07:09:43 -05:00
|
|
|
def issue_usage_metrics
|
2020-09-28 08:10:02 -04:00
|
|
|
return unless for_issue?
|
|
|
|
|
|
|
|
case state
|
|
|
|
when 'closed'
|
2022-08-19 08:11:34 -04:00
|
|
|
issue_usage_counter.track_issue_closed_action(author: user, project: issue.project)
|
2020-09-28 08:10:02 -04:00
|
|
|
when 'reopened'
|
2022-08-19 08:11:34 -04:00
|
|
|
issue_usage_counter.track_issue_reopened_action(author: user, project: issue.project)
|
2020-09-28 08:10:02 -04:00
|
|
|
else
|
|
|
|
# no-op, nothing to do, not a state we're tracking
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def issue_usage_counter
|
|
|
|
Gitlab::UsageDataCounters::IssueActivityUniqueCounter
|
|
|
|
end
|
2020-05-11 11:09:37 -04:00
|
|
|
end
|
2020-09-17 08:09:37 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
ResourceStateEvent.prepend_mod_with('ResourceStateEvent')
|