Class: Integrations::Packagist

Inherits:
Integration show all
Includes:
HasWebHook
Defined in:
app/models/integrations/packagist.rb

Constant Summary

Constants included from Base::Integration

Base::Integration::BASE_ATTRIBUTES, Base::Integration::BASE_CLASSES, Base::Integration::DEV_INTEGRATION_NAMES, Base::Integration::ENCRYPTED_PROPERTIES_MAX_SIZE, Base::Integration::INSTANCE_LEVEL_ONLY_INTEGRATION_NAMES, Base::Integration::INTEGRATION_NAMES, Base::Integration::PROJECT_AND_GROUP_LEVEL_ONLY_INTEGRATION_NAMES, Base::Integration::PROJECT_LEVEL_ONLY_INTEGRATION_NAMES, Base::Integration::SECTION_TYPE_CONFIGURATION, Base::Integration::SECTION_TYPE_CONNECTION, Base::Integration::SECTION_TYPE_TRIGGER, Base::Integration::SNOWPLOW_EVENT_ACTION, Base::Integration::SNOWPLOW_EVENT_LABEL, Base::Integration::UnknownType

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from HasCheckConstraints

HasCheckConstraints::NOT_NULL_CHECK_PATTERN

Constants included from ResetOnColumnErrors

ResetOnColumnErrors::MAX_RESET_PERIOD

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasWebHook

#execute_web_hook!, #hook_ssl_verification, #update_web_hook!

Methods included from Base::Integration

#activate!, #activate_disabled_reason, #activated?, #after_build_from_integration, #api_field_names, #async_execute, #attributes, #attribution_notice, #category, #chat?, #ci?, #configurable_events, #deactivate!, #default_test_event, #description, #dup, #editable?, #event_channel_names, #event_names, #fields, #form_fields, #group_level?, #help, #inheritable?, #initialize_properties, #instance_level?, #json_fields, #manual_activation?, #operating?, #organization_id_from_parent, #parent, #project_level?, #reencrypt_properties, #reset_updated_properties, #secret_fields, #sections, #supported_events, #supports_data_fields?, #testable?, #title, #to_database_hash, #to_param, #toggle!, #updated_properties, #validate_encrypted_properties_size_limit

Methods included from Gitlab::Utils::Override

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

Methods inherited from ApplicationRecord

===, cached_column_list, #create_or_load_association, current_transaction, declarative_enum, default_select_columns, delete_all_returning, #deleted_from_database?, id_in, id_not_in, iid_in, nullable_column?, 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 Organizations::Sharding

#sharding_organization

Methods included from ResetOnColumnErrors

#reset_on_union_error, #reset_on_unknown_attribute_error

Methods included from Gitlab::SensitiveSerializableHash

#serializable_hash

Class Method Details

.descriptionObject



36
37
38
# File 'app/models/integrations/packagist.rb', line 36

def self.description
  s_('Integrations|Keep your PHP dependencies updated on Packagist.')
end

.supported_eventsObject



44
45
46
# File 'app/models/integrations/packagist.rb', line 44

def self.supported_events
  %w[push merge_request tag_push]
end

.titleObject



32
33
34
# File 'app/models/integrations/packagist.rb', line 32

def self.title
  'Packagist'
end

.to_paramObject



40
41
42
# File 'app/models/integrations/packagist.rb', line 40

def self.to_param
  'packagist'
end

Instance Method Details

#execute(data) ⇒ Object



48
49
50
51
52
# File 'app/models/integrations/packagist.rb', line 48

def execute(data)
  return unless supported_events.include?(data[:object_kind])

  execute_web_hook!(data)
end

#hook_urlObject



66
67
68
69
# File 'app/models/integrations/packagist.rb', line 66

def hook_url
  base_url = server.presence || 'https://packagist.org'
  "#{base_url}/api/update-package?username={username}&apiToken={token}"
end

#test(data) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'app/models/integrations/packagist.rb', line 54

def test(data)
  begin
    result = execute(data)
    return { success: false, result: result.message } if result.payload[:http_status] != 202
  rescue StandardError => e
    return { success: false, result: e.message }
  end

  { success: true, result: result.message }
end

#url_variablesObject



71
72
73
# File 'app/models/integrations/packagist.rb', line 71

def url_variables
  { 'username' => username, 'token' => token }
end