toolshed 0.0.8 → 0.0.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c985d9e718e2feed7ec333208251e24c1db2f3e
4
- data.tar.gz: 4401c13b81de6f31d52c7470c4b332b0e0742e57
3
+ metadata.gz: 2735e0a05ef49646976753969a095916a4f00324
4
+ data.tar.gz: aa781e23427a9534108d1d0727ea3b27fa90f142
5
5
  SHA512:
6
- metadata.gz: e8932dd259abcf841c0b225db249089c8e083a5b4960b6049fa697988654fd7730f55517aa7d8c7392f216cc365d9e68aa8f4556463a0a328808af68cf4118d4
7
- data.tar.gz: f24035635ed27bd5fb3de8979dbc26b60423f16db943528f6b809ebf427981cb1c39061ea469d1a4170fd43458f1ea41ececca1b54818fd53c39e18c004ab676
6
+ metadata.gz: aae5bc491f329b09cf07dd0768ae979b8f7883b5b67e3db2a57c26a11419ccb3da8538f8b8907a0b30627c30a6973bf16a357ba3855c7dd7c45cbc7b164def0d
7
+ data.tar.gz: 473ce7fb64bf9394874fc726fe5b8730297c3604d7a6ebdc8e761f06f6d790905cf1e536bd6e00337c157aa6f2e8301958cfb5cc7f218f2ec40d694cca6ea81a
@@ -52,7 +52,12 @@ create_pull_request [ # create a github pull request based on
52
52
  --title "Pull Request Title" # Title you want to use with the pull request
53
53
  --body "Pull Request Body" # Body you want to use with the pull request
54
54
  ]
55
- get_pivotal_tracker_story_information # Get the ticket information from a PivotalTracker story based on project_id and story_id
55
+ ticket_information [ # Get the ticket information from a story based on ticket system configuration
56
+ --use-defaults="true|false" # If you want to use defaults ticket_id is taken from branch_name otherwise configuration is used
57
+ --clipboard="true|false" # Copy the output to the system clipboard (Mac OSx) tested
58
+ --field="field_name" # The field you want to either output or copy to your clipboard
59
+ --formatted-string="{name} - {url} # Pass a formatted string in ticket name and url and it will return that string replaced by the actual value
60
+ ]
56
61
  create_pivotal_tracker_note # Create a note for a specific PivotalTracker story based on project_id and story_id
57
62
  update_pivotal_tracker_story_status # Update the status of PivotalTracker story
58
63
  create_branch [ # Create a branch default (git) and push it to your local repository
@@ -66,7 +71,9 @@ push_branch [ # Push your current working branch to yo
66
71
  --force # Push your current working branch up with --force after
67
72
  --branch-name "another" # Push this specific branch up instead of your current working branch
68
73
  ]
69
- get_daily_time_update # Get a daily update from your time tracking toolset currently harvest is supported
74
+ get_daily_time_update [ # Get a daily update from your time tracking toolset currently harvest is supported
75
+ --format="html|text" # Format you want if you want html it will open html page in broswer otherwise puts out plain text
76
+ ]
70
77
  list_branches [ # List branches for your remote repository
71
78
  --repository-name "depot" # The repository name you want to list branches for if not passed pull_from_repository_name is used
72
79
  ]
@@ -149,6 +156,25 @@ if $0.split("/").last == 'toolshed'
149
156
  options[:branch_name] = opt
150
157
  end
151
158
  end,
159
+ 'get_daily_time_update' => OptionParser.new do |opts|
160
+ opts.on("--format [ARG]") do |opt|
161
+ options[:format] = opt
162
+ end
163
+ end,
164
+ 'ticket_information' => OptionParser.new do |opts|
165
+ opts.on("--use-defaults [ARG]") do |opt|
166
+ options[:use_defaults] = opt
167
+ end
168
+ opts.on("--clipboard [ARG]") do |opt|
169
+ options[:clipboard] = opt
170
+ end
171
+ opts.on("--field [ARG]") do |opt|
172
+ options[:field] = opt
173
+ end
174
+ opts.on("--formatted-string [ARG]") do |opt|
175
+ options[:formatted_string] = opt
176
+ end
177
+ end,
152
178
  }
153
179
 
154
180
  global.order!
@@ -3,6 +3,8 @@ require 'httparty'
3
3
  require 'pivotal-tracker'
4
4
  require 'harvested'
5
5
  require 'veto'
6
+ require 'launchy'
7
+ require 'clipboard'
6
8
 
7
9
  module Toolshed
8
10
  BLANK_REGEX = /\S+/
@@ -1,6 +1,18 @@
1
1
  module Toolshed
2
2
  class Base
3
- # implement base methods here
3
+ def self.wait_for_command(command, seconds=10)
4
+ begin
5
+ Timeout::timeout(seconds) {
6
+ until (system(command))
7
+ sleep 1
8
+ end
9
+ return
10
+ }
11
+ rescue Timeout::Error => e
12
+ puts "Unable to execute command after #{seconds} seconds"
13
+ return
14
+ end
15
+ end
4
16
  end
5
17
  end
6
18
 
@@ -23,7 +23,7 @@ module Toolshed
23
23
  {
24
24
  'create_pull_request' => Toolshed::Commands::CreatePullRequest,
25
25
  'create_pivotal_tracker_note' => Toolshed::Commands::CreatePivotalTrackerNote,
26
- 'get_pivotal_tracker_story_information' => Toolshed::Commands::GetPivotalTrackerStoryInformation,
26
+ 'ticket_information' => Toolshed::Commands::TicketInformation,
27
27
  'update_pivotal_tracker_story_status' => Toolshed::Commands::UpdatePivotalTrackerStoryStatus,
28
28
  'create_branch' => Toolshed::Commands::CreateBranch,
29
29
  'checkout_branch' => Toolshed::Commands::CheckoutBranch,
@@ -38,7 +38,7 @@ end
38
38
 
39
39
  require 'toolshed/commands/create_pull_request'
40
40
  require 'toolshed/commands/create_pivotal_tracker_note'
41
- require 'toolshed/commands/get_pivotal_tracker_story_information'
41
+ require 'toolshed/commands/ticket_information'
42
42
  require 'toolshed/commands/update_pivotal_tracker_story_status'
43
43
  require 'toolshed/commands/create_branch'
44
44
  require 'toolshed/commands/checkout_branch'
@@ -3,14 +3,24 @@ module Toolshed
3
3
  class GetDailyTimeUpdate
4
4
  def execute(args, options = {})
5
5
  if (Toolshed::Client.time_tracking_tool == 'harvest')
6
- harvest = Toolshed::TimeTracking::Harvest.new
6
+ harvest = Toolshed::TimeTracking::Harvest.new(options)
7
7
 
8
8
  puts "Getting time entries:"
9
9
 
10
10
  notes = harvest.previous
11
- notes = "#{notes}\n\n#{harvest.today}"
11
+ notes = "#{notes}#{harvest.line_break}#{harvest.line_break}#{harvest.today}"
12
+ notes = "#{notes}#{harvest.brought_to_you_by_message}"
12
13
 
13
- puts notes
14
+ if (harvest.format == 'html')
15
+ FileUtils.rm_rf(Toolshed::TimeTracking::Harvest::GENERATED_HTML_FILE_LOCATION)
16
+ File.open(Toolshed::TimeTracking::Harvest::GENERATED_HTML_FILE_LOCATION, 'w') {|f| f.write(notes) }
17
+ Launchy.open( Toolshed::TimeTracking::Harvest::GENERATED_HTML_FILE_LOCATION ) do |exception|
18
+ puts "Attempted to open #{uri} and failed because #{exception}"
19
+ end
20
+ puts "Checkout out your default or open browser!"
21
+ else
22
+ puts notes
23
+ end
14
24
  else
15
25
  puts "Time tracking tool is undefined implementation needed"
16
26
  exit
@@ -0,0 +1,79 @@
1
+ module Toolshed
2
+ module Commands
3
+ class TicketInformation
4
+ def execute(args, options = {})
5
+ begin
6
+ ticket_tracker_class = Object.const_get("Toolshed::TicketTracking::#{Toolshed::Client.ticket_tracking_tool.camel_case}")
7
+
8
+ if Object.const_get("#{ticket_tracker_class}::USE_PROJECT_ID")
9
+ ticket_tracker_project_id = read_user_input_project_id("Project ID (Default: #{Toolshed::Client.default_pivotal_tracker_project_id}):", options.merge!({ default: Toolshed::Client.default_pivotal_tracker_project_id }))
10
+ options.merge!({ project_id: ticket_tracker_project_id })
11
+ end
12
+
13
+ ticket_tracker = ticket_tracker_class.create_instance(options)
14
+
15
+ default_ticket_id = Toolshed::TicketTracking::PivotalTracker::story_id_from_branch_name(Toolshed::Git::Base.branch_name)
16
+ ticket_id = read_user_input_ticket_id("Story ID (Default: #{default_ticket_id}):", options.merge!({ default: default_ticket_id }))
17
+
18
+ if Object.const_get("#{ticket_tracker_class}::USE_PROJECT_ID")
19
+ puts "Using Project: #{ticket_tracker_project_id}"
20
+ end
21
+ puts "Using Ticket: #{ticket_id}"
22
+
23
+ result = ticket_tracker.story_information(ticket_id)
24
+
25
+ if (options[:field])
26
+ field_value = result.send(options[:field])
27
+ if (options[:clipboard])
28
+ Clipboard.copy field_value
29
+ end
30
+
31
+ puts field_value
32
+ elsif(options[:formatted_string])
33
+ formatted_string = options[:formatted_string].gsub(/\{(.*?)\}/) { |m| result.send(m.gsub("{", "").gsub("}", "")) }
34
+ if (options[:clipboard])
35
+ Clipboard.copy formatted_string
36
+ end
37
+
38
+ puts formatted_string
39
+ else
40
+ result.instance_variables.each do |name, value|
41
+ puts "#{name}: #{result.instance_variable_get(name).inspect}"
42
+ end
43
+ end
44
+
45
+ return
46
+ rescue => e
47
+ puts e.message
48
+ exit
49
+ end
50
+ end
51
+
52
+ def read_user_input_project_id(message, options)
53
+ return options[:default] if (options.has_key?(:use_defaults))
54
+
55
+ puts message
56
+ value = $stdin.gets.chomp
57
+
58
+ if (value.empty?)
59
+ value = options[:default]
60
+ end
61
+
62
+ value
63
+ end
64
+
65
+ def read_user_input_ticket_id(message, options)
66
+ return options[:default] if (options.has_key?(:use_defaults))
67
+
68
+ puts message
69
+ value = $stdin.gets.chomp
70
+
71
+ if (value.empty?)
72
+ value = options[:default]
73
+ end
74
+
75
+ value
76
+ end
77
+ end
78
+ end
79
+ end
@@ -17,14 +17,10 @@ module Toolshed
17
17
 
18
18
  def checkout(branch_name)
19
19
  branch_name = Toolshed::Git::Base.branch_name_from_id(branch_name)
20
- until system("git checkout #{branch_name} #{Toolshed::Client.git_quiet}")
21
- sleep 1
22
- end
20
+ Toolshed::Base.wait_for_command("git checkout #{branch_name} #{Toolshed::Client.git_quiet}")
23
21
 
24
22
  unless (Toolshed::Git::Base.git_submodule_command.empty?)
25
- until system(Toolshed::Git::Base.git_submodule_command)
26
- sleep 1
27
- end
23
+ Toolshed::Base.wait_for_command(Toolshed::Git::Base.git_submodule_command)
28
24
  end
29
25
 
30
26
  branch_name
@@ -38,9 +34,7 @@ module Toolshed
38
34
  Toolshed::Git::Base.checkout('master')
39
35
  end
40
36
 
41
- until system("git push #{Toolshed::Client.push_to_remote_name} :#{branch_name}; git branch -D #{branch_name}")
42
- sleep 1
43
- end
37
+ Toolshed::Base.wait_for_command("git push #{Toolshed::Client.push_to_remote_name} :#{branch_name}; git branch -D #{branch_name}")
44
38
 
45
39
  branch_name
46
40
  end
@@ -62,9 +56,7 @@ module Toolshed
62
56
  branch_name = (options.has_key?(:branch_name)) ? Toolshed::Git::Base.branch_name_from_id(options[:branch_name]) : Toolshed::Git::Base.branch_name
63
57
  force_command = (options.has_key?(:force_command)) ? '--force' : ''
64
58
 
65
- until system("git push #{Toolshed::Client.push_to_remote_name} #{branch_name} #{force_command}")
66
- sleep 1
67
- end
59
+ Toolshed::Base.wait_for_command("git push #{Toolshed::Client.push_to_remote_name} #{branch_name} #{force_command}")
68
60
 
69
61
  branch_name
70
62
  end
@@ -111,23 +103,15 @@ module Toolshed
111
103
  self.validator.validate!(self)
112
104
 
113
105
  new_branch_name = Toolshed::Git::Base.clean_branch_name(self.to_remote_branch_name)
114
- until system("git remote update #{Toolshed::Client.git_quiet}")
115
- sleep 1
116
- end
106
+ Toolshed::Base.wait_for_command("git remote update #{Toolshed::Client.git_quiet}")
117
107
 
118
- until system("git checkout -b #{new_branch_name} #{self.from_remote_name}/#{self.from_remote_branch_name} #{Toolshed::Client.git_quiet}")
119
- sleep 1
120
- end
108
+ Toolshed::Base.wait_for_command("git checkout -b #{new_branch_name} #{self.from_remote_name}/#{self.from_remote_branch_name} #{Toolshed::Client.git_quiet}")
121
109
 
122
110
  unless (Toolshed::Git::Base.git_submodule_command.empty?)
123
- until system(Toolshed::Git::Base.git_submodule_command)
124
- sleep 1
125
- end
111
+ Toolshed::Base.wait_for_command(Toolshed::Git::Base.git_submodule_command)
126
112
  end
127
113
 
128
- until system("git push #{self.to_remote_name} #{new_branch_name} #{Toolshed::Client.git_quiet}")
129
- sleep 1
130
- end
114
+ Toolshed::Base.wait_for_command("git push #{self.to_remote_name} #{new_branch_name} #{Toolshed::Client.git_quiet}")
131
115
  end
132
116
  end
133
117
  end
@@ -4,8 +4,9 @@ module Toolshed
4
4
  extend TimeTracking
5
5
 
6
6
  MAX_ATTEMPTS = 10
7
+ GENERATED_HTML_FILE_LOCATION = '/tmp/toolshed_generated_time_sheet.html'
7
8
 
8
- attr_accessor :harvest_client, :project_id
9
+ attr_accessor :harvest_client, :project_id, :line_break, :start_list_item, :end_list_item, :start_unorder_list, :end_unorder_list, :format
9
10
 
10
11
  def initialize(options={})
11
12
  username = Toolshed::Client::time_tracking_username
@@ -24,18 +25,27 @@ module Toolshed
24
25
  owner = options[:sub_domain]
25
26
  end
26
27
 
27
- self.harvest_client = ::Harvest.client('ackmanndickenson', 'jwaller@ackmanndickenson.com', 'V0AU2gRMLhs1')
28
+ self.harvest_client = ::Harvest.client(owner, username, password)
28
29
  self.project_id = self.get_project_id
30
+
31
+ # setup formatting
32
+ formatter(options)
29
33
  end
30
34
 
31
- def previous(days_ago=1)
32
- notes = "Previous:\n\n"
35
+ def previous(days_ago=1, options={})
36
+
37
+ notes = "Previous:#{self.line_break}"
33
38
 
34
39
  time_entries = self.harvest_client.time.all((DateTime.now - days_ago), self.project_id)
35
40
  if (time_entries.size > 0 || days_ago == Toolshed::TimeTracking::Harvest::MAX_ATTEMPTS)
41
+ notes = "#{notes}#{self.start_unorder_list}"
36
42
  time_entries.each do |time_entry|
37
- notes = "#{notes}#{time_entry.notes}\n"
43
+ notes = "#{notes}#{self.start_list_item}#{time_entry.notes}#{self.end_list_item}"
44
+ if (self.end_list_item == '')
45
+ notes = "#{notes}#{self.line_break}"
46
+ end
38
47
  end
48
+ notes = "#{notes}#{self.end_unorder_list}"
39
49
  else
40
50
  notes = self.previous(days_ago + 1)
41
51
  end
@@ -44,12 +54,17 @@ module Toolshed
44
54
  end
45
55
 
46
56
  def today
47
- notes = "Today:\n\n"
57
+ notes = "Today:#{self.line_break}"
48
58
 
49
59
  time_entries = self.harvest_client.time.all(Time.now, self.project_id)
60
+ notes = "#{notes}#{self.start_unorder_list}"
50
61
  time_entries.each do |time_entry|
51
- notes = "#{notes}#{time_entry.notes}\n"
62
+ notes = "#{notes}#{self.start_list_item}#{time_entry.notes}#{self.end_list_item}"
63
+ if (self.end_list_item == '')
64
+ notes = "#{notes}#{self.line_break}"
65
+ end
52
66
  end
67
+ notes = "#{notes}#{self.end_unorder_list}"
53
68
 
54
69
  notes
55
70
  end
@@ -63,6 +78,28 @@ module Toolshed
63
78
 
64
79
  project_id
65
80
  end
81
+
82
+ def brought_to_you_by_message
83
+ "#{self.line_break}Provided by Toolshed https://rubygems.org/gems/toolshed#{self.line_break}"
84
+ end
85
+
86
+ def formatter(options={})
87
+ if (options[:format] && options[:format] == 'html')
88
+ self.format = 'html'
89
+ self.line_break = "<br>"
90
+ self.start_list_item = "<li>"
91
+ self.end_list_item = "</li>"
92
+ self.start_unorder_list = "<ul>"
93
+ self.end_unorder_list = "</ul>"
94
+ else
95
+ self.format = 'text'
96
+ self.line_break = "\n"
97
+ self.start_list_item = ""
98
+ self.end_list_item = ""
99
+ self.start_unorder_list = ""
100
+ self.end_unorder_list = ""
101
+ end
102
+ end
66
103
  end
67
104
  end
68
105
  end
@@ -1,3 +1,3 @@
1
1
  module Toolshed
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -14,8 +14,8 @@ Gem::Specification.new do |spec|
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
17
- spec.executables = ["toolshed"]
18
- #spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ #spec.executables = ["toolshed"]
18
+ spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ["lib"]
21
21
 
@@ -24,6 +24,8 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency "pivotal-tracker"
25
25
  spec.add_dependency "harvested"
26
26
  spec.add_dependency "veto"
27
+ spec.add_dependency "launchy"
28
+ spec.add_dependency "clipboard"
27
29
 
28
30
  spec.add_development_dependency "bundler", "~> 1.3"
29
31
  spec.add_development_dependency "rake"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toolshed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - test
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-21 00:00:00.000000000 Z
11
+ date: 2014-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -80,6 +80,34 @@ dependencies:
80
80
  - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: launchy
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: clipboard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: bundler
85
113
  requirement: !ruby/object:Gem::Requirement
@@ -198,6 +226,7 @@ email:
198
226
  - test@gmail.com
199
227
  executables:
200
228
  - toolshed
229
+ - toolshed.rb
201
230
  extensions: []
202
231
  extra_rdoc_files: []
203
232
  files:
@@ -219,9 +248,9 @@ files:
219
248
  - lib/toolshed/commands/create_pull_request.rb
220
249
  - lib/toolshed/commands/delete_branch.rb
221
250
  - lib/toolshed/commands/get_daily_time_update.rb
222
- - lib/toolshed/commands/get_pivotal_tracker_story_information.rb
223
251
  - lib/toolshed/commands/list_branches.rb
224
252
  - lib/toolshed/commands/push_branch.rb
253
+ - lib/toolshed/commands/ticket_information.rb
225
254
  - lib/toolshed/commands/update_pivotal_tracker_story_status.rb
226
255
  - lib/toolshed/error.rb
227
256
  - lib/toolshed/git/git.rb
@@ -1,37 +0,0 @@
1
- module Toolshed
2
- module Commands
3
- class GetPivotalTrackerStoryInformation
4
- def execute(args, options = {})
5
- begin
6
- print "Project ID (Default: #{Toolshed::Client.default_pivotal_tracker_project_id})? "
7
- project_id = $stdin.gets.chomp.strip
8
- if (project_id == '')
9
- project_id = Toolshed::Client.default_pivotal_tracker_project_id
10
- end
11
-
12
- pivotal_tracker = Toolshed::TicketTracking::PivotalTracker.new({
13
- project_id: project_id,
14
- username: Toolshed::TicketTracking::PivotalTracker.username,
15
- password: Toolshed::TicketTracking::PivotalTracker.password,
16
- })
17
-
18
- default_story_id = Toolshed::TicketTracking::PivotalTracker::story_id_from_branch_name(Toolshed::Git::Base.branch_name)
19
- print "Story ID (Default: #{default_story_id})? "
20
- story_id = $stdin.gets.chomp.strip
21
- if (story_id == '')
22
- story_id = default_story_id
23
- end
24
-
25
- result = pivotal_tracker.story_information(story_id)
26
- result.instance_variables.each do |name, value|
27
- puts "#{name}: #{result.instance_variable_get(name).inspect}"
28
- end
29
- exit
30
- rescue => e
31
- puts e.message
32
- exit
33
- end
34
- end
35
- end
36
- end
37
- end