module Verto::DSL::Syntax

Public Instance Methods

after(&block) click to toggle source
# File lib/verto/dsl/syntax.rb, line 71
def after(&block)
  Verto.config.hooks << Hook.new(moment: :after, &block)
end
after_command(command_name, &block) click to toggle source
# File lib/verto/dsl/syntax.rb, line 87
def after_command(command_name, &block)
  deprecate('after_command', use: 'after_command_tag_up')

  Verto.config.hooks << Hook.new(moment: "after_#{command_name}", &block)
end
after_command_tag_up(&block) click to toggle source
# File lib/verto/dsl/syntax.rb, line 97
def after_command_tag_up(&block)
  Verto.config.hooks << Hook.new(moment: 'after_tag_up', &block)
end
before(&block) click to toggle source
# File lib/verto/dsl/syntax.rb, line 67
def before(&block)
  Verto.config.hooks << Hook.new(moment: :before, &block)
end
before_command(command_name, &block) click to toggle source
# File lib/verto/dsl/syntax.rb, line 81
def before_command(command_name, &block)
  deprecate('before_command', use: 'before_command_tag_up')

  Verto.config.hooks << Hook.new(moment: "before_#{command_name}", &block)
end
before_command_tag_up(&block) click to toggle source
# File lib/verto/dsl/syntax.rb, line 93
def before_command_tag_up(&block)
  Verto.config.hooks << Hook.new(moment: 'before_tag_up', &block)
end
before_tag_creation(&block) click to toggle source
# File lib/verto/dsl/syntax.rb, line 101
def before_tag_creation(&block)
  Verto.config.hooks << Hook.new(moment: 'before_tag_creation', &block)
end
branch(*branch_names) click to toggle source
# File lib/verto/dsl/syntax.rb, line 35
def branch(*branch_names)
  branch_names.any? do |branch|
    return branch.match?(current_branch) if branch.is_a?(Regexp)

    branch.to_s.include? current_branch
  end
end
command_options() click to toggle source
# File lib/verto/dsl/syntax.rb, line 63
def command_options
  Verto.config.command_options
end
config(&block) click to toggle source
# File lib/verto/dsl/syntax.rb, line 15
def config(&block)
  Verto.config.instance_eval(&block)
end
confirm(text) click to toggle source

TODO: Use delegator

# File lib/verto/dsl/syntax.rb, line 126
def confirm(text)
  CliHelpers.confirm(text)
end
context(condition, &block) click to toggle source
# File lib/verto/dsl/syntax.rb, line 43
def context(condition, &block)
  block.call if condition
end
current_branch() click to toggle source
# File lib/verto/dsl/syntax.rb, line 31
def current_branch
  @current_branch ||= git('rev-parse --abbrev-ref HEAD', output: false).output.chomp.strip
end
env(environment_name) click to toggle source
# File lib/verto/dsl/syntax.rb, line 121
def env(environment_name)
  ENV[environment_name]
end
error(text) click to toggle source
# File lib/verto/dsl/syntax.rb, line 130
def error(text)
  stderr.puts text
end
error!(text) click to toggle source
# File lib/verto/dsl/syntax.rb, line 134
def error!(text)
  error(text)

  raise Verto::ExitError
end
file(filepath) click to toggle source
# File lib/verto/dsl/syntax.rb, line 117
def file(filepath)
  DSL::File.new(filepath)
end
git(subcommand, output: :from_config) click to toggle source
# File lib/verto/dsl/syntax.rb, line 47
def git(subcommand, output: :from_config)
  sh("git #{subcommand}", output: output)
end
git!(subcommand, output: :from_config) click to toggle source
# File lib/verto/dsl/syntax.rb, line 51
def git!(subcommand, output: :from_config)
  sh!("git #{subcommand}", output: output)
end
latest_pre_release_version() click to toggle source
# File lib/verto/dsl/syntax.rb, line 27
def latest_pre_release_version
  @latest_pre_release_version ||= latest_semantic_version_for(:pre_release_only)
end
latest_release_version() click to toggle source
# File lib/verto/dsl/syntax.rb, line 23
def latest_release_version
  @latest_release_version ||= latest_semantic_version_for(:release_only)
end
latest_version() click to toggle source
# File lib/verto/dsl/syntax.rb, line 19
def latest_version
  @latest_version ||= latest_semantic_version_for(:all)
end
on(moment, &block) click to toggle source
# File lib/verto/dsl/syntax.rb, line 75
def on(moment, &block)
  deprecate('on', use: 'before_tag_creation')

  Verto.config.hooks << Hook.new(moment: moment, &block)
end
sh(command, output: :from_config) click to toggle source
# File lib/verto/dsl/syntax.rb, line 55
def sh(command, output: :from_config)
  command_executor(output: output).run command
end
sh!(command, output: :from_config) click to toggle source
# File lib/verto/dsl/syntax.rb, line 59
def sh!(command, output: :from_config)
  raise Verto::ExitError, command unless sh(command, output: output).success?
end
update_changelog(with: :merged_pull_requests_with_bracketed_labels, confirmation: true, filename: 'CHANGELOG.md') click to toggle source
# File lib/verto/dsl/syntax.rb, line 105
def update_changelog(with: :merged_pull_requests_with_bracketed_labels, confirmation: true, filename: 'CHANGELOG.md')
  permitted_moments = %w[before_tag_creation after_tag_up]
  unless permitted_moments.include? Verto.current_moment.to_s
    raise ExitError, 'update_changelog is only supported in before_tag_creation or after_command_tag_up'
  end

  UpdateChangelog.new.call(with: with,
                           new_version: new_version,
                           confirmation: confirmation,
                           filename: filename)
end
verto_version(expected_version_string) click to toggle source
# File lib/verto/dsl/syntax.rb, line 6
def verto_version(expected_version_string)
  expected_version = Verto::SemanticVersion.new(expected_version_string)

  verto_version = Verto::SemanticVersion.new(Verto::VERSION)

  error_message = "Current Verto version is #{verto_version}, required version is #{expected_version} or higher"
  raise Verto::ExitError, error_message unless expected_version <= verto_version
end

Private Instance Methods

command_executor(output: :from_config) click to toggle source
# File lib/verto/dsl/syntax.rb, line 142
def command_executor(output: :from_config)
  @executors ||= {
    from_config: Verto::SystemCommandExecutor.new,
    true => Verto::SystemCommandExecutor.new(stdout: $stdout, stderr: $stderr),
    false => Verto::SystemCommandExecutor.new(stdout: nil, stderr: nil)
  }

  @executors[output]
end
deprecate(current, use:) click to toggle source
# File lib/verto/dsl/syntax.rb, line 168
def deprecate(current, use:)
  warn "[DEPRECATED] `#{current}` is deprecated and will be removed in a future release, use `#{use}` instead"
end
latest_semantic_version_for(filter) click to toggle source
# File lib/verto/dsl/syntax.rb, line 160
def latest_semantic_version_for(filter)
  tag_version = tag_repository.latest(filter: TagFilter.for(filter))

  return SemanticVersion.new('0.0.0') unless tag_version

  SemanticVersion.new(tag_version)
end
stderr() click to toggle source
# File lib/verto/dsl/syntax.rb, line 152
def stderr
  Verto.stderr
end
tag_repository() click to toggle source
# File lib/verto/dsl/syntax.rb, line 156
def tag_repository
  @tag_repository ||= TagRepository.new
end