Class: PushEvent
- Inherits:
-
Event
- Object
- ActiveRecord::Base
- ApplicationRecord
- Event
- PushEvent
- Defined in:
- app/models/push_event.rb
Constant Summary
Constants inherited from Event
Event::CONTRIBUTABLE_TARGET_TYPES, Event::DESIGN_ACTIONS, Event::ISSUE_ACTIONS, Event::ISSUE_TYPES, Event::PROJECT_ACTIONS, Event::REPOSITORY_UPDATED_AT_INTERVAL, Event::RESET_PROJECT_ACTIVITY_INTERVAL, Event::TARGET_TYPES, Event::TEAM_ACTIONS, Event::WIKI_ACTIONS
Constants included from Import::HasImportSource
Import::HasImportSource::IMPORT_SOURCES
Constants inherited from ApplicationRecord
Constants included from HasCheckConstraints
HasCheckConstraints::NOT_NULL_CHECK_PATTERN
Constants included from ResetOnColumnErrors
ResetOnColumnErrors::MAX_RESET_PERIOD
Class Method Summary collapse
-
.branch_events ⇒ Object
Returns events of pushes to a branch.
-
.created_or_pushed ⇒ Object
Returns events of pushes that either pushed to an existing ref or created a new one.
- .sti_name ⇒ Object
-
.without_existing_merge_requests ⇒ Object
Returns PushEvent instances for which no merge requests have been created.
Instance Method Summary collapse
- #commit_id ⇒ Object
- #last_push_to_non_root? ⇒ Boolean
- #md_ref? ⇒ Boolean
- #new_ref? ⇒ Boolean
- #push_action? ⇒ Boolean
- #push_with_commits? ⇒ Boolean
- #ref_name ⇒ Object (also: #branch_name, #tag_name)
- #rm_ref? ⇒ Boolean
- #validate_push_action ⇒ Object
Methods inherited from Event
#action_name, #authored_by?, #body?, #commit_note?, #created_project_action?, #created_target?, #created_wiki_page?, #design, #design?, #design_note?, #ensure_sharding_key, find_sti_class, #has_no_project_and_group?, #issue, #issue?, #issue_note?, limit_recent, #membership_changed?, #merge_request, #merge_request?, #merge_request_note?, #milestone, #milestone?, model_name, #note, #note?, #note_target, #note_target_id, #note_target_reference, #personal_snippet_note?, #present, #project?, #project_snippet_note?, #reset_project_activity, #resource_parent, #snippet_note?, #target, #target_id, #target_iid, #target_title, #target_type, target_types, #to_partial_path, #update_project, #updated_wiki_page?, #visible_to_user?, #wiki_page, #wiki_page?, #wiki_page_note?, #work_item?
Methods included from Import::HasImportSource
Methods included from Presentable
Methods inherited from ApplicationRecord
===, cached_column_list, #create_or_load_association, current_transaction, declarative_enum, default_select_columns, delete_all_returning, #deleted_from_database?, id_in, id_not_in, iid_in, nullable_column?, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
Methods included from Organizations::Sharding
Methods included from ResetOnColumnErrors
#reset_on_union_error, #reset_on_unknown_attribute_error
Methods included from Gitlab::SensitiveSerializableHash
Class Method Details
.branch_events ⇒ Object
Returns events of pushes to a branch.
46 47 48 49 50 51 |
# File 'app/models/push_event.rb', line 46 def self.branch_events ref_type = PushEventPayload.ref_types[:branch] joins(:push_event_payload) .where(push_event_payloads: { ref_type: ref_type }) end |
.created_or_pushed ⇒ Object
Returns events of pushes that either pushed to an existing ref or created a new one.
35 36 37 38 39 40 41 42 43 |
# File 'app/models/push_event.rb', line 35 def self.created_or_pushed actions = [ PushEventPayload.actions[:pushed], PushEventPayload.actions[:created] ] joins(:push_event_payload) .where(push_event_payloads: { action: actions }) end |
.sti_name ⇒ Object
72 73 74 |
# File 'app/models/push_event.rb', line 72 def self.sti_name actions[:pushed] end |
.without_existing_merge_requests ⇒ Object
Returns PushEvent instances for which no merge requests have been created.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/models/push_event.rb', line 54 def self.without_existing_merge_requests existing_mrs = MergeRequest.except(:order, :where) .select(1) .where('merge_requests.source_project_id = events.project_id') .where('merge_requests.source_branch = push_event_payloads.ref') .with_state(:opened) # For reasons unknown the use of #eager_load will result in the # "push_event_payload" association not being set. Because of this we're # using "joins" here, which does mean an additional query needs to be # executed in order to retrieve the "push_event_association" when the # returned PushEvent is used. joins(:push_event_payload) .where('NOT EXISTS (?)', existing_mrs) .created_or_pushed .branch_events end |
Instance Method Details
#commit_id ⇒ Object
103 104 105 |
# File 'app/models/push_event.rb', line 103 def commit_id commit_to || commit_from end |
#last_push_to_non_root? ⇒ Boolean
107 108 109 |
# File 'app/models/push_event.rb', line 107 def last_push_to_non_root? branch? && project.default_branch != branch_name end |
#md_ref? ⇒ Boolean
92 93 94 |
# File 'app/models/push_event.rb', line 92 def md_ref? !(rm_ref? || new_ref?) end |
#new_ref? ⇒ Boolean
84 85 86 |
# File 'app/models/push_event.rb', line 84 def new_ref? push_event_payload.created? end |
#push_action? ⇒ Boolean
76 77 78 |
# File 'app/models/push_event.rb', line 76 def push_action? true end |
#push_with_commits? ⇒ Boolean
80 81 82 |
# File 'app/models/push_event.rb', line 80 def push_with_commits? !!(commit_from && commit_to) end |
#ref_name ⇒ Object Also known as: branch_name, tag_name
96 97 98 |
# File 'app/models/push_event.rb', line 96 def ref_name push_event_payload.ref end |
#rm_ref? ⇒ Boolean
88 89 90 |
# File 'app/models/push_event.rb', line 88 def rm_ref? push_event_payload.removed? end |
#validate_push_action ⇒ Object
111 112 113 114 115 |
# File 'app/models/push_event.rb', line 111 def validate_push_action return if pushed_action? errors.add(:action, "the action #{action.inspect} is not valid") end |