Class: Minfra::Cli::Project::Branch

Inherits:
Command show all
Defined in:
lib/minfra/cli/commands/project/branch.rb

Instance Method Summary collapse

Methods included from Logging

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

Methods included from Common

#run_cmd

Instance Method Details

#create(story_desc) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/minfra/cli/commands/project/branch.rb', line 13

def create(story_desc)
  if options[:tag]
    tag = options[:tag]
  else
    story_desc = story_desc.gsub(/[^0-9a-z-]/i, '_')

    prefix = options[:prefix] || Minfra::Cli.config.project.dig('project', 'branch', 'create', 'prefix')
    unless prefix
      email = Minfra::Cli.config.project.dig('identity', 'email') || `git config user.email`
      fullname = email.split('@').first
      prefix = fullname[0] + fullname.split('.').last
    end

    now = Time.now.utc.strftime('%Y%m%d')
    tag = options[:tag] || "#{prefix}_#{story_desc}_#{now}"
  end

  Runner.run("git checkout -b #{tag}", test: options[:test])
end