Class: EventCreateService
- Inherits:
-
Object
- Object
- EventCreateService
- Defined in:
- app/services/event_create_service.rb
Overview
EventCreateService class
Used for creating events feed on dashboard after certain user action
Ex.
EventCreateService.new.new_issue(issue, current_user)
Constant Summary collapse
- IllegalActionError =
Class.new(StandardError)
- DEGIGN_EVENT_LABEL =
'usage_activity_by_stage_monthly.create.action_monthly_active_users_design_management'
- MR_EVENT_LABEL =
'usage_activity_by_stage_monthly.create.merge_requests_users'
- MR_EVENT_PROPERTY =
'merge_request_action'
Instance Method Summary collapse
- #approve_mr(merge_request, current_user) ⇒ Object
- #bulk_push(project, current_user, push_data) ⇒ Object
- #close_issue(issue, current_user) ⇒ Object
- #close_milestone(milestone, current_user) ⇒ Object
- #close_mr(merge_request, current_user) ⇒ Object
- #create_project(project, current_user) ⇒ Object
- #destroy_designs(designs, current_user) ⇒ Object
- #destroy_milestone(milestone, current_user) ⇒ Object
- #expired_leave_project(project, current_user) ⇒ Object
- #join_project(project, current_user) ⇒ Object
- #leave_note(note, current_user) ⇒ Object
- #leave_project(project, current_user) ⇒ Object
- #merge_mr(merge_request, current_user) ⇒ Object
- #open_issue(issue, current_user) ⇒ Object
- #open_milestone(milestone, current_user) ⇒ Object
- #open_mr(merge_request, current_user) ⇒ Object
- #push(project, current_user, push_data) ⇒ Object
- #reopen_issue(issue, current_user) ⇒ Object
- #reopen_milestone(milestone, current_user) ⇒ Object
- #reopen_mr(merge_request, current_user) ⇒ Object
- #save_designs(current_user, create: [], update: []) ⇒ Object
-
#wiki_event(wiki_page_meta, author, action, fingerprint) ⇒ Event
Create a new wiki page event.
Instance Method Details
#approve_mr(merge_request, current_user) ⇒ Object
186 187 188 |
# File 'app/services/event_create_service.rb', line 186 def approve_mr(merge_request, current_user) create_record_event(merge_request, current_user, :approved) end |
#bulk_push(project, current_user, push_data) ⇒ Object
123 124 125 |
# File 'app/services/event_create_service.rb', line 123 def bulk_push(project, current_user, push_data) create_push_event(BulkPushEventPayloadService, project, current_user, push_data) end |
#close_issue(issue, current_user) ⇒ Object
21 22 23 |
# File 'app/services/event_create_service.rb', line 21 def close_issue(issue, current_user) create_record_event(issue, current_user, :closed) end |
#close_milestone(milestone, current_user) ⇒ Object
76 77 78 |
# File 'app/services/event_create_service.rb', line 76 def close_milestone(milestone, current_user) create_record_event(milestone, current_user, :closed) end |
#close_mr(merge_request, current_user) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/services/event_create_service.rb', line 42 def close_mr(merge_request, current_user) create_record_event(merge_request, current_user, :closed).tap do Gitlab::UsageDataCounters::HLLRedisCounter.track_event(:merge_request_action, values: current_user.id) track_snowplow_event( action: :closed, project: merge_request.project, user: current_user, label: MR_EVENT_LABEL, property: MR_EVENT_PROPERTY ) end end |
#create_project(project, current_user) ⇒ Object
115 116 117 |
# File 'app/services/event_create_service.rb', line 115 def create_project(project, current_user) create_event(project, current_user, :created) end |
#destroy_designs(designs, current_user) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'app/services/event_create_service.rb', line 144 def destroy_designs(designs, current_user) return [] unless designs.present? track_snowplow_event( action: :destroy, project: designs.first.project, user: current_user, label: DEGIGN_EVENT_LABEL, property: :design_action ) inserted_events = create_record_events(designs.zip([:destroyed].cycle), current_user) Gitlab::UsageDataCounters::HLLRedisCounter.track_event(:design_action, values: current_user.id) Gitlab::UsageDataCounters::HLLRedisCounter.track_event(:git_write_action, values: current_user.id) inserted_events end |
#destroy_milestone(milestone, current_user) ⇒ Object
84 85 86 |
# File 'app/services/event_create_service.rb', line 84 def destroy_milestone(milestone, current_user) create_record_event(milestone, current_user, :destroyed) end |
#expired_leave_project(project, current_user) ⇒ Object
111 112 113 |
# File 'app/services/event_create_service.rb', line 111 def expired_leave_project(project, current_user) create_event(project, current_user, :expired) end |
#join_project(project, current_user) ⇒ Object
103 104 105 |
# File 'app/services/event_create_service.rb', line 103 def join_project(project, current_user) create_event(project, current_user, :joined) end |
#leave_note(note, current_user) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'app/services/event_create_service.rb', line 88 def leave_note(note, current_user) create_record_event(note, current_user, :commented).tap do if note.is_a?(DiffNote) && note.for_merge_request? Gitlab::UsageDataCounters::HLLRedisCounter.track_event(:merge_request_action, values: current_user.id) track_snowplow_event( action: :commented, project: note.project, user: current_user, label: MR_EVENT_LABEL, property: MR_EVENT_PROPERTY ) end end end |
#leave_project(project, current_user) ⇒ Object
107 108 109 |
# File 'app/services/event_create_service.rb', line 107 def leave_project(project, current_user) create_event(project, current_user, :left) end |
#merge_mr(merge_request, current_user) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/services/event_create_service.rb', line 59 def merge_mr(merge_request, current_user) create_record_event(merge_request, current_user, :merged).tap do Gitlab::UsageDataCounters::HLLRedisCounter.track_event(:merge_request_action, values: current_user.id) track_snowplow_event( action: :merged, project: merge_request.project, user: current_user, label: MR_EVENT_LABEL, property: MR_EVENT_PROPERTY ) end end |
#open_issue(issue, current_user) ⇒ Object
17 18 19 |
# File 'app/services/event_create_service.rb', line 17 def open_issue(issue, current_user) create_record_event(issue, current_user, :created) end |
#open_milestone(milestone, current_user) ⇒ Object
72 73 74 |
# File 'app/services/event_create_service.rb', line 72 def open_milestone(milestone, current_user) create_record_event(milestone, current_user, :created) end |
#open_mr(merge_request, current_user) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/services/event_create_service.rb', line 29 def open_mr(merge_request, current_user) create_record_event(merge_request, current_user, :created).tap do Gitlab::UsageDataCounters::HLLRedisCounter.track_event(:merge_request_action, values: current_user.id) track_snowplow_event( action: :created, project: merge_request.project, user: current_user, label: MR_EVENT_LABEL, property: MR_EVENT_PROPERTY ) end end |
#push(project, current_user, push_data) ⇒ Object
119 120 121 |
# File 'app/services/event_create_service.rb', line 119 def push(project, current_user, push_data) create_push_event(PushEventPayloadService, project, current_user, push_data) end |
#reopen_issue(issue, current_user) ⇒ Object
25 26 27 |
# File 'app/services/event_create_service.rb', line 25 def reopen_issue(issue, current_user) create_record_event(issue, current_user, :reopened) end |
#reopen_milestone(milestone, current_user) ⇒ Object
80 81 82 |
# File 'app/services/event_create_service.rb', line 80 def reopen_milestone(milestone, current_user) create_record_event(milestone, current_user, :reopened) end |
#reopen_mr(merge_request, current_user) ⇒ Object
55 56 57 |
# File 'app/services/event_create_service.rb', line 55 def reopen_mr(merge_request, current_user) create_record_event(merge_request, current_user, :reopened) end |
#save_designs(current_user, create: [], update: []) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'app/services/event_create_service.rb', line 127 def save_designs(current_user, create: [], update: []) records = create.zip([:created].cycle) + update.zip([:updated].cycle) return [] if records.empty? = { user: current_user, label: DEGIGN_EVENT_LABEL, property: :design_action } track_snowplow_event(action: :create, project: create.first.project, **) if create.any? track_snowplow_event(action: :update, project: update.first.project, **) if update.any? inserted_events = create_record_events(records, current_user) Gitlab::UsageDataCounters::HLLRedisCounter.track_event(:design_action, values: current_user.id) Gitlab::UsageDataCounters::HLLRedisCounter.track_event(:git_write_action, values: current_user.id) inserted_events end |
#wiki_event(wiki_page_meta, author, action, fingerprint) ⇒ Event
Create a new wiki page event
The fingerprint, if provided, should be sufficient to find duplicate events. Suitable values would be, for example, the current page SHA.
174 175 176 177 178 179 180 181 182 183 184 |
# File 'app/services/event_create_service.rb', line 174 def wiki_event(, , action, fingerprint) raise IllegalActionError, action unless Event::WIKI_ACTIONS.include?(action) Gitlab::UsageDataCounters::HLLRedisCounter.track_event(:wiki_action, values: .id) Gitlab::UsageDataCounters::HLLRedisCounter.track_event(:git_write_action, values: .id) duplicate = Event.().for_fingerprint(fingerprint).first return duplicate if duplicate.present? create_record_event(, , action, fingerprint.presence) end |