debian-mirror-gitlab/app/models/hooks/project_hook.rb

68 lines
1.3 KiB
Ruby
Raw Normal View History

2018-11-20 20:47:30 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
class ProjectHook < WebHook
2018-03-17 18:26:18 +05:30
include TriggerableHooks
2020-01-01 13:55:28 +05:30
include Presentable
2020-05-24 23:13:21 +05:30
include Limitable
2021-06-08 01:23:25 +05:30
extend ::Gitlab::Utils::Override
2020-05-24 23:13:21 +05:30
self.limit_scope = :project
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
triggerable_hooks [
:push_hooks,
:tag_push_hooks,
:issue_hooks,
:confidential_issue_hooks,
:note_hooks,
2018-04-05 14:03:07 +05:30
:confidential_note_hooks,
2018-03-17 18:26:18 +05:30
:merge_request_hooks,
:job_hooks,
:pipeline_hooks,
2020-10-24 23:57:45 +05:30
:wiki_page_hooks,
2021-01-29 00:20:46 +05:30
:deployment_hooks,
:feature_flag_hooks,
:release_hooks
2018-03-17 18:26:18 +05:30
]
2014-09-02 18:07:02 +05:30
2017-09-10 17:25:29 +05:30
belongs_to :project
validates :project, presence: true
2020-01-01 13:55:28 +05:30
2022-08-13 15:12:31 +05:30
scope :for_projects, ->(project) { where(project: project) }
2020-01-01 13:55:28 +05:30
def pluralized_name
2020-04-08 14:13:33 +05:30
_('Webhooks')
2020-01-01 13:55:28 +05:30
end
2021-06-08 01:23:25 +05:30
2021-09-04 01:27:46 +05:30
override :application_context
def application_context
super.merge(project: project)
end
2022-01-26 12:08:38 +05:30
2022-03-02 08:16:31 +05:30
override :parent
def parent
project
end
2022-08-13 15:12:31 +05:30
override :update_last_failure
def update_last_failure
return if executable?
key = "web_hooks:last_failure:project-#{project_id}"
time = Time.current.utc.iso8601
Gitlab::Redis::SharedState.with do |redis|
prev = redis.get(key)
redis.set(key, time) if !prev || prev < time
end
end
2022-01-26 12:08:38 +05:30
private
override :web_hooks_disable_failed?
def web_hooks_disable_failed?
Feature.enabled?(:web_hooks_disable_failed, project)
end
2014-09-02 18:07:02 +05:30
end
2019-12-04 20:38:33 +05:30
2021-06-08 01:23:25 +05:30
ProjectHook.prepend_mod_with('ProjectHook')