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



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

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

#cmd_create_tag_commitObject



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

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

#cmd_ensure_commit_is_pushedObject



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

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

#cmd_pushObject



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

def cmd_push
  'git push'
end

#cmd_push_tagObject



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

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

#cmd_tag_commit(message) ⇒ Object



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

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

#ensure_commit_is_pushedObject



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

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



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

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

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



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

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
21
# 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)
  tag_name
end

#tag_nameObject

TBD: this should be more flexible



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

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