Class: Integrations::Packagist

Inherits:
Integration show all
Extended by:
Gitlab::Utils::Override
Includes:
HasWebHook
Defined in:
app/models/integrations/packagist.rb

Constant Summary

Constants inherited from Integration

Integration::BASE_CLASSES, Integration::DEV_INTEGRATION_NAMES, Integration::INTEGRATION_NAMES, Integration::PROJECT_SPECIFIC_INTEGRATION_NAMES, Integration::SECTION_TYPE_CONNECTION, Integration::UnknownType

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Instance Attribute Summary

Attributes included from Importable

#imported, #importing

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Utils::Override

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

Methods included from HasWebHook

#execute_web_hook!, #hook_ssl_verification, #update_web_hook!

Methods inherited from Integration

#activate_disabled_reason, #activated?, #api_field_names, #async_execute, #attributes, available_integration_names, available_integration_types, boolean_accessor, build_from_integration, #category, #configurable_events, create_from_active_default_integrations, default_integration, default_test_event, #default_test_event, dev_integration_names, #dup, #editable?, #event_channel_names, event_description, #event_field, event_names, #event_names, field, fields, find_or_initialize_all_non_project_specific, find_or_initialize_non_project_specific_integration, #global_fields, #group_level?, #help, #inheritable?, inherited_descendants_from_self_or_ancestors_from, #initialize_properties, instance_exists_for?, #instance_level?, integration_name_to_model, integration_name_to_type, integration_names, #json_fields, #operating?, #parent, #project_level?, project_specific_integration_names, prop_accessor, #properties=, #reencrypt_properties, #reset_updated_properties, #secret_fields, #sections, #show_active_box?, #supported_events, #supports_data_fields?, #testable?, #to_data_fields_hash, #to_integration_hash, #to_param, #updated_properties

Methods included from ResetSecretFields

#exposing_secrets_fields

Methods included from Loggable

#build_message, #log_error, #log_exception, #log_info, #logger

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

Class Method Details

.supported_eventsObject


56
57
58
# File 'app/models/integrations/packagist.rb', line 56

def self.supported_events
  %w(push merge_request tag_push)
end

.to_paramObject


21
22
23
# File 'app/models/integrations/packagist.rb', line 21

def self.to_param
  'packagist'
end

Instance Method Details

#descriptionObject


17
18
19
# File 'app/models/integrations/packagist.rb', line 17

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

#execute(data) ⇒ Object


60
61
62
63
64
# File 'app/models/integrations/packagist.rb', line 60

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

  execute_web_hook!(data)
end

#fieldsObject


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
# File 'app/models/integrations/packagist.rb', line 25

def fields
  [
    {
      type: 'text',
      name: 'username',
      title: _('Username'),
      help: s_('Enter your Packagist username.'),
      placeholder: '',
      required: true
    },
    {
      type: 'password',
      name: 'token',
      title: _('Token'),
      help: s_('Enter your Packagist token.'),
      non_empty_password_title: s_('ProjectService|Enter new token'),
      non_empty_password_help: s_('ProjectService|Leave blank to use your current token.'),
      placeholder: '',
      required: true
    },
    {
      type: 'text',
      name: 'server',
      title: _('Server (optional)'),
      help: s_('Enter your Packagist server. Defaults to https://packagist.org.'),
      placeholder: 'https://packagist.org',
      required: false
    }
  ]
end

#hook_urlObject


78
79
80
81
# File 'app/models/integrations/packagist.rb', line 78

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

#test(data) ⇒ Object


66
67
68
69
70
71
72
73
74
75
# File 'app/models/integrations/packagist.rb', line 66

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

  { success: true, result: result[:message] }
end

#titleObject


13
14
15
# File 'app/models/integrations/packagist.rb', line 13

def title
  'Packagist'
end