Class: Tracker::Cli::Command::Fetch

Inherits:
Object
  • Object
show all
Defined in:
lib/tracker/cli/command/fetch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cli:, object_type:, **arguments) ⇒ Fetch

Returns a new instance of Fetch.



7
8
9
10
11
12
13
14
# File 'lib/tracker/cli/command/fetch.rb', line 7

def initialize(cli: , object_type: , **arguments)
  @cli = cli
  @arguments = arguments
  
  case object_type
  when 'story' then fetch_story(**arguments)
  end
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



5
6
7
# File 'lib/tracker/cli/command/fetch.rb', line 5

def arguments
  @arguments
end

#cliObject (readonly)

Returns the value of attribute cli.



5
6
7
# File 'lib/tracker/cli/command/fetch.rb', line 5

def cli
  @cli
end

Instance Method Details

#create_commit(story) ⇒ Object



43
44
45
46
47
48
# File 'lib/tracker/cli/command/fetch.rb', line 43

def create_commit(story)
  commit_message = "\"[##{story['id']}] #{story['name'].to_json[1..-2]}\""
  command = [ 'git', 'commit', '-m', commit_message ]
  _, stdout = Open3.popen2(*command)
  print stdout.read
end

#fetch_story(object_id: nil, interactive: false, commit: false, **arguments) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/tracker/cli/command/fetch.rb', line 16

def fetch_story(object_id: nil, interactive: false, commit: false, **arguments)
  if object_id
    story = cli.connection.fetch_story(object_id)
  elsif interactive
    story = select_story
  end
    
  if commit
    create_commit(story)
  else
    print "#{story['id']}\t#{story['name'].to_json}\n"
  end
end

#select_storyObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/tracker/cli/command/fetch.rb', line 30

def select_story
  query_params = arguments.fetch(:query_params, {})
  stories = cli.connection.fetch_stories(project: Tracker.project, query: query_params)
  stories.each_with_index do |story, index|
    print "(#{index + 1}) #{story['id']} #{story['name'].to_json}\n"
  end
  
  print "\nWhich Story? "
  index = $stdin.gets.chomp.to_i - 1
  print "\n"
  stories[index]
end