Class: PushEvent

Inherits:
Event show all
Defined in:
app/models/push_event.rb

Constant Summary

Constants inherited from Event

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 inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Event

#action_name, #authored_by?, #body?, #commit_note?, contributions, #created_project_action?, #created_target?, #created_wiki_page?, #design, #design?, #design_note?, 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_snippet_note?, #reset_project_activity, #resource_parent, #snippet_note?, #target_iid, #target_title, target_types, #to_partial_path, #updated_wiki_page?, #visible_to_user?, #wiki_page, #wiki_page?, #work_item?

Methods included from Presentable

#present

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, 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 SensitiveSerializableHash

#serializable_hash

Class Method Details

.branch_eventsObject

Returns events of pushes to a branch.



44
45
46
47
48
49
# File 'app/models/push_event.rb', line 44

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.



33
34
35
36
37
38
39
40
41
# File 'app/models/push_event.rb', line 33

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



70
71
72
# File 'app/models/push_event.rb', line 70

def self.sti_name
  actions[:pushed]
end

.without_existing_merge_requestsObject

Returns PushEvent instances for which no merge requests have been created.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/models/push_event.rb', line 52

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



105
106
107
# File 'app/models/push_event.rb', line 105

def commit_id
  commit_to || commit_from
end

#last_push_to_non_root?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'app/models/push_event.rb', line 109

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

#md_ref?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'app/models/push_event.rb', line 94

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

#new_ref?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'app/models/push_event.rb', line 86

def new_ref?
  push_event_payload.created?
end

#push_action?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'app/models/push_event.rb', line 74

def push_action?
  true
end

#push_with_commits?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'app/models/push_event.rb', line 78

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

#ref_nameObject Also known as: branch_name, tag_name



98
99
100
# File 'app/models/push_event.rb', line 98

def ref_name
  push_event_payload.ref
end

#rm_ref?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'app/models/push_event.rb', line 90

def rm_ref?
  push_event_payload.removed?
end

#valid_push?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'app/models/push_event.rb', line 82

def valid_push?
  push_event_payload.ref.present?
end

#validate_push_actionObject



113
114
115
116
117
# File 'app/models/push_event.rb', line 113

def validate_push_action
  return if pushed_action?

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