class DeployChanges::Validator

Attributes

error_raiser[RW]
notifier[RW]

Public Class Methods

new(notifier_object) click to toggle source
# File lib/deploy_changes/validator.rb, line 9
def initialize(notifier_object)
  self.notifier = notifier_object
  self.error_raiser = ErrorRaiser.new
end

Public Instance Methods

last_command_successful?() click to toggle source
# File lib/deploy_changes/validator.rb, line 56
def last_command_successful?
  $CHILD_STATUS.success?
end
validate_deploy_job_build_number(job_build_number) click to toggle source
# File lib/deploy_changes/validator.rb, line 24
def validate_deploy_job_build_number(job_build_number)
  return if non_empty_string?(job_build_number) && job_build_number.to_i > 0

  error_raiser.raise_deploy_job_build_number_missing_error
end
validate_deploy_job_name(job_name) click to toggle source
# File lib/deploy_changes/validator.rb, line 30
def validate_deploy_job_name(job_name)
  error_raiser.raise_deploy_job_name_missing_error unless non_empty_string?(job_name)
end
validate_new_tag(new_tag_name) click to toggle source
# File lib/deploy_changes/validator.rb, line 38
def validate_new_tag(new_tag_name)
  return if non_empty_string?(new_tag_name) && git_tag_exists?(new_tag_name)

  error_raiser.raise_invalid_tag_name_error(new_tag_name)
end
validate_repo_cloned(repo_directory_name) click to toggle source
# File lib/deploy_changes/validator.rb, line 50
def validate_repo_cloned(repo_directory_name)
  error_raiser.raise_git_repo_clone_failed_error(
    notifier.git_repo_url
  ) unless last_command_successful? && Dir.exist?(repo_directory_name)
end
validate_repo_url(repo_url) click to toggle source
# File lib/deploy_changes/validator.rb, line 14
def validate_repo_url(repo_url)
  error_raiser.raise_invalid_git_repo_url_error(
    repo_url
  ) unless repo_url =~ git_repo_url_regex
end
validate_slack_api_token(token) click to toggle source
# File lib/deploy_changes/validator.rb, line 44
def validate_slack_api_token(token)
  return if non_empty_string?(token)

  error_raiser.raise_slack_api_token_missing_error
end
validate_slack_channel_name(channel_name) click to toggle source
# File lib/deploy_changes/validator.rb, line 34
def validate_slack_channel_name(channel_name)
  error_raiser.raise_slack_channel_missing_error unless non_empty_string?(channel_name)
end
validate_tag_prefix(prefix) click to toggle source
# File lib/deploy_changes/validator.rb, line 20
def validate_tag_prefix(prefix)
  error_raiser.raise_tag_prefix_missing_error unless non_empty_string?(prefix)
end

Private Instance Methods

git_repo_url_regex() click to toggle source
# File lib/deploy_changes/validator.rb, line 62
def git_repo_url_regex
  /^https:\/\/github.com\/(.*)\/(.*)/
end
git_tag_exists?(tag_name) click to toggle source
# File lib/deploy_changes/validator.rb, line 66
def git_tag_exists?(tag_name)
  tag_command_output = `cd #{notifier.git_repo_directory} && git tag -l #{tag_name}`

  $CHILD_STATUS.success? && tag_command_output.split("\n").count == 1
end
non_empty_string?(string_var) click to toggle source
# File lib/deploy_changes/validator.rb, line 72
def non_empty_string?(string_var)
  string_var.is_a?(String) && !string_var.empty?
end