Class: DeployChanges::Notifier

Inherits:
Object
  • Object
show all
Defined in:
lib/deploy_changes/notifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|config| ... } ⇒ Notifier

Returns a new instance of Notifier.

Yields:

  • (config)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/deploy_changes/notifier.rb', line 35

def initialize
  self.validator = Validator.new(self)

  config = OpenStruct.new

  yield config if block_given?

  self.git_repo_url = config.git_repo_url || ENV["GIT_REPO_URL"]
  self.tag_prefix = config.tag_prefix || ENV["TAG_PREFIX"]

  self.deploy_job_build_number = config.deploy_job_build_number || ENV["DEPLOY_JOB_BUILD_NUMBER"]
  self.deploy_job_name = config.deploy_job_name || ENV["DEPLOY_JOB_NAME"]

  self.new_tag_name = tag_prefix + deploy_job_build_number

  self.slack_channel = config.slack_channel || ENV["SLACK_CHANNEL"]
  self.slack_bot_api_token = config.slack_bot_api_token || ENV["SLACK_BOT_API_TOKEN"]
  configure_slack
end

Instance Attribute Details

#deploy_job_build_numberObject

Returns the value of attribute deploy_job_build_number.



26
27
28
# File 'lib/deploy_changes/notifier.rb', line 26

def deploy_job_build_number
  @deploy_job_build_number
end

#deploy_job_nameObject

Returns the value of attribute deploy_job_name.



26
27
28
# File 'lib/deploy_changes/notifier.rb', line 26

def deploy_job_name
  @deploy_job_name
end

#git_repo_urlObject

Returns the value of attribute git_repo_url.



26
27
28
# File 'lib/deploy_changes/notifier.rb', line 26

def git_repo_url
  @git_repo_url
end

#new_tag_nameObject

Returns the value of attribute new_tag_name.



26
27
28
# File 'lib/deploy_changes/notifier.rb', line 26

def new_tag_name
  @new_tag_name
end

#slack_channelObject

Returns the value of attribute slack_channel.



26
27
28
# File 'lib/deploy_changes/notifier.rb', line 26

def slack_channel
  @slack_channel
end

#tag_prefixObject

Returns the value of attribute tag_prefix.



26
27
28
# File 'lib/deploy_changes/notifier.rb', line 26

def tag_prefix
  @tag_prefix
end

Instance Method Details

#git_repo_directoryObject



65
66
67
68
69
70
# File 'lib/deploy_changes/notifier.rb', line 65

def git_repo_directory
  @git_repo_directory ||= git_repo_url
                            .split('/')
                            .last
                            .gsub('.git', '')
end

#send_deploy_changes_notificationObject



55
56
57
58
59
60
61
62
63
# File 'lib/deploy_changes/notifier.rb', line 55

def send_deploy_changes_notification
  cleanup_repo
  clone_repo
  send_slack_notification
rescue StandardError => e
  raise e
ensure
  cleanup_repo
end