2021-05-24 12:10:31 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Integrations
|
|
|
|
class Packagist < Integration
|
2021-07-14 18:08:31 +00:00
|
|
|
include HasWebHook
|
|
|
|
extend Gitlab::Utils::Override
|
|
|
|
|
2022-07-14 00:08:59 +00:00
|
|
|
field :username,
|
2022-07-28 18:09:03 +00:00
|
|
|
title: -> { s_('Username') },
|
2022-07-14 00:08:59 +00:00
|
|
|
help: -> { s_('Enter your Packagist username.') },
|
|
|
|
placeholder: '',
|
|
|
|
required: true
|
|
|
|
|
|
|
|
field :token,
|
|
|
|
type: 'password',
|
2022-07-28 18:09:03 +00:00
|
|
|
title: -> { s_('Token') },
|
2022-07-14 00:08:59 +00: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 18:09:03 +00:00
|
|
|
title: -> { s_('Server (optional)') },
|
2022-07-14 00:08:59 +00:00
|
|
|
help: -> { s_('Enter your Packagist server. Defaults to https://packagist.org.') },
|
2022-07-28 18:09:03 +00:00
|
|
|
placeholder: 'https://packagist.org',
|
|
|
|
exposes_secrets: true,
|
|
|
|
required: false
|
2021-05-24 12:10:31 +00:00
|
|
|
|
|
|
|
validates :username, presence: true, if: :activated?
|
|
|
|
validates :token, presence: true, if: :activated?
|
|
|
|
|
|
|
|
def title
|
|
|
|
'Packagist'
|
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
2021-07-27 00:08:48 +00:00
|
|
|
s_('Integrations|Keep your PHP dependencies updated on Packagist.')
|
2021-05-24 12:10:31 +00: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 18:08:31 +00:00
|
|
|
execute_web_hook!(data)
|
2021-05-24 12:10:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test(data)
|
|
|
|
begin
|
|
|
|
result = execute(data)
|
|
|
|
return { success: false, result: result[:message] } if result[:http_status] != 202
|
2022-08-09 15:11:31 +00:00
|
|
|
rescue StandardError => e
|
|
|
|
return { success: false, result: e }
|
2021-05-24 12:10:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
{ success: true, result: result[:message] }
|
|
|
|
end
|
|
|
|
|
2021-07-14 18:08:31 +00:00
|
|
|
override :hook_url
|
2021-05-24 12:10:31 +00:00
|
|
|
def hook_url
|
|
|
|
base_url = server.presence || 'https://packagist.org'
|
|
|
|
"#{base_url}/api/update-package?username=#{username}&apiToken=#{token}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|