Class: Geordi::Gitpt

Inherits:
Object
  • Object
show all
Defined in:
lib/geordi/gitpt.rb

Instance Method Summary collapse

Constructor Details

#initializeGitpt

Returns a new instance of Gitpt.



12
13
14
15
16
# File 'lib/geordi/gitpt.rb', line 12

def initialize
  self.highline = HighLine.new
  self.settings = Settings.new
  self.client = build_client
end

Instance Method Details

#run_branch(from_master: false) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/geordi/gitpt.rb', line 29

def run_branch(from_master: false)
  story = choose_story || Interaction.fail('No story selected.')

  normalized_story_name = normalize_string(story.name)

  branch_list_string = if Util.testing?
    ENV['GEORDI_TESTING_GIT_BRANCHES'] || ''
  else
    `git branch --format="%(refname:short)"`
  end

  if branch_list_string.nil? || branch_list_string.strip.empty?
    Interaction.fail 'Could not determine local git branches.'
  end

  new_branch_name = "#{git_user_initials}/#{normalized_story_name}-#{story.id}"

  local_branches = branch_list_string.split("\n")
  branch_name = local_branches.find { |branch_name| branch_name == new_branch_name }
  branch_name ||= local_branches.find { |branch_name| branch_name.include? story.id.to_s }

  if branch_name.present?
    checkout_branch branch_name, new_branch: false
  else
    checkout_branch new_branch_name, new_branch: true, from_master: from_master
  end
end

#run_commit(git_args) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/geordi/gitpt.rb', line 18

def run_commit(git_args)
  Interaction.warn <<~WARNING unless Util.staged_changes?
    No staged changes. Will create an empty commit.
  WARNING

  story = choose_story
  if story
    create_commit "[##{story.id}] #{story.name}", "Story: #{story.url}", *git_args
  end
end