tpope-pickler 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,31 +1,115 @@
1
1
  class Pickler
2
2
  class Runner
3
3
 
4
- attr_reader :pickler, :argv
4
+ attr_reader :argv
5
+
6
+ def pickler
7
+ @pickler ||= Pickler.new(Dir.getwd)
8
+ end
5
9
 
6
10
  def initialize(argv)
7
11
  @argv = argv
8
- @pickler = Pickler.new(Dir.getwd)
12
+ @tty = $stdout.tty?
13
+ end
14
+
15
+ COLORS = {
16
+ :black => 0,
17
+ :red => 1,
18
+ :green => 2,
19
+ :yellow => 3,
20
+ :blue => 4,
21
+ :magenta => 5,
22
+ :cyan => 6,
23
+ :white => 7
24
+ }
25
+
26
+ STATE_COLORS = {
27
+ nil => COLORS[:black],
28
+ "rejected" => COLORS[:red],
29
+ "accepted" => COLORS[:green],
30
+ "delivered" => COLORS[:yellow],
31
+ "unscheduled" => COLORS[:white],
32
+ "started" => COLORS[:magenta],
33
+ "finished" => COLORS[:cyan],
34
+ "unstarted" => COLORS[:blue]
35
+ }
36
+
37
+ STATE_SYMBOLS = {
38
+ "unscheduled" => " ",
39
+ "unstarted" => ":|",
40
+ "started" => ":/",
41
+ "finished" => ":)",
42
+ "delivered" => ";)",
43
+ "rejected" => ":(",
44
+ "accepted" => ":D"
45
+ }
46
+
47
+ TYPE_COLORS = {
48
+ 'chore' => COLORS[:blue],
49
+ 'feature' => COLORS[:magenta],
50
+ 'bug' => COLORS[:red],
51
+ 'release' => COLORS[:cyan]
52
+ }
53
+
54
+ TYPE_SYMBOLS = {
55
+ "feature" => "*",
56
+ "chore" => "%",
57
+ "release" => "!",
58
+ "bug" => "/"
59
+ }
60
+
61
+ def color?
62
+ case pickler.config["color"]
63
+ when "always" then true
64
+ when "never" then false
65
+ else
66
+ @tty && RUBY_PLATFORM !~ /mswin|mingw/
67
+ end
68
+ end
69
+
70
+ def puts_summary(story)
71
+ summary = "%6d " % story.id
72
+ type = story.estimate || TYPE_SYMBOLS[story.story_type]
73
+ state = STATE_SYMBOLS[story.current_state]
74
+ if color?
75
+ summary << "\e[3#{STATE_COLORS[story.current_state]}m#{state}\e[00m "
76
+ summary << "\e[01;3#{TYPE_COLORS[story.story_type]}m#{type}\e[00m "
77
+ else
78
+ summary << "#{state} #{type} "
79
+ end
80
+ summary << story.name
81
+ puts summary
82
+ end
83
+
84
+ def paginated_output
85
+ stdout = $stdout
86
+ if @tty && pager = pickler.config["pager"]
87
+ # Modeled after git
88
+ ENV["LESS"] ||= "FRSX"
89
+ IO.popen(pager,"w") do |io|
90
+ $stdout = io
91
+ yield
92
+ end
93
+ else
94
+ yield
95
+ end
96
+ ensure
97
+ $stdout = stdout
9
98
  end
10
99
 
11
100
  def run
12
101
  case first = argv.shift
13
102
  when 'show', /^\d+$/
14
103
  story = pickler.project.story(first == 'show' ? argv.shift : first)
15
- puts story
104
+ paginated_output do
105
+ puts story
106
+ end
16
107
  when 'search'
17
- stories = pickler.project.stories(*argv).group_by {|s| s.current_state}
18
- first = true
19
- states = Pickler::Tracker::Story::STATES
20
- states -= %w(unstarted accepted) if argv.empty?
21
- states.each do |state|
22
- next unless stories[state]
23
- puts unless first
24
- first = false
25
- puts state.upcase
26
- puts '-' * state.length
27
- stories[state].each do |story|
28
- puts "[#{story.id}] #{story.story_type.capitalize}: #{story.name}"
108
+ stories = pickler.project.stories(*argv)
109
+ stories.reject! {|s| %w(unscheduled unstarted accepted).include?(s.current_state)} if argv.empty?
110
+ paginated_output do
111
+ stories.each do |story|
112
+ puts_summary story
29
113
  end
30
114
  end
31
115
  when 'push'
@@ -11,6 +11,7 @@ class Pickler
11
11
  end
12
12
 
13
13
  def story(story_id)
14
+ raise Error, "No story id given" if story_id.to_s.empty?
14
15
  Story.new(self,tracker.get_xml("/projects/#{id}/stories/#{story_id}")["story"])
15
16
  end
16
17
 
@@ -8,7 +8,7 @@ class Pickler
8
8
  attr_reader :project, :iteration
9
9
  reader :url, :labels
10
10
  date_reader :created_at, :accepted_at, :deadline
11
- accessor :current_state, :name, :description, :estimate, :owned_by, :requested_by, :story_type
11
+ accessor :current_state, :name, :description, :owned_by, :requested_by, :story_type
12
12
 
13
13
  def initialize(project, attributes = {})
14
14
  @project = project
@@ -78,6 +78,10 @@ class Pickler
78
78
  [@attributes["notes"]].flatten.compact.map {|n| Note.new(self,n)}
79
79
  end
80
80
 
81
+ def estimate
82
+ @attributes["estimate"].to_i < 0 ? nil : @attributes["estimate"]
83
+ end
84
+
81
85
  def comment!(body)
82
86
  raise ArgumentError if body.strip.empty? || body.size > 5000
83
87
  response = tracker.request_xml(:post, "#{resource_url}/notes",{:text => body}.to_xml(:root => 'note'))
data/pickler.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "pickler"
3
- s.version = "0.0.3"
3
+ s.version = "0.0.4"
4
4
 
5
5
  s.summary = "PIvotal traCKer Liaison to cucumbER"
6
6
  s.description = "Synchronize between Cucumber and Pivotal Tracker"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tpope-pickler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Pope