debian-mirror-gitlab/app/models/resource_state_event.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

57 lines
1.3 KiB
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# frozen_string_literal: true
class ResourceStateEvent < ResourceEvent
include MergeRequestResourceEvent
2022-10-11 01:57:18 +05:30
include Importable
2020-05-24 23:13:21 +05:30
2022-10-11 01:57:18 +05:30
validate :exactly_one_issuable, unless: :importing?
2020-05-24 23:13:21 +05:30
2020-07-28 23:09:34 +05:30
belongs_to :source_merge_request, class_name: 'MergeRequest', foreign_key: :source_merge_request_id
2020-05-24 23:13:21 +05:30
# state is used for issue and merge request states.
enum state: Issue.available_states.merge(MergeRequest.available_states).merge(reopened: 5)
2021-02-22 17:27:13 +05:30
after_create :issue_usage_metrics
2021-01-03 14:25:43 +05:30
2023-06-20 00:43:36 +05:30
scope :aliased_for_timebox_report, -> do
select("'state' AS event_type", "id", "created_at", "state AS value", "NULL AS action", "issue_id")
end
2020-05-24 23:13:21 +05:30
def self.issuable_attrs
%i(issue merge_request).freeze
end
2020-07-28 23:09:34 +05:30
def issuable
issue || merge_request
end
2021-01-03 14:25:43 +05:30
def for_issue?
issue_id.present?
end
2023-03-17 16:20:25 +05:30
def synthetic_note_class
StateNote
end
2021-01-03 14:25:43 +05:30
private
2021-02-22 17:27:13 +05:30
def issue_usage_metrics
2021-01-03 14:25:43 +05:30
return unless for_issue?
case state
when 'closed'
2022-10-11 01:57:18 +05:30
issue_usage_counter.track_issue_closed_action(author: user, project: issue.project)
2021-01-03 14:25:43 +05:30
when 'reopened'
2022-10-11 01:57:18 +05:30
issue_usage_counter.track_issue_reopened_action(author: user, project: issue.project)
2021-01-03 14:25:43 +05:30
else
# no-op, nothing to do, not a state we're tracking
end
end
def issue_usage_counter
Gitlab::UsageDataCounters::IssueActivityUniqueCounter
end
2020-05-24 23:13:21 +05:30
end
2020-11-24 15:15:51 +05:30
2021-06-08 01:23:25 +05:30
ResourceStateEvent.prepend_mod_with('ResourceStateEvent')