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