-
Notifications
You must be signed in to change notification settings - Fork 1
/
helper.rb
42 lines (32 loc) · 1.5 KB
/
helper.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
module Mina
module Slack
module Promulgator
class Helper
def self.requirements_check(slack_promulgator_webhook_url)
raise "Must set 'slack_promulgator_webhook_url' in your deploy file for promulgator to work" unless slack_promulgator_webhook_url
end
def self.project_name(repository)
regex = /:(\w+)\/((\w|-)+)/
repository.match(regex)[2]
end
def self.default_github_url
remote_origin_url = `git config --get remote.origin.url`
path = remote_origin_url.gsub("git@", "").gsub(".git", "").gsub("github.com:", "github.com/")
"https://#{path}".strip
end
def self.success_message(emoji, repository, github_url)
"#{emoji} [#{project_name(repository)}] deployed: #{github_url}/commit/'\"$GIT_HASH\"'"
end
def self.failure_message(emoji, repository, github_url)
"#{emoji} [#{project_name(repository)}] deploy failed: #{github_url}/commit/'\"$GIT_HASH\"'"
end
def self.success_payload(text, channel, name, application_emoji)
%{{"text": "#{text}", "channel": "#{channel}", "username": "#{name}", "icon_emoji": "#{application_emoji}"}}
end
def self.failure_payload(text, channel, name, application_emoji)
%{{"attachments": [ { "fallback": "#{text}", "color": "danger", "text": "#{text}" } ], "channel": "#{channel}", "username": "#{name}", "icon_emoji": "#{application_emoji}"}}
end
end
end
end
end