Class: Mina::Slack::Promulgator::Helper

Inherits:
Object
  • Object
show all
Defined in:
lib/mina/slack/promulgator/helper.rb

Class Method Summary collapse

Class Method Details

.default_github_urlObject



15
16
17
18
19
# File 'lib/mina/slack/promulgator/helper.rb', line 15

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

.failure_message(emoji, repository, github_url) ⇒ Object



25
26
27
# File 'lib/mina/slack/promulgator/helper.rb', line 25

def self.failure_message(emoji, repository, github_url)
  "#{emoji} [#{project_name(repository)}] deploy failed: #{github_url}/commit/'\"$GIT_HASH\"'"
end

.failure_payload(text, channel, name, application_emoji) ⇒ Object



33
34
35
# File 'lib/mina/slack/promulgator/helper.rb', line 33

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

.project_name(repository) ⇒ Object



10
11
12
13
# File 'lib/mina/slack/promulgator/helper.rb', line 10

def self.project_name(repository)
  regex = /:(\w+)\/((\w|-)+)/
  repository.match(regex)[2]
end

.requirements_check(slack_promulgator_webhook_url) ⇒ Object



6
7
8
# File 'lib/mina/slack/promulgator/helper.rb', line 6

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

.success_message(emoji, repository, github_url) ⇒ Object



21
22
23
# File 'lib/mina/slack/promulgator/helper.rb', line 21

def self.success_message(emoji, repository, github_url)
  "#{emoji} [#{project_name(repository)}] deployed: #{github_url}/commit/'\"$GIT_HASH\"'"
end

.success_payload(text, channel, name, application_emoji) ⇒ Object



29
30
31
# File 'lib/mina/slack/promulgator/helper.rb', line 29

def self.success_payload(text, channel, name, application_emoji)
  %{{"text": "#{text}", "channel": "#{channel}", "username": "#{name}", "icon_emoji": "#{application_emoji}"}}
end