Class: Tracker::Cli::Command::Fetch
- Inherits:
-
Object
- Object
- Tracker::Cli::Command::Fetch
- Defined in:
- lib/tracker/cli/command/fetch.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#cli ⇒ Object
readonly
Returns the value of attribute cli.
Instance Method Summary collapse
- #create_commit(story) ⇒ Object
- #fetch_story(object_id: nil, interactive: false, commit: false, **arguments) ⇒ Object
-
#initialize(cli:, object_type:, **arguments) ⇒ Fetch
constructor
A new instance of Fetch.
- #select_story ⇒ Object
Constructor Details
#initialize(cli:, object_type:, **arguments) ⇒ Fetch
Returns a new instance of Fetch.
7 8 9 10 11 12 13 14 15 16 |
# 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) when 'account' print cli.connection.fetch(accounts: object_id) end end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
5 6 7 |
# File 'lib/tracker/cli/command/fetch.rb', line 5 def arguments @arguments end |
#cli ⇒ Object (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) = "[##{story['id']}] #{story['name'].to_json[1..-2]}" command = [ 'git', 'commit', '-m', ] _, stdout = Open3.popen2(*command) $stderr.print stdout.read end |
#fetch_story(object_id: nil, interactive: false, commit: false, **arguments) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/tracker/cli/command/fetch.rb', line 18 def fetch_story(object_id: nil, interactive: false, commit: false, **arguments) if object_id story = cli.connection.fetch(stories: object_id) elsif interactive story = select_story end if commit create_commit(story) else print "#{story['name']} (#{story['story_type']} ##{story['id']})\n\n" print "#{story['labels'].join(', ')}\n\n" if story['labels'] && story['labels'].any? print "#{story['description'] || '(no description)'}\n\n" print "#{story['url']}\n" end end |
#select_story ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/tracker/cli/command/fetch.rb', line 35 def select_story query_params = arguments.fetch(:query_params, {}) stories = cli.connection.fetch(:stories, projects: Tracker.project, query: query_params) select = View::Select.new('Which Story?', stories) { |story| "#{story['id']} #{story['name'].to_json}" } select.selection end |