Class: Minfra::Cli::Tag

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/minfra/cli/commands/tag.rb

Instance Method Summary collapse

Methods included from Logging

#debug, #deprecated, #error, #exit_error, #info, #warn

Constructor Details

#initializeTag

Returns a new instance of Tag.



8
9
10
11
12
# File 'lib/minfra/cli/commands/tag.rb', line 8

def initialize
  @now = Time.now.utc
  @format = '%Y_%m_%dT%H_%M_%SZ'
  @tags_folder = '.tags'
end

Instance Method Details

#cmd_add_tag_info(file) ⇒ Object



36
37
38
# File 'lib/minfra/cli/commands/tag.rb', line 36

def cmd_add_tag_info(file)
  "git add #{file}"
end

#cmd_create_tag_commitObject



40
41
42
# File 'lib/minfra/cli/commands/tag.rb', line 40

def cmd_create_tag_commit
  "git commit -m '#{tag_name}'"
end

#cmd_ensure_commit_is_pushedObject



32
33
34
# File 'lib/minfra/cli/commands/tag.rb', line 32

def cmd_ensure_commit_is_pushed
  'git branch -r --contains $(git rev-list --max-count=1 HEAD)'
end

#cmd_pushObject



48
49
50
# File 'lib/minfra/cli/commands/tag.rb', line 48

def cmd_push
  'git push'
end

#cmd_push_tagObject



52
53
54
# File 'lib/minfra/cli/commands/tag.rb', line 52

def cmd_push_tag
  "git push origin #{tag_name}"
end

#cmd_tag_commit(message) ⇒ Object



44
45
46
# File 'lib/minfra/cli/commands/tag.rb', line 44

def cmd_tag_commit(message)
  "git tag -a #{tag_name} -m '#{message}'"
end

#ensure_commit_is_pushedObject



22
23
24
25
26
27
28
29
30
# File 'lib/minfra/cli/commands/tag.rb', line 22

def ensure_commit_is_pushed
  info 'Checking that the current commit is present on the remote.'
  output = run_cmd(cmd_ensure_commit_is_pushed)

  return unless output.empty?

  exit_error "The current commit is not present on the remote.\n" \
             'Please push your changes to origin and try again.'
end

#git_current_branchObject



56
57
58
# File 'lib/minfra/cli/commands/tag.rb', line 56

def git_current_branch
  `git rev-parse --abbrev-ref HEAD`.strip
end

#run_cmd(cmd, _how = :system) ⇒ Object



65
66
67
# File 'lib/minfra/cli/commands/tag.rb', line 65

def run_cmd(cmd, _how = :system)
  Runner.run(cmd)
end

#tag_current_commit_for_deploy(message, format) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/minfra/cli/commands/tag.rb', line 14

def tag_current_commit_for_deploy(message, format)
  @format = format if format

  info 'Creating tag.'
  run_cmd(cmd_tag_commit(message), :system)
  run_cmd(cmd_push_tag, :system)
end

#tag_nameObject

TBD: this should be more flexible



61
62
63
# File 'lib/minfra/cli/commands/tag.rb', line 61

def tag_name
  "#{git_current_branch}-REL-#{@now.strftime(@format)}"
end