class DeployController

Attributes

develop_tag_generator[RW]
environ[RW]
git_helper[RW]
other_tag_generator[RW]
tag_types[RW]
user_comms[RW]

Public Class Methods

new(environ, git_helper, user_comms, develop_tag_generator, other_tag_generator, tag_types) click to toggle source
# File lib/build_promotion_tool/controller/deploy_controller.rb, line 10
def initialize(environ, git_helper, user_comms, develop_tag_generator, other_tag_generator, tag_types)
  self.environ = environ
  self.tag_types = tag_types
  self.git_helper = git_helper
  self.user_comms = user_comms
  self.develop_tag_generator = develop_tag_generator
  self.other_tag_generator = other_tag_generator
end

Public Instance Methods

environment_choice() click to toggle source
# File lib/build_promotion_tool/controller/deploy_controller.rb, line 19
def environment_choice
  environ.downcase
  @tags_for_this_commit = git_helper.get_tags_for_this_commit
  dev_tag = tag_types['first_deploy_step']
  all_tags = tag_types['all_tags']

  case environ
  when dev_tag
    if other_tag_generator.tag_exists?(dev_tag, @tags_for_this_commit)
      @user_comms.error_commit_has_dev_tag
      return
    end

    unless develop_tag_generator.develop_tag_exists?
      @user_comms.tell_user_no_develop_tags
      apply_tag(develop_tag_generator.first_tag)
    else
      to_increment = increment_choice
      next_tag = develop_tag_generator.next_develop_tag(to_increment)
      apply_tag(next_tag)
    end

  else
    if all_tags.include? environ
      last_tag_index = all_tags.index(environ) - 1
      last_tag_type = all_tags[last_tag_index]
      select_next_tag(last_tag_type, environ)
    else
      @user_comms.error_incorrect_environ
      return
    end

  end
  @user_comms.say_thank_you
end

Private Instance Methods

apply_tag(next_tag) click to toggle source
# File lib/build_promotion_tool/controller/deploy_controller.rb, line 76
def apply_tag(next_tag)
  @user_comms.ask_permissison_to_apply(next_tag)
  loop do
    answer = @user_comms.user_reply_y_or_n
    if answer == "y"
      git_helper.apply_tag(next_tag)
      git_helper.push_tag_to_remote(next_tag)
    end
    @user_comms.say_no_tag_applied if answer =="n"
    break if ['y', 'n'].include? answer
  end
end
increment_choice() click to toggle source
# File lib/build_promotion_tool/controller/deploy_controller.rb, line 67
def increment_choice
  loop do
    @user_comms.ask_increment_type
    @to_increment = @user_comms.user_increment_choice
    break if ['major', 'minor', 'patch', 'p', 'mi', 'ma'].include? @to_increment
  end
  @to_increment
end
select_next_tag(last_tag_type, next_tag_type) click to toggle source
# File lib/build_promotion_tool/controller/deploy_controller.rb, line 57
def select_next_tag(last_tag_type, next_tag_type)
  if !other_tag_generator.tag_exists?(last_tag_type, @tags_for_this_commit)
    @user_comms.tell_user_no_tag(last_tag_type)
  elsif other_tag_generator.tag_exists?(next_tag_type, @tags_for_this_commit)
    @user_comms.tell_user_already_a_tag(next_tag_type)
  else
    apply_tag(other_tag_generator.next_tag(last_tag_type, next_tag_type, @tags_for_this_commit))
  end
end