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

project_hook.rb « hooks « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 05c5ad222187a4d89fdfd997ea20f7d0018c344f (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
# frozen_string_literal: true

class ProjectHook < WebHook
  include TriggerableHooks
  include Presentable
  include Limitable
  extend ::Gitlab::Utils::Override

  self.limit_scope = :project

  triggerable_hooks [
    :push_hooks,
    :tag_push_hooks,
    :issue_hooks,
    :confidential_issue_hooks,
    :note_hooks,
    :confidential_note_hooks,
    :merge_request_hooks,
    :job_hooks,
    :pipeline_hooks,
    :wiki_page_hooks,
    :deployment_hooks,
    :feature_flag_hooks,
    :release_hooks,
    :emoji_hooks
  ]

  belongs_to :project
  validates :project, presence: true

  scope :for_projects, ->(project) { where(project: project) }

  def pluralized_name
    _('Webhooks')
  end

  override :application_context
  def application_context
    super.merge(project: project)
  end

  override :parent
  def parent
    project
  end

  override :update_last_failure
  def update_last_failure
    if executable?
      project.cache_web_hook_failure if project.get_web_hook_failure # may need update
    else
      project.cache_web_hook_failure(true) # definitely failing, no need to check

      Gitlab::Redis::SharedState.with do |redis|
        last_failure_key = project.last_failure_redis_key
        time = Time.current.utc.iso8601
        prev = redis.get(last_failure_key)

        redis.set(last_failure_key, time) if !prev || prev < time
      end
    end
  end
end

ProjectHook.prepend_mod_with('ProjectHook')