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
|
|
|
|
|
2022-07-13 20:08:59 -04:00
|
|
|
field :username,
|
2022-07-28 14:09:03 -04:00
|
|
|
title: -> { s_('Username') },
|
2022-07-13 20:08:59 -04:00
|
|
|
help: -> { s_('Enter your Packagist username.') },
|
|
|
|
placeholder: '',
|
|
|
|
required: true
|
|
|
|
|
|
|
|
field :token,
|
|
|
|
type: 'password',
|
2022-07-28 14:09:03 -04:00
|
|
|
title: -> { s_('Token') },
|
2022-07-13 20:08:59 -04:00
|
|
|
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
|
|
|
|
|
|
|
|
field :server,
|
2022-07-28 14:09:03 -04:00
|
|
|
title: -> { s_('Server (optional)') },
|
2022-07-13 20:08:59 -04:00
|
|
|
help: -> { s_('Enter your Packagist server. Defaults to https://packagist.org.') },
|
2022-07-28 14:09:03 -04:00
|
|
|
placeholder: 'https://packagist.org',
|
|
|
|
exposes_secrets: true,
|
|
|
|
required: false
|
2021-05-24 08:10:31 -04:00
|
|
|
|
|
|
|
validates :username, presence: true, if: :activated?
|
|
|
|
validates :token, presence: true, if: :activated?
|
|
|
|
|
|
|
|
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 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
|
2022-08-09 11:11:31 -04:00
|
|
|
rescue StandardError => e
|
|
|
|
return { success: false, result: e }
|
2021-05-24 08:10:31 -04:00
|
|
|
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'
|
2022-09-29 17:08:27 -04:00
|
|
|
"#{base_url}/api/update-package?username={username}&apiToken={token}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def url_variables
|
|
|
|
{ 'username' => username, 'token' => token }
|
2021-05-24 08:10:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|