pivotal-cli 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/bin/pivotal CHANGED
@@ -13,11 +13,11 @@ version PivotalCli::VERSION
13
13
  # Shared re-usable actions
14
14
 
15
15
  def setup_config
16
- username = ask("What's your full name? ")
17
- project_id = ask("Project Id? ", Integer)
18
- token = ask("API Token? (Available at https://www.pivotaltracker.com/profile) ") {|q| q.validate = /\A[A-Za-z0-9]{32}\z/ }
16
+ username = ask("What's your full name? ")
17
+ project_ids = ask("Project Id(s)? (For multiple projects, comma separate Ids) ")
18
+ token = ask("API Token? (Available at https://www.pivotaltracker.com/profile) ") {|q| q.validate = /\A[A-Za-z0-9]{32}\z/ }
19
19
 
20
- @tracker.setup(username, project_id, token)
20
+ @tracker.setup(username, project_ids, token)
21
21
  puts Rainbow("Configuration has been saved to `#{@tracker.config_file}`.").yellow
22
22
  end
23
23
 
@@ -46,11 +46,14 @@ desc 'Display pivotal items assigned to you'
46
46
  command :list do |c|
47
47
  c.action do |global_options,options,args|
48
48
  ensure_setup_complete
49
- stories = @tracker.my_stories
50
- puts Rainbow("\n You have #{stories.length} stories assigned to you.\n").green
49
+ stories_per_project = @tracker.my_stories_per_project
50
+ stories_per_project.each do |id, name, stories|
51
+ next if stories.length == 0
51
52
 
52
- stories.each_with_index do |story, index|
53
- puts formatted_story(story)
53
+ puts Rainbow("\n == #{name} - #{stories.length} stor#{stories.length == 1 ? 'y' : 'ies'} assigned to you.\n").green
54
+ stories.each do |story|
55
+ puts formatted_story(story)
56
+ end
54
57
  end
55
58
  end
56
59
  end
@@ -65,32 +68,50 @@ command :branch do |c|
65
68
  next
66
69
  end
67
70
 
68
- stories = @tracker.my_stories
71
+ stories_per_project = @tracker.my_stories_per_project
72
+ stories_per_id = []
73
+ stories = stories_per_project.map(&:last).flatten
74
+
69
75
  branch_name = args[0]
70
76
  task_id = args[1].to_i
71
77
  story = task_id && stories.find { |story| story.id == task_id }
72
- new_story = PivotalTracker::Story.new(name: '<Create a new story>', id: '????????', current_state: '', estimate: -1)
73
78
 
74
79
  # Ask the user to select a task from the menu
75
80
  if story.nil?
76
- puts Rainbow("\n You have #{stories.length} stories assigned to you.\n").green
77
81
 
78
- # Create a dummy new story
79
- stories << new_story
80
- stories.each_with_index do |story, index|
81
- puts formatted_story(story, index + 1)
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
82
102
  end
83
103
 
84
- question = Rainbow("\nWhich of the #{stories.length} stories are you starting? ").green
85
- task_index = ask(question, Integer) { |q| q.in = 1..(stories.length) }
86
- story = stories[task_index - 1]
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]
87
107
  end
88
108
 
89
109
  # Create the new story on the fly
90
- if story == new_story
91
- story_name = ask(Rainbow('Story name? ').green)
92
- story_description = ask(Rainbow('Story description? ').green)
93
- story = @tracker.create_story(story_name, story_description)
110
+ if story.id.include? '?'
111
+ story.id = nil
112
+ story.name = ask(Rainbow('Story name? ').green)
113
+ story.description = ask(Rainbow('Story description? ').green)
114
+ story = @tracker.create_story(story)
94
115
  if story.errors && story.errors.count > 0
95
116
  puts Rainbow("Whoops, something went wrong when creating the story:").red
96
117
  story.errors.each do |error|
@@ -2,7 +2,7 @@ require 'pivotal-tracker'
2
2
 
3
3
  module PivotalCli
4
4
  class Tracker
5
- attr_accessor :project, :username
5
+ attr_accessor :projects, :username
6
6
 
7
7
  def config_file
8
8
  @config_file ||= "#{ENV['HOME']}/.pivotal"
@@ -12,27 +12,26 @@ module PivotalCli
12
12
  File.exists?(config_file)
13
13
  end
14
14
 
15
- def setup(username, project_id, token)
15
+ def setup(username, project_ids, token)
16
16
  username = username.strip
17
17
  File.open(config_file, 'w') do |file|
18
18
  file.puts(username)
19
- file.puts(project_id)
19
+ file.puts(project_ids)
20
20
  file.puts(token)
21
21
  end
22
22
  end
23
23
 
24
- def my_stories
25
- @project.stories.all(owned_by: username).reject { |s| s.current_state =~ /accepted/ }
24
+ def my_stories_per_project
25
+ projects.map do |project|
26
+ stories = project.stories.all(owned_by: username).reject { |s| s.current_state =~ /accepted/ }
27
+ [project.id, project.name, stories]
28
+ end
26
29
  end
27
30
 
28
- def create_story(name, description)
29
- attributes = {
30
- story_type: 'feature',
31
- name: name,
32
- description: description,
33
- owned_by: username
34
- }
35
- @project.stories.create(attributes)
31
+ def create_story(story)
32
+ story.story_type = 'feature'
33
+ story.owned_by = username
34
+ story.create # Return a new story object (with id)
36
35
  end
37
36
 
38
37
  def set_points(story, points)
@@ -46,13 +45,13 @@ module PivotalCli
46
45
  def load_configuration
47
46
  File.open(config_file, 'r') do |file|
48
47
  lines = file.readlines
49
- @username = lines[0].strip
50
- token = lines[2].strip
51
- project_id = lines[1].strip
48
+ @username = lines[0].strip
49
+ token = lines[2].strip
50
+ project_ids = lines[1].split(',').map(&:strip)
52
51
 
53
52
  PivotalTracker::Client.token = token
54
53
  PivotalTracker::Client.use_ssl = true
55
- @project = PivotalTracker::Project.find(project_id)
54
+ @projects = project_ids.map { |project_id| PivotalTracker::Project.find(project_id) }
56
55
  end
57
56
  end
58
57
  end
@@ -1,3 +1,3 @@
1
1
  module PivotalCli
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  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.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-23 00:00:00.000000000 Z
12
+ date: 2014-07-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gli