Class: PushEvent

Inherits:
Event show all
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::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

ApplicationRecord::MAX_PLUCK

Constants included from HasCheckConstraints

HasCheckConstraints::NOT_NULL_CHECK_PATTERN

Constants included from ResetOnColumnErrors

ResetOnColumnErrors::MAX_RESET_PERIOD

Class Method Summary collapse

Instance Method Summary collapse

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_iid, #target_title, 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

#imported?

Methods included from Presentable

#present

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 ResetOnColumnErrors

#reset_on_union_error, #reset_on_unknown_attribute_error

Methods included from Gitlab::SensitiveSerializableHash

#serializable_hash

Class Method Details

.branch_eventsObject

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_pushedObject

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_nameObject



72
73
74
# File 'app/models/push_event.rb', line 72

def self.sti_name
  actions[:pushed]
end

.without_existing_merge_requestsObject

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_idObject



107
108
109
# File 'app/models/push_event.rb', line 107

def commit_id
  commit_to || commit_from
end

#last_push_to_non_root?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'app/models/push_event.rb', line 111

def last_push_to_non_root?
  branch? && project.default_branch != branch_name
end

#md_ref?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'app/models/push_event.rb', line 96

def md_ref?
  !(rm_ref? || new_ref?)
end

#new_ref?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'app/models/push_event.rb', line 88

def new_ref?
  push_event_payload.created?
end

#push_action?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'app/models/push_event.rb', line 76

def push_action?
  true
end

#push_with_commits?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'app/models/push_event.rb', line 80

def push_with_commits?
  !!(commit_from && commit_to)
end

#ref_nameObject Also known as: branch_name, tag_name



100
101
102
# File 'app/models/push_event.rb', line 100

def ref_name
  push_event_payload.ref
end

#rm_ref?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'app/models/push_event.rb', line 92

def rm_ref?
  push_event_payload.removed?
end

#valid_push?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'app/models/push_event.rb', line 84

def valid_push?
  push_event_payload.ref.present?
end

#validate_push_actionObject



115
116
117
118
119
# File 'app/models/push_event.rb', line 115

def validate_push_action
  return if pushed_action?

  errors.add(:action, "the action #{action.inspect} is not valid")
end