Class: ProjectHook

Inherits:
WebHook show all
Extended by:
Gitlab::Utils::Override
Includes:
Limitable, Presentable, TriggerableHooks
Defined in:
app/models/hooks/project_hook.rb

Constant Summary

Constants included from Limitable

Limitable::GLOBAL_SCOPE

Constants included from TriggerableHooks

TriggerableHooks::AVAILABLE_TRIGGERS

Constants inherited from WebHook

WebHook::InterpolationError, WebHook::SECRET_MASK, WebHook::VARIABLE_REFERENCE_RE

Constants included from WebHooks::AutoDisabling

WebHooks::AutoDisabling::BACKOFF_GROWTH_FACTOR, WebHooks::AutoDisabling::ENABLED_HOOK_TYPES, WebHooks::AutoDisabling::EXCEEDED_FAILURE_THRESHOLD, WebHooks::AutoDisabling::FAILURE_THRESHOLD, WebHooks::AutoDisabling::INITIAL_BACKOFF, WebHooks::AutoDisabling::MAX_BACKOFF, WebHooks::AutoDisabling::MAX_FAILURES

Constants included from Gitlab::Loggable

Gitlab::Loggable::ANONYMOUS

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Instance Method Summary collapse

Methods included from Gitlab::Utils::Override

extended, extensions, included, method_added, override, prepended, queue_verification, verify!

Methods included from Limitable

#exceeds_limits?

Methods included from Presentable

#present

Methods inherited from WebHook

#allow_local_requests?, #async_execute, #execute, #help_path, #interpolated_url, #masked_token, #rate_limit, #rate_limited?, #serializable_hash

Methods included from WebHooks::AutoDisabling

#alert_status, #backoff!, #enable!, #executable?, #failed!, #next_backoff, #permanently_disabled?, #temporarily_disabled?

Methods included from Gitlab::Loggable

#build_structured_payload

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

Instance Method Details

#application_contextObject



38
39
40
# File 'app/models/hooks/project_hook.rb', line 38

def application_context
  super.merge(project: project)
end

#parentObject



43
44
45
# File 'app/models/hooks/project_hook.rb', line 43

def parent
  project
end

#pluralized_nameObject



33
34
35
# File 'app/models/hooks/project_hook.rb', line 33

def pluralized_name
  _('Webhooks')
end

#update_last_failureObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/models/hooks/project_hook.rb', line 48

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