Welcome to mirror list, hosted at ThFree Co, Russian Federation.

push_event.rb « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3f1ff979de6be9f61fee62356c5662e858b9a03c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
class PushEvent < Event
  # This validation exists so we can't accidentally use PushEvent with a
  # different "action" value.
  validate :validate_push_action

  # Authors are required as they're used to display who pushed data.
  #
  # We're just validating the presence of the ID here as foreign key constraints
  # should ensure the ID points to a valid user.
  validates :author_id, presence: true

  # The project is required to build links to commits, commit ranges, etc.
  #
  # We're just validating the presence of the ID here as foreign key constraints
  # should ensure the ID points to a valid project.
  validates :project_id, presence: true

  # The "data" field must not be set for push events since it's not used and a
  # waste of space.
  validates :data, absence: true

  # These fields are also not used for push events, thus storing them would be a
  # waste.
  validates :target_id, absence: true
  validates :target_type, absence: true

  def self.sti_name
    PUSHED
  end

  def push?
    true
  end

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

  def tag?
    return super unless push_event_payload

    push_event_payload.tag?
  end

  def branch?
    return super unless push_event_payload

    push_event_payload.branch?
  end

  def valid_push?
    return super unless push_event_payload

    push_event_payload.ref.present?
  end

  def new_ref?
    return super unless push_event_payload

    push_event_payload.created?
  end

  def rm_ref?
    return super unless push_event_payload

    push_event_payload.removed?
  end

  def commit_from
    return super unless push_event_payload

    push_event_payload.commit_from
  end

  def commit_to
    return super unless push_event_payload

    push_event_payload.commit_to
  end

  def ref_name
    return super unless push_event_payload

    push_event_payload.ref
  end

  def ref_type
    return super unless push_event_payload

    push_event_payload.ref_type
  end

  def branch_name
    return super unless push_event_payload

    ref_name
  end

  def tag_name
    return super unless push_event_payload

    ref_name
  end

  def commit_title
    return super unless push_event_payload

    push_event_payload.commit_title
  end

  def commit_id
    commit_to || commit_from
  end

  def commits_count
    return super unless push_event_payload

    push_event_payload.commit_count
  end

  def validate_push_action
    return if action == PUSHED

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