toolshed 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +11 -0
  4. data/.toolshedrc.sample +32 -0
  5. data/README.md +159 -2
  6. data/Rakefile +3 -3
  7. data/bin/toolshed +6 -1
  8. data/lib/toolshed.rb +38 -28
  9. data/lib/toolshed/base.rb +33 -11
  10. data/lib/toolshed/cli.rb +30 -38
  11. data/lib/toolshed/client.rb +87 -293
  12. data/lib/toolshed/commands/base.rb +65 -23
  13. data/lib/toolshed/commands/checkout_branch.rb +15 -2
  14. data/lib/toolshed/commands/create_branch.rb +34 -29
  15. data/lib/toolshed/commands/create_pivotal_tracker_note.rb +9 -3
  16. data/lib/toolshed/commands/create_pull_request.rb +115 -68
  17. data/lib/toolshed/commands/create_ticket_comment.rb +17 -1
  18. data/lib/toolshed/commands/delete_branch.rb +34 -3
  19. data/lib/toolshed/commands/get_daily_time_update.rb +20 -3
  20. data/lib/toolshed/commands/list_branches.rb +16 -5
  21. data/lib/toolshed/commands/push_branch.rb +28 -9
  22. data/lib/toolshed/commands/rename_branch.rb +29 -0
  23. data/lib/toolshed/commands/ssh.rb +44 -3
  24. data/lib/toolshed/commands/ticket_information.rb +30 -4
  25. data/lib/toolshed/commands/update_pivotal_tracker_story_status.rb +9 -3
  26. data/lib/toolshed/commands/update_ticket_status.rb +8 -2
  27. data/lib/toolshed/entry_point.rb +89 -0
  28. data/lib/toolshed/git.rb +59 -0
  29. data/lib/toolshed/git/branch.rb +224 -0
  30. data/lib/toolshed/git/github.rb +45 -57
  31. data/lib/toolshed/git/validator.rb +14 -0
  32. data/lib/toolshed/logger.rb +46 -0
  33. data/lib/toolshed/password.rb +11 -6
  34. data/lib/toolshed/server_administration/ssh.rb +4 -2
  35. data/lib/toolshed/ticket_tracking/jira.rb +8 -6
  36. data/lib/toolshed/ticket_tracking/pivotal_tracker.rb +8 -6
  37. data/lib/toolshed/time_tracking/harvest.rb +8 -14
  38. data/lib/toolshed/version.rb +25 -1
  39. data/test/commands/checkout_branch_test.rb +11 -7
  40. data/test/commands/create_branch_test.rb +29 -24
  41. data/test/commands/create_pull_request_test.rb +39 -31
  42. data/test/commands/delete_branch_test.rb +35 -25
  43. data/test/commands/get_daily_time_update_test.rb +8 -8
  44. data/test/commands/push_branch_test.rb +27 -15
  45. data/test/commands/rename_branch_test.rb +59 -0
  46. data/test/git/git_helper.rb +5 -5
  47. data/test/git/git_test.rb +36 -31
  48. data/test/git/github_test.rb +9 -46
  49. data/test/helper.rb +11 -11
  50. data/test/server_administration/ssh_test.rb +1 -0
  51. data/test/ticket_tracking/jira_test.rb +18 -16
  52. data/test/time_tracking/harvest_test.rb +8 -6
  53. data/toolshed.gemspec +23 -20
  54. metadata +95 -46
  55. data/bin/toolshed.rb +0 -261
  56. data/lib/toolshed/git/git.rb +0 -119
data/bin/toolshed.rb DELETED
@@ -1,261 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $:.unshift(File.dirname(__FILE__) + '/../lib')
4
- require 'toolshed'
5
- require 'toolshed/cli'
6
-
7
- cli = Toolshed::CLI.new
8
-
9
- require 'optparse'
10
-
11
- def usage
12
- $stderr.puts <<EOF
13
- Command line tool for toolshed. More information about toolshed can
14
- be found at https://github.com/wallerjake/toolshed
15
-
16
- Before using this tool you should create a file called .toolshedrc in your projects directory or home directory if you want to use the settings globally.
17
- Note that it will only read one file which ever file is closest to the directory you are in. Then and add the following to that file:
18
-
19
- ticket_tracking_tool: 'pivotal_tracker' (required)
20
- pivotal_tracker_username: [pivotal_tracker_username] (optional)
21
- pivotal_tracker_password: [pivotal_tracker_password] (optional)
22
- default_pivotal_tracker_project_id: [project_id] (optional)
23
- ticket_status_for_complete: [status] (required (only if using pull requests)) example: "Code Review"
24
-
25
- github_username: [github_username] (optional)
26
- github_password: [github_password] (optional)
27
- github_token: [github_token] (optional) - create the token if your account require two factor you can disable token or enable through Github. See https://github.com/settings/tokens/new for details.
28
- git_tool: github (optional default `github`)
29
- use_git_submodules: false (optional default `false`)
30
- pull_from_remote_name: [pull_from_remote_name] (required)
31
- pull_from_repository_user: [pull_from_repository_username] (required)
32
- pull_from_repository_name: [pull_from_repository_name] (required)
33
- push_to_repository_user: [push_to_repository_user] (required)
34
- push_to_repository_name: [push_to_repository_name] (required)
35
- push_to_remote_name: [push_to_remote_name] (required)
36
- default_pull_request_title_format: [id] - [summary] (optional)
37
-
38
- time_tracking_username: [username] (optional)
39
- time_tracking_password: [password] (optional)
40
- time_tracking_owner: [owner] (optional)
41
- time_tracking_default_project_id: [project_id] (optional)
42
- time_tracking_tool: [tool] (required unless you are not going to be doing time tracking)
43
-
44
- == Commands
45
-
46
- All commands are executed as toolshed [options] command [command-options] args
47
-
48
- The following commands are available:
49
-
50
- help # show this usage
51
- create_pull_request [ # create a github pull request based on the branch you currently have checked out
52
- --tool "github", # Optionally pass in your specific tool this can also be set in your config as git_tool
53
- --ticket-system "pivotal_tracker" # Optionally pass in your ticket system this can also be set in your config as ticket_tracking_tool
54
- --use-defaults "true" # use defaults instead of getting prompts if you don't want to edit your body or title
55
- --title "Pull Request Title" # Title you want to use with the pull request
56
- --body "Pull Request Body" # Body you want to use with the pull request
57
- ]
58
- ticket_information [ # Get the ticket information from a story based on ticket system configuration
59
- --use-defaults="true|false" # If you want to use defaults ticket_id is taken from branch_name otherwise configuration is used
60
- --clipboard="true|false" # Copy the output to the system clipboard (Mac OSx) tested
61
- --field="field_name" # The field you want to either output or copy to your clipboard
62
- --formatted-string="{name} - {url} # Pass a formatted string in ticket name and url and it will return that string replaced by the actual value
63
- ]
64
- create_pivotal_tracker_note # Create a note for a specific PivotalTracker story based on project_id and story_id
65
- update_pivotal_tracker_story_status # Update the status of PivotalTracker story
66
- create_branch [ # Create a branch default (git) and push it to your local repository
67
- --branch-name "123_test" # The branch name standard it [ticket_id]_description
68
- --branch-from "master" # What branch do you want to branch from
69
- ]
70
- checkout_branch [ # Checkout a branch [default git] and update the submodules if true
71
- --branch-name "123" # Branch name or part of the branch name you want to checkout
72
- ]
73
- push_branch [ # Push your current working branch to your own repository
74
- --force # Push your current working branch up with --force after
75
- --branch-name "another" # Push this specific branch up instead of your current working branch
76
- ]
77
- get_daily_time_update [ # Get a daily update from your time tracking toolset currently harvest is supported
78
- --format="html|text" # Format you want if you want html it will open html page in broswer otherwise puts out plain text
79
- --use-defaults="true|false" # If you want to use your default project_id instead of entering it
80
- --project-id="1234" # If you want to use a project id other than your defaults
81
- ]
82
- list_branches [ # List branches for your remote repository
83
- --repository-name "depot" # The repository name you want to list branches for if not passed pull_from_repository_name is used
84
- ]
85
- delete_branch [ # Delete a branch both locally and to your push to remote
86
- --branch-name "134_mybranch" | "134" # Either the full branch name or some unique string in the branch i.e. ticket id
87
- ]
88
- create_ticket_comment [ # Add a comment to a specific ticket
89
- --use-defaults "true" # use defaults instead of getting prompts if you don't want to supply project name
90
- ]
91
- update_ticket_status [ # Update a specific tickets status
92
- ]
93
- ssh [
94
- --use-sudo "true|false" # If you want the command to run under sudo i.e. sudo ssh ..
95
- --host "ip_address" # The host you want to connect to
96
- --connection-string-options "-p 4000" # A string of options that will be added onto the command
97
- --commands 'command1;command2' # A list of commands either a string array "["command1", "command2"]" or "command1;command2" or put string into toolshedrc file and call it "main_server_commands"
98
- --password "password1" # The password you are using to login to the server
99
- --prompt-for-password "true|false" # If you want to be more secure and just prompt for passwords
100
- --user "username" # The user you want to connect with
101
- --keys "path/to/file" # IdentityFile you want to use for authentication if passed no password will be asked
102
- --sudo-password "password1" # If you need to use sudo provide a sudo password this can be taken from toolshedrc file also
103
- --verbose-output "true|flase" # If you want to see commands being ran and other verbose output set this flag to true
104
- ]
105
- EOF
106
- end
107
-
108
- if $0.split("/").last == 'toolshed'
109
- options = {}
110
-
111
- global = OptionParser.new do |opts|
112
- opts.on("-u", "--github-username [ARG]") do |username|
113
- Toolshed::Client.github_username = username
114
- end
115
- opts.on("-p", "--github-password [ARG]") do |password|
116
- Toolshed::Client.github_password = password
117
- end
118
- opts.on("-t", "--github-token [ARG]") do |token|
119
- Toolshed::Client.github_token = token
120
- end
121
- opts.on("-u", "--pivotal-tracker-username [ARG]") do |username|
122
- Toolshed::Client.pivotal_tracker_username = username
123
- end
124
- opts.on("-p", "--pivotal-tracker-password [ARG]") do |password|
125
- Toolshed::Client.pivotal_tracker_password = password
126
- end
127
- opts.on("-d", "--debug [ARG]") do
128
- Toolshed::Client.debug = true
129
- end
130
- opts.on("-h", "--help", "Help") do
131
- usage
132
- end
133
- end
134
-
135
- subcommands = {
136
- 'create_pull_request' => OptionParser.new do |opts|
137
- opts.on("--tool [ARG]") do |opt|
138
- Toolshed::Client.git_tool = opt.downcase
139
- end
140
- opts.on("--ticket-system [ARG]") do |opt|
141
- Toolshed::Client.ticket_tracking_tool = opt.downcase
142
- end
143
- opts.on("--use-defaults [ARG]") do |opt|
144
- Toolshed::Client.use_defaults = opt
145
- end
146
- opts.on("--title [ARG]") do |opt|
147
- options[:title] = opt
148
- end
149
- opts.on("--body [ARG]") do |opt|
150
- options[:body] = opt
151
- end
152
- end,
153
- 'create_branch' => OptionParser.new do |opts|
154
- opts.on("--branch-name [ARG]") do |opt|
155
- options[:branch_name] = opt
156
- end
157
- opts.on("--branch-from [ARG]") do |opt|
158
- options[:branch_from] = opt
159
- end
160
- end,
161
- 'push_branch' => OptionParser.new do |opts|
162
- opts.on("--force [ARG]") do |opt|
163
- options[:force_command] = true
164
- end
165
- opts.on("--branch-name [ARG]") do |opt|
166
- options[:branch_name] = opt
167
- end
168
- end,
169
- 'list_branches' => OptionParser.new do |opts|
170
- opts.on("--repository-name [ARG]") do |opt|
171
- Toolshed::Client.pull_from_repository_name = opt
172
- end
173
- end,
174
- 'checkout_branch' => OptionParser.new do |opts|
175
- opts.on("--branch-name [ARG]") do |opt|
176
- options[:branch_name] = opt
177
- end
178
- end,
179
- 'delete_branch' => OptionParser.new do |opts|
180
- opts.on("--branch-name [ARG]") do |opt|
181
- options[:branch_name] = opt
182
- end
183
- end,
184
- 'get_daily_time_update' => OptionParser.new do |opts|
185
- opts.on("--format [ARG]") do |opt|
186
- options[:format] = opt
187
- end
188
- opts.on("--use-defaults [ARG]") do |opt|
189
- Toolshed::Client.use_defaults = opt
190
- end
191
- opts.on("--project-id [ARG]") do |opt|
192
- options[:project_id] = opt
193
- end
194
- end,
195
- 'ticket_information' => OptionParser.new do |opts|
196
- opts.on("--use-defaults [ARG]") do |opt|
197
- options[:use_defaults] = opt
198
- end
199
- opts.on("--clipboard [ARG]") do |opt|
200
- options[:clipboard] = opt
201
- end
202
- opts.on("--field [ARG]") do |opt|
203
- options[:field] = opt
204
- end
205
- opts.on("--formatted-string [ARG]") do |opt|
206
- options[:formatted_string] = opt
207
- end
208
- end,
209
- 'create_ticket_comment' => OptionParser.new do |opts|
210
- opts.on("--use-defaults [ARG]") do |opt|
211
- Toolshed::Client.use_defaults = opt
212
- end
213
- end,
214
- 'ssh' => OptionParser.new do |opts|
215
- opts.on("--use-sudo [ARG]") do |opt|
216
- options[:use_sudo] = opt
217
- end
218
- opts.on("--host [ARG]") do |opt|
219
- options[:host] = opt
220
- end
221
- opts.on("--connection-string-options [ARG]") do |opt|
222
- options[:connection_string_options] = opt
223
- end
224
- opts.on("--commands [ARG]") do |opt|
225
- options[:commands] = opt
226
- end
227
- opts.on("--password [ARG]") do |opt|
228
- options[:password] = opt
229
- end
230
- opts.on("--prompt-for-password [ARG]") do |opt|
231
- options[:prompt_for_password] = opt
232
- end
233
- opts.on("--user [ARG]") do |opt|
234
- options[:user] = opt
235
- end
236
- opts.on("--keys [ARG]") do |opt|
237
- options[:keys] = opt
238
- end
239
- opts.on("--sudo-password [ARG]") do |opt|
240
- options[:sudo_password] = opt
241
- end
242
- opts.on("--verbose-output [ARG]") do |opt|
243
- options[:verbose_output] = opt
244
- end
245
- end,
246
- }
247
-
248
- global.order!
249
- command = ARGV.shift
250
- if command.nil? || command == 'help'
251
- usage
252
- else
253
- options_parser = subcommands[command]
254
- options_parser.order! if options_parser
255
- begin
256
- cli.execute(command, ARGV, options)
257
- rescue Toolshed::CommandNotFound => e
258
- puts e.message
259
- end
260
- end
261
- end
@@ -1,119 +0,0 @@
1
- module Toolshed
2
- module Git
3
- DEFAULT_GIT_TOOL = 'github'
4
- DEFAULT_BRANCH_FROM = 'master'
5
-
6
- def branch_name
7
- # branch information
8
- branch_name = `git rev-parse --abbrev-ref HEAD`.strip
9
- end
10
-
11
- def branched_from
12
- branched_from = `git rev-parse --abbrev-ref --symbolic-full-name @{u}`.split('/')[-1].strip
13
- end
14
-
15
- def branch_name_from_id(id)
16
- branch_name = `git branch | grep \"#{id}\"`.gsub("*", "").strip
17
- end
18
-
19
- def checkout(branch_name)
20
- branch_name = Toolshed::Git::Base.branch_name_from_id(branch_name)
21
- Toolshed::Base.wait_for_command("git checkout #{branch_name} #{Toolshed::Client.git_quiet}")
22
-
23
- unless (Toolshed::Git::Base.git_submodule_command.empty?)
24
- Toolshed::Base.wait_for_command(Toolshed::Git::Base.git_submodule_command)
25
- end
26
-
27
- branch_name
28
- end
29
-
30
- def delete(branch_name)
31
- branch_name = Toolshed::Git::Base.branch_name_from_id(branch_name)
32
-
33
- # if delete your current branch checkout master so it can be deleted
34
- if (branch_name == Toolshed::Git::Base.branch_name)
35
- Toolshed::Git::Base.checkout('master')
36
- end
37
-
38
- Toolshed::Base.wait_for_command("git push #{Toolshed::Client.push_to_remote_name} :#{branch_name}; git branch -D #{branch_name}")
39
-
40
- branch_name
41
- end
42
-
43
- def git_submodule_command
44
- git_submodule_command = ''
45
- if (Toolshed::Client.use_git_submodules)
46
- git_submodule_command = "git submodule update #{Toolshed::Client.git_quiet}"
47
- end
48
-
49
- git_submodule_command
50
- end
51
-
52
- def clean_branch_name(branch_name)
53
- branch_name.strip.downcase.tr(" ", "_").gsub("&", "").gsub("/", "_").gsub(".", "_").gsub("'", "").gsub("__", "_").gsub(":", "").gsub(",", "")
54
- end
55
-
56
- def push(options = {})
57
- branch_name = (options.has_key?(:branch_name)) ? Toolshed::Git::Base.branch_name_from_id(options[:branch_name]) : Toolshed::Git::Base.branch_name
58
- force_command = (options.has_key?(:force_command)) ? '--force' : ''
59
-
60
- Toolshed::Base.wait_for_command("git push #{Toolshed::Client.push_to_remote_name} #{branch_name} #{force_command}")
61
-
62
- branch_name
63
- end
64
-
65
- class GitValidator
66
- include Veto.validator
67
-
68
- validates :from_remote_name, :presence => true
69
- validates :from_remote_branch_name, :presence => true
70
- validates :to_remote_name, :presence => true
71
- validates :to_remote_branch_name, :presence => true
72
- end
73
-
74
- class Base
75
- extend Toolshed::Git
76
-
77
- attr_accessor :from_remote_name, :from_remote_branch_name, :to_remote_name, :to_remote_branch_name, :validator
78
-
79
- def initialize(options={})
80
- # options with defaults
81
- self.from_remote_name = Toolshed::Client.pull_from_remote_name
82
- unless (options[:from_remote_name].nil?)
83
- self.from_remote_name = options[:from_remote_name]
84
- end
85
-
86
- self.to_remote_name = Toolshed::Client.push_to_remote_name
87
- unless (options[:to_remote_name].nil?)
88
- self.to_remote_name = options[:to_remote_name]
89
- end
90
-
91
- # options that do not have a default
92
- unless (options[:from_remote_branch_name].nil?)
93
- self.from_remote_branch_name = options[:from_remote_branch_name]
94
- end
95
-
96
- unless (options[:to_remote_branch_name].nil?)
97
- self.to_remote_branch_name = options[:to_remote_branch_name]
98
- end
99
-
100
- self.validator = ::Toolshed::Git::GitValidator.new
101
- end
102
-
103
- def create_branch
104
- self.validator.validate!(self)
105
-
106
- new_branch_name = Toolshed::Git::Base.clean_branch_name(self.to_remote_branch_name)
107
- Toolshed::Base.wait_for_command("git remote update #{Toolshed::Client.git_quiet}")
108
-
109
- Toolshed::Base.wait_for_command("git checkout -b #{new_branch_name} #{self.from_remote_name}/#{self.from_remote_branch_name} #{Toolshed::Client.git_quiet}")
110
-
111
- unless (Toolshed::Git::Base.git_submodule_command.empty?)
112
- Toolshed::Base.wait_for_command(Toolshed::Git::Base.git_submodule_command)
113
- end
114
-
115
- Toolshed::Base.wait_for_command("git push #{self.to_remote_name} #{new_branch_name} #{Toolshed::Client.git_quiet}")
116
- end
117
- end
118
- end
119
- end