pivotal-cli 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/pivotal CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'gli'
3
+ require 'launchy'
3
4
  require 'rainbow'
4
5
  require 'pivotal_cli'
5
6
  require 'highline/import'
@@ -40,6 +41,50 @@ def formatted_story(story, index = nil)
40
41
  output
41
42
  end
42
43
 
44
+ def ask_which_story(stories_per_project, show_new = false)
45
+ stories_per_id = []
46
+ story_index = 1
47
+ stories_per_project.each do |id, name, stories|
48
+ puts Rainbow("\n == #{name} - #{stories.length} stor#{stories.length == 1 ? 'y' : 'ies'} assigned to you.\n").green
49
+
50
+ # Create a dummy new story
51
+ if show_new
52
+ new_story = PivotalTracker::Story.new(
53
+ name: '<Create a new story>',
54
+ id: '????????',
55
+ current_state: '',
56
+ estimate: -1,
57
+ project_id: id
58
+ )
59
+ stories << new_story
60
+ end
61
+
62
+ # Show all, yay!
63
+ stories.each do |story|
64
+ puts formatted_story(story, story_index)
65
+ stories_per_id[story_index] = story
66
+ story_index += 1
67
+ end
68
+ end
69
+
70
+ question = Rainbow("\nWhich of the #{story_index - 1} stories? ").green
71
+ selected_index = ask(question, Integer) { |q| q.in = 1..(story_index - 1) }
72
+ stories_per_id[selected_index]
73
+ end
74
+
75
+ def find_story(story_id, allow_create = false)
76
+ stories_per_project = @tracker.my_stories_per_project
77
+ stories = stories_per_project.map(&:last).flatten
78
+ story_id = story_id.to_i
79
+ story = story_id && stories.find { |story| story.id == story_id }
80
+
81
+ if story.nil?
82
+ story = ask_which_story(stories_per_project, allow_create)
83
+ end
84
+
85
+ story
86
+ end
87
+
43
88
  # CLI entry points
44
89
 
45
90
  desc 'Display pivotal items assigned to you'
@@ -58,8 +103,18 @@ command :list do |c|
58
103
  end
59
104
  end
60
105
 
106
+ desc 'Open story in browser'
107
+ arg_name '[story id]'
108
+ command :open do |c|
109
+ c.action do |global_options,options,args|
110
+ ensure_setup_complete
111
+ story = find_story(args[0])
112
+ Launchy.open(story.url)
113
+ end
114
+ end
115
+
61
116
  desc 'Start a pivotal task, and create a branch for it'
62
- arg_name '<branchname> [task id]'
117
+ arg_name '<branchname> [story id]'
63
118
  command :branch do |c|
64
119
  c.action do |global_options,options,args|
65
120
  ensure_setup_complete
@@ -68,46 +123,11 @@ command :branch do |c|
68
123
  next
69
124
  end
70
125
 
71
- stories_per_project = @tracker.my_stories_per_project
72
- stories_per_id = []
73
- stories = stories_per_project.map(&:last).flatten
74
-
75
126
  branch_name = args[0]
76
- task_id = args[1].to_i
77
- story = task_id && stories.find { |story| story.id == task_id }
78
-
79
- # Ask the user to select a task from the menu
80
- if story.nil?
81
-
82
- story_index = 1
83
- stories_per_project.each do |id, name, stories|
84
- puts Rainbow("\n == #{name} - #{stories.length} stor#{stories.length == 1 ? 'y' : 'ies'} assigned to you.\n").green
85
-
86
- # Create a dummy new story
87
- new_story = PivotalTracker::Story.new(
88
- name: '<Create a new story>',
89
- id: '????????',
90
- current_state: '',
91
- estimate: -1,
92
- project_id: id
93
- )
94
-
95
- # Show all, yay!
96
- stories << new_story
97
- stories.each do |story|
98
- puts formatted_story(story, story_index)
99
- stories_per_id[story_index] = story
100
- story_index += 1
101
- end
102
- end
103
-
104
- question = Rainbow("\nWhich of the #{story_index - 1} stories are you starting? ").green
105
- selected_index = ask(question, Integer) { |q| q.in = 1..(story_index - 1) }
106
- story = stories_per_id[selected_index]
107
- end
127
+ story = find_story(args[1], true)
108
128
 
109
129
  # Create the new story on the fly
110
- if story.id.include? '?'
130
+ if story.id[0] == '?'
111
131
  story.id = nil
112
132
  story.name = ask(Rainbow('Story name? ').green)
113
133
  story.description = ask(Rainbow('Story description? ').green)
@@ -1,3 +1,3 @@
1
1
  module PivotalCli
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
data/pivotal_cli.gemspec CHANGED
@@ -15,6 +15,7 @@ spec = Gem::Specification.new do |s|
15
15
  s.executables << 'pivotal'
16
16
  s.add_runtime_dependency('gli','2.11.0')
17
17
  s.add_runtime_dependency('rainbow', '2.0.0')
18
+ s.add_runtime_dependency('launchy', '2.4.2')
18
19
  s.add_runtime_dependency('highline','1.6.21')
19
20
  s.add_runtime_dependency('pivotal-tracker', '0.5.12')
20
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pivotal-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - '='
44
44
  - !ruby/object:Gem::Version
45
45
  version: 2.0.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: launchy
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - '='
52
+ - !ruby/object:Gem::Version
53
+ version: 2.4.2
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.4.2
46
62
  - !ruby/object:Gem::Dependency
47
63
  name: highline
48
64
  requirement: !ruby/object:Gem::Requirement