Class: PackagistService

Inherits:
Service show all
Defined in:
app/models/project_services/packagist_service.rb

Constant Summary

Constants inherited from Service

Service::DEV_SERVICE_NAMES, Service::PROJECT_SPECIFIC_SERVICE_NAMES, Service::SERVICE_NAMES

Instance Attribute Summary

Attributes included from Importable

#imported, #importing

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Service

#activated?, #api_field_names, #async_execute, available_services_names, available_services_types, boolean_accessor, build_from_integration, #can_test?, #category, #configurable_event_actions, #configurable_events, create_from_active_default_integrations, default_integration, #default_test_event, default_test_event, dev_services_names, #editable?, #event_channel_names, event_description, #event_field, #event_names, event_names, #external_issue_tracker?, #external_wiki?, find_or_create_templates, find_or_initialize_all_non_project_specific, find_or_initialize_non_project_specific_integration, #global_fields, #help, inherited_descendants_from_self_or_ancestors_from, #initialize_properties, instance_exists_for?, #json_fields, #operating?, project_specific_services_names, prop_accessor, #reset_updated_properties, services_names, #show_active_box?, supported_event_actions, #supported_events, #supports_data_fields?, #to_data_fields_hash, #to_param, #to_service_hash, #updated_properties

Methods included from ProjectServicesLoggable

#build_message, #log_error, #log_info, #logger

Methods inherited from ApplicationRecord

at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, where_exists, with_fast_statement_timeout, without_order

Class Method Details

.supported_eventsObject


34
35
36
# File 'app/models/project_services/packagist_service.rb', line 34

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

.to_paramObject


22
23
24
# File 'app/models/project_services/packagist_service.rb', line 22

def self.to_param
  'packagist'
end

Instance Method Details

#compose_service_hookObject


55
56
57
58
59
# File 'app/models/project_services/packagist_service.rb', line 55

def compose_service_hook
  hook = service_hook || build_service_hook
  hook.url = hook_url
  hook.save
end

#descriptionObject


18
19
20
# File 'app/models/project_services/packagist_service.rb', line 18

def description
  s_('Integrations|Update your projects on Packagist, the main Composer repository')
end

#execute(data) ⇒ Object


38
39
40
41
42
# File 'app/models/project_services/packagist_service.rb', line 38

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

  service_hook.execute(data)
end

#fieldsObject


26
27
28
29
30
31
32
# File 'app/models/project_services/packagist_service.rb', line 26

def fields
  [
    { type: 'text', name: 'username', placeholder: '', required: true },
    { type: 'text', name: 'token', placeholder: '', required: true },
    { type: 'text', name: 'server', placeholder: 'https://packagist.org', required: false }
  ]
end

#hook_urlObject


61
62
63
64
# File 'app/models/project_services/packagist_service.rb', line 61

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

#test(data) ⇒ Object


44
45
46
47
48
49
50
51
52
53
# File 'app/models/project_services/packagist_service.rb', line 44

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


14
15
16
# File 'app/models/project_services/packagist_service.rb', line 14

def title
  'Packagist'
end