Class: Afterlife::Release::PreHelper

Inherits:
Helper
  • Object
show all
Defined in:
lib/afterlife/release/pre_helper.rb

Instance Attribute Summary

Attributes inherited from Helper

#cli

Instance Method Summary collapse

Methods inherited from Helper

call, #git, #initialize

Constructor Details

This class inherits a constructor from Afterlife::Release::Helper

Instance Method Details

#callObject



6
7
8
9
10
11
12
# File 'lib/afterlife/release/pre_helper.rb', line 6

def call
  confirm_creation
  check_tag_does_not_exist
  commit
  create_tag
  push_tag if cli.options[:push]
end

#check_tag_does_not_existObject



23
24
25
26
27
28
29
# File 'lib/afterlife/release/pre_helper.rb', line 23

def check_tag_does_not_exist
  tags = `git tag --list "#{tag}"`.chomp
  cli.fatal! "tag #{tag} already exist" unless tags.split.empty?

  `git ls-remote --tags --exit-code '#{git.remotes.first.name}' #{tag} >/dev/null 2>&1`
  cli.fatal! "tag #{tag} already exist on remote" if $CHILD_STATUS.success?
end

#commitObject



40
41
42
43
44
# File 'lib/afterlife/release/pre_helper.rb', line 40

def commit
  version_files = ChangeVersion.call(new_version)
  version_files.each { |path| git.add(path) }
  git.commit("bump #{tag}", no_verify: true)
end

#confirm_creationObject



14
15
16
17
18
19
20
21
# File 'lib/afterlife/release/pre_helper.rb', line 14

def confirm_creation
  return if cli.options[:yes]

  cli.sure? 'You are about to create ' \
            "#{cli.options[:push] ? '(and push) ' : ''}" \
            "the tag #{cli.set_color(tag, :bold)} " \
            'in the current commit'
end

#create_tagObject



31
32
33
# File 'lib/afterlife/release/pre_helper.rb', line 31

def create_tag
  git.add_tag(tag)
end

#new_versionObject



50
51
52
# File 'lib/afterlife/release/pre_helper.rb', line 50

def new_version
  @new_version ||= Bump::Semver.calculate_next(:pre, cli.options[:name])
end

#push_tagObject



35
36
37
38
# File 'lib/afterlife/release/pre_helper.rb', line 35

def push_tag
  cli.say_status 'Publishing', tag
  git.push(git.remote('origin'), tag)
end

#tagObject



46
47
48
# File 'lib/afterlife/release/pre_helper.rb', line 46

def tag
  "v#{new_version}"
end