/
samson_plugin.rb
53 lines (43 loc) · 1.17 KB
/
samson_plugin.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# frozen_string_literal: true
module SamsonAssertible
class SamsonPlugin < Rails::Engine
end
class Notification
class << self
def deliver(deploy)
return unless deploy.stage.notify_assertible? && deploy.succeeded?
conn = Faraday.new(url: 'https://assertible.com')
conn.basic_auth(deploy_token, '')
conn.post(
'/deployments',
{
service: service_key,
environmentName: deploy.stage.name,
version: 'v1',
url: url_helpers.project_deploy_url(
id: deploy.id,
project_id: deploy.project.id
)
}.to_json
)
end
private
def service_key
ENV.fetch('ASSERTIBLE_SERVICE_KEY')
end
def deploy_token
ENV.fetch('ASSERTIBLE_DEPLOY_TOKEN')
end
def url_helpers
Rails.application.routes.url_helpers
end
end
end
end
Samson::Hooks.view :stage_form_checkbox, 'samson_assertible'
Samson::Hooks.callback :after_deploy do |deploy, _|
SamsonAssertible::Notification.deliver(deploy)
end
Samson::Hooks.callback :stage_permitted_params do
:notify_assertible
end