2021-05-24 08:10:31 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Integrations
|
|
|
|
class Packagist < Integration
|
2021-07-14 14:08:31 -04:00
|
|
|
include HasWebHook
|
|
|
|
extend Gitlab::Utils::Override
|
|
|
|
|
2021-05-24 08:10:31 -04:00
|
|
|
prop_accessor :username, :token, :server
|
|
|
|
|
|
|
|
validates :username, presence: true, if: :activated?
|
|
|
|
validates :token, presence: true, if: :activated?
|
|
|
|
|
|
|
|
default_value_for :push_events, true
|
|
|
|
default_value_for :tag_push_events, true
|
|
|
|
|
|
|
|
def title
|
|
|
|
'Packagist'
|
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
2021-07-26 20:08:48 -04:00
|
|
|
s_('Integrations|Keep your PHP dependencies updated on Packagist.')
|
2021-05-24 08:10:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.to_param
|
|
|
|
'packagist'
|
|
|
|
end
|
|
|
|
|
|
|
|
def fields
|
|
|
|
[
|
2021-07-26 20:08:48 -04:00
|
|
|
{
|
|
|
|
type: 'text',
|
|
|
|
name: 'username',
|
|
|
|
title: _('Username'),
|
|
|
|
help: s_('Enter your Packagist username.'),
|
|
|
|
placeholder: '',
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'text',
|
|
|
|
name: 'token',
|
|
|
|
title: _('Token'),
|
|
|
|
help: s_('Enter your Packagist 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
|
|
|
|
}
|
2021-05-24 08:10:31 -04:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.supported_events
|
|
|
|
%w(push merge_request tag_push)
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute(data)
|
|
|
|
return unless supported_events.include?(data[:object_kind])
|
|
|
|
|
2021-07-14 14:08:31 -04:00
|
|
|
execute_web_hook!(data)
|
2021-05-24 08:10:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2021-07-14 14:08:31 -04:00
|
|
|
override :hook_url
|
2021-05-24 08:10:31 -04:00
|
|
|
def hook_url
|
|
|
|
base_url = server.presence || 'https://packagist.org'
|
|
|
|
"#{base_url}/api/update-package?username=#{username}&apiToken=#{token}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|