pgit 0.0.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/.agignore +3 -0
  3. data/.travis.yml +1 -0
  4. data/README.markdown +32 -9
  5. data/Rakefile +12 -0
  6. data/bin/pgit +167 -25
  7. data/lib/pgit.rb +40 -10
  8. data/lib/pgit/bilateral/handle_back.rb +22 -0
  9. data/lib/pgit/bilateral/handle_choose_story.rb +31 -0
  10. data/lib/pgit/bilateral/story.rb +44 -0
  11. data/lib/pgit/command.rb +83 -0
  12. data/lib/pgit/command/add.rb +36 -0
  13. data/lib/pgit/command/application.rb +21 -0
  14. data/lib/pgit/command/edit.rb +36 -0
  15. data/lib/pgit/command/remove.rb +36 -0
  16. data/lib/pgit/command/run.rb +32 -0
  17. data/lib/pgit/command/show.rb +53 -0
  18. data/lib/pgit/configuration.rb +27 -3
  19. data/lib/pgit/current_project.rb +9 -45
  20. data/lib/pgit/current_project/validator.rb +2 -1
  21. data/lib/pgit/error/external.rb +11 -0
  22. data/lib/pgit/error/user.rb +12 -0
  23. data/lib/pgit/helpers/heredoc.rb +17 -0
  24. data/lib/pgit/helpers/query_methods.rb +63 -0
  25. data/lib/pgit/helpers/string_extensions.rb +29 -0
  26. data/lib/pgit/installer/bash_auto_completion.rb +57 -0
  27. data/lib/pgit/pivotal/collection_request.rb +21 -0
  28. data/lib/pgit/pivotal/individual_request.rb +47 -0
  29. data/lib/pgit/pivotal/iteration.rb +6 -0
  30. data/lib/pgit/pivotal/iterations.rb +15 -0
  31. data/lib/pgit/pivotal/project.rb +6 -0
  32. data/lib/pgit/pivotal/projects.rb +20 -0
  33. data/lib/pgit/pivotal/query.rb +8 -0
  34. data/lib/pgit/pivotal/request.rb +33 -0
  35. data/lib/pgit/pivotal/request/query.rb +25 -0
  36. data/lib/pgit/pivotal/story.rb +38 -0
  37. data/lib/pgit/pivotal_request_validator.rb +1 -1
  38. data/lib/pgit/project.rb +78 -0
  39. data/lib/pgit/project/add.rb +28 -0
  40. data/lib/pgit/project/application.rb +21 -0
  41. data/lib/pgit/project/interactive_adder.rb +41 -0
  42. data/lib/pgit/project/remove.rb +41 -0
  43. data/lib/pgit/project/reuse_api_token_adder.rb +48 -0
  44. data/lib/pgit/response_handler.rb +16 -0
  45. data/lib/pgit/root.rb +5 -0
  46. data/lib/pgit/status.rb +16 -0
  47. data/lib/pgit/story_branch/application.rb +3 -3
  48. data/lib/pgit/{name_parser.rb → story_branch/name_parser.rb} +0 -0
  49. data/lib/pgit/story_branch/story_id_parser.rb +11 -0
  50. data/lib/pgit/validators/project_validator.rb +20 -0
  51. data/lib/pgit/version.rb +1 -1
  52. data/lib/pivotal +0 -0
  53. data/pgit.gemspec +5 -0
  54. data/spec/fixtures/iterations +1 -0
  55. data/spec/pgit/bilateral/handle_back_spec.rb +29 -0
  56. data/spec/pgit/bilateral/handle_choose_story_spec.rb +17 -0
  57. data/spec/pgit/bilateral/story_spec.rb +178 -0
  58. data/spec/pgit/command/add_spec.rb +68 -0
  59. data/spec/pgit/command/application_spec.rb +110 -0
  60. data/spec/pgit/command/edit_spec.rb +61 -0
  61. data/spec/pgit/command/remove_spec.rb +76 -0
  62. data/spec/pgit/command/run_spec.rb +49 -0
  63. data/spec/pgit/command/show_spec.rb +95 -0
  64. data/spec/pgit/command_spec.rb +299 -0
  65. data/spec/pgit/configuration_spec.rb +121 -18
  66. data/spec/pgit/current_project/validator_spec.rb +2 -1
  67. data/spec/pgit/current_project_spec.rb +20 -71
  68. data/spec/pgit/{external_error_spec.rb → error/external_spec.rb} +3 -3
  69. data/spec/pgit/error/user_spec.rb +17 -0
  70. data/spec/pgit/helpers/heredoc_spec.rb +33 -0
  71. data/spec/pgit/helpers/query_methods_spec.rb +24 -0
  72. data/spec/pgit/helpers/string_extensions_spec.rb +49 -0
  73. data/spec/pgit/installer/bash_auto_completion_spec.rb +134 -0
  74. data/spec/pgit/pivotal/individual_request_spec.rb +32 -0
  75. data/spec/pgit/pivotal/iteration_spec.rb +19 -0
  76. data/spec/pgit/pivotal/iterations_spec.rb +37 -0
  77. data/spec/pgit/pivotal/project_spec.rb +9 -0
  78. data/spec/pgit/pivotal/projects_spec.rb +48 -0
  79. data/spec/pgit/pivotal/request/query_spec.rb +24 -0
  80. data/spec/pgit/pivotal/story_spec.rb +113 -0
  81. data/spec/pgit/pivotal_request_validator_spec.rb +3 -3
  82. data/spec/pgit/project/add_spec.rb +52 -0
  83. data/spec/pgit/project/application_spec.rb +69 -0
  84. data/spec/pgit/project/interactive_adder_spec.rb +45 -0
  85. data/spec/pgit/project/remove_spec.rb +86 -0
  86. data/spec/pgit/project/reuse_api_token_adder_spec.rb +41 -0
  87. data/spec/pgit/project_spec.rb +513 -0
  88. data/spec/pgit/status_spec.rb +40 -0
  89. data/spec/pgit/story_branch/application_spec.rb +5 -8
  90. data/spec/pgit/story_branch/name_parser_spec.rb +3 -3
  91. data/spec/pgit/story_branch/story_id_parser_spec.rb +17 -0
  92. data/spec/pgit/validators/project_validator_spec.rb +39 -0
  93. metadata +146 -21
  94. data/lib/pgit/configuration/layout_error.rb +0 -9
  95. data/lib/pgit/configuration/missing_attributes_error.rb +0 -10
  96. data/lib/pgit/configuration/not_found_error.rb +0 -10
  97. data/lib/pgit/configuration/project_missing_error.rb +0 -10
  98. data/lib/pgit/configuration/validator.rb +0 -41
  99. data/lib/pgit/current_project/no_paths_match_working_dir_error.rb +0 -10
  100. data/lib/pgit/external_error.rb +0 -9
  101. data/lib/pgit/installer/configuration.rb +0 -34
  102. data/lib/pgit/story.rb +0 -44
  103. data/spec/pgit/configuration/missing_attributes_error_spec.rb +0 -30
  104. data/spec/pgit/configuration/not_found_error_spec.rb +0 -17
  105. data/spec/pgit/configuration/project_missing_error_spec.rb +0 -30
  106. data/spec/pgit/configuration/validator_spec.rb +0 -79
  107. data/spec/pgit/current_project/no_paths_match_working_dir_error_spec.rb +0 -17
  108. data/spec/pgit/installer/configuration_spec.rb +0 -162
  109. data/spec/pgit/story_spec.rb +0 -35
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d736adc51cc2cda472f63edadcddd766f7ad22a2
4
- data.tar.gz: 2b7e43a567cb947507d4d1d1cd4c0704a02af14c
3
+ metadata.gz: c992ab6fde90207008812368d16901885da908e4
4
+ data.tar.gz: edb7562be4874a0c82f28e17cdd70734bce7d195
5
5
  SHA512:
6
- metadata.gz: 7c30a313b05b8940dc915c14f13c9e36621c7c876dd1b8121d23d16d0a7d2bc74d39062e1543184cb3fd5bf9f2bfdb7c39cb81184a42aa48f0a2cc4292a67a72
7
- data.tar.gz: e811579cab502fd70ed1dda709637222f42036e04fd8702636da4d99319236d27876a2bc44302adf9cb6b0d66a159bf1501e5c6a12183c5eab4170fa6c3e93e1
6
+ metadata.gz: e467a864a8d3f2afbb1918b17c2c7715bfa3a800ea892520c9464782bb894706bd012454d09e3b8bd77a4739c370312cbc06250015ee35b29919a7c001fb615e
7
+ data.tar.gz: 672584afd6286457f95837d4544180d94fa291a9e743420cd34b6bee1ef2cfa8a2c43ea62d8ca2b0e49a756fced144adbeae97a278abda4117a21602bcdab930
@@ -0,0 +1,3 @@
1
+ coverage
2
+ doc
3
+ pkg
@@ -3,4 +3,5 @@ rvm:
3
3
  - 2.1.2
4
4
  - 2.1.3
5
5
  - 2.1.5
6
+ - 2.2.0
6
7
  script: "bundle exec rake"
@@ -21,27 +21,50 @@ will create a branch for you named `implement-really-cool-feature-10102004`
21
21
 
22
22
  ## Installation
23
23
 
24
- * Install via RubyGems:
24
+ ### Install via RubyGems:
25
25
 
26
26
  ```
27
27
  $ gem install pgit
28
28
  ```
29
29
 
30
- * Setup configuration file:
31
-
30
+ ### Create autocompletion script and configuration file
32
31
  ```
33
32
  $ pgit install
34
33
  ```
35
34
 
36
- This will generate a YAML file under `~/.pgit.rc.yml`. Edit that file to add
37
- information about projects that you're working on. Each project needs a
38
- project `id`, Pivotal Tracker `api_token`, and `path`.
35
+ ### Add a project
36
+
37
+ The following will ask you questions as to which Pivotal Tracker project to associate to your working directory:
38
+
39
+ ```
40
+ $ pgit proj add
41
+ ```
42
+
43
+ ### Create a branch
44
+
45
+ Once your working directory is associated to a Pivotal Tracker project,
46
+ this will ask you which branch to create:
47
+
48
+ ```
49
+ $ pgit branch
50
+ ```
51
+
52
+ ### Add a command for deployment
39
53
 
40
- The `api_token` can be found here: https://www.pivotaltracker.com/profile
54
+ Do you want to automate the merging/rebasing process?
55
+ `STORY_BRANCH` is the memoized current branch.
41
56
 
42
- The project id is in the URL when visiting a project (i.e.
43
- https://pivotaltracker.com/projects/12345678)
57
+ ```
58
+ pgit cmd add --name="finish" --steps="git fetch origin master, git rebase origin/master, git checkout master, git merge STORY_BRANCH, git branch -d STORY_BRANCH, git push origin :STORY_BRANCH, git push origin master"
59
+ ```
60
+
61
+ You can run the steps of the command as follows:
62
+
63
+ ```
64
+ $ pgit cmd run finish
65
+ ```
44
66
 
45
67
 
46
68
  ## Development
69
+
47
70
  See https://www.pivotaltracker.com/n/projects/1228944 for information.
data/Rakefile CHANGED
@@ -18,3 +18,15 @@ desc 'Run specs'
18
18
  require 'rspec/core/rake_task'
19
19
  RSpec::Core::RakeTask.new
20
20
  task :default => [:spec]
21
+
22
+ namespace :spec do
23
+ RSpec::Core::RakeTask.new(:unit) do |t|
24
+ puts 'Running unit specs'
25
+ t.pattern = Dir['spec/pgit/**/*_spec.rb']
26
+ end
27
+
28
+ RSpec::Core::RakeTask.new(:integration) do |t|
29
+ puts 'Running integration specs'
30
+ t.pattern = Dir['spec/integration/**/*_spec.rb']
31
+ end
32
+ end
data/bin/pgit CHANGED
@@ -10,6 +10,13 @@ version Pgit::VERSION
10
10
  subcommand_option_handling :normal
11
11
  arguments :strict
12
12
 
13
+ desc "Color output"
14
+ default_value :true
15
+ switch :color
16
+
17
+ desc "Print backtrace if there is an exception"
18
+ switch :trace
19
+
13
20
  # desc 'Path to the config file'
14
21
  # default_value "#{ENV['HOME']}/.pgit.rc.yml"
15
22
  # arg_name '/path/to/.pivotal.yml'
@@ -21,11 +28,154 @@ arguments :strict
21
28
  # desc 'PivotalTracker API Token'
22
29
  # arg_name 'secr3tT0ken123'
23
30
  # flag [:'api-token']
31
+ desc "Work with projects"
32
+ command :proj do |p|
33
+
34
+ p.desc "add a project"
35
+ p.command :add do |a|
36
+
37
+ a.desc "the id associated to the Pivotal Tracker project"
38
+ a.arg_name '12030405'
39
+ a.flag :d, :id
40
+
41
+ a.desc "the filepath that is going to be associated to the Pivotal Tracker and Git project"
42
+ a.arg_name '"/some/file/path"'
43
+ a.default_value Dir.pwd
44
+ a.flag :p, :path
45
+
46
+ a.desc "your Pivotal Tracker API token"
47
+ a.arg_name "token"
48
+ a.flag :t, :api_token
49
+
50
+ a.action do |global_options,options,args|
51
+ app = PGit::Project::Application.new(global_options, options, args)
52
+ add = PGit::Project::Add.new(app)
53
+ add.execute!
54
+ end
55
+ end
56
+
57
+ p.desc "remove a project"
58
+ p.command :rm do |a|
59
+
60
+ a.desc "the path whose pgit project will be removed"
61
+ a.arg_name '"/some/file/path"'
62
+ a.default_value Dir.pwd
63
+ a.flag :p, :path
64
+
65
+ a.action do |global_options,options,args|
66
+ app = PGit::Project::Application.new(global_options, options, args)
67
+ rm = PGit::Project::Remove.new(app)
68
+ rm.execute!
69
+ end
70
+ end
71
+ end
72
+
73
+ desc "Work with custom commands defined in the current project"
74
+ command :cmd do |c|
75
+ c.desc "show the custom command(s)"
76
+ c.arg_name 'command_name'
77
+ c.command :show do |s|
78
+ s.action do |global_options,options,args|
79
+ app = PGit::Command::Application.new(global_options,
80
+ options,
81
+ args)
82
+
83
+ show = PGit::Command::Show.new(app)
84
+ show.execute!
85
+ end
86
+ end
87
+
88
+ c.desc "run a command"
89
+ c.arg_name 'command_name'
90
+ c.command :run do |r|
91
+ r.action do |global_options,options,args|
92
+ app = PGit::Command::Application.new(global_options,
93
+ options,
94
+ args)
95
+ run = PGit::Command::Run.new(app)
96
+ run.execute!
97
+ end
98
+ end
99
+
100
+ c.desc "add a command"
101
+ c.command :add do |a|
102
+ accept(Array) do |value|
103
+ value.split(',').map {|item| item.strip }
104
+ end
105
+ a.desc "name of the command"
106
+ a.arg_name "new_command_name"
107
+ a.flag :n, :name, required: true
108
+
109
+ a.desc "steps of the command, delimited by commas"
110
+ a.arg_name "steps"
111
+ a.flag :s, :steps, required: true, type: Array
112
+
113
+ a.action do |global_options,options,args|
114
+ app = PGit::Command::Application.new(global_options,
115
+ options,
116
+ args)
117
+ add = PGit::Command::Add.new(app)
118
+ add.execute!
119
+ end
120
+ end
121
+
122
+ c.desc "edit a command"
123
+ c.command :edit do |a|
124
+ accept(Array) do |value|
125
+ value.split(',').map {|item| item.strip }
126
+ end
127
+ a.desc "name of the command"
128
+ a.arg_name "new_command_name"
129
+ a.flag :n, :name, required: true
130
+
131
+ a.desc "steps of the command, delimited by commas"
132
+ a.arg_name "steps"
133
+ a.flag :s, :steps, required: true, type: Array
134
+
135
+ a.action do |global_options,options,args|
136
+ app = PGit::Command::Application.new(global_options,
137
+ options,
138
+ args)
139
+ edit = PGit::Command::Edit.new(app)
140
+ edit.execute!
141
+ end
142
+ end
143
+
144
+ c.desc "remove a command"
145
+ c.command :rm do |a|
146
+ accept(Array) do |value|
147
+ value.split(',').map {|item| item.strip }
148
+ end
149
+ a.desc "name of the command"
150
+ a.arg_name "new_command_name"
151
+ a.flag :n, :name, required: true
152
+
153
+ a.action do |global_options,options,args|
154
+ app = PGit::Command::Application.new(global_options,
155
+ options,
156
+ args)
157
+ remove = PGit::Command::Remove.new(app)
158
+ remove.execute!
159
+ end
160
+ end
161
+ end
162
+
163
+ desc "Show the status of the story being worked on"
164
+ command :status do |c|
165
+ c.action do |global_options,options,args|
166
+ status = PGit::Status.new(global_options,options,args)
167
+ status.execute!
168
+ end
169
+ end
24
170
 
25
171
  desc "Installs the pgit configuration file"
26
172
  command :install do |c|
27
173
  c.action do |global_options,options,args|
28
- PGit::Installer::Configuration.new(global_options, options, args)
174
+ completer = PGit::Installer::BashAutoCompletion.new(global_options,
175
+ options,
176
+ args)
177
+ completer.write_completer_file
178
+ completer.source_completer_from_bashrc
29
179
  end
30
180
  end
31
181
 
@@ -41,44 +191,34 @@ command :story_branch do |c|
41
191
  c.arg_name 'STORY_ID'
42
192
  c.flag :s, :start
43
193
 
44
- # c.desc "Merge back to staging, remove local and remote (origin?) branches"
45
- # c.switch :f, :finish
46
-
47
- # c.desc "Attempts to join the story-branch that, presumably, already exists"
48
- # c.arg_name 'STORY_ID'
49
- # c.flag :j, :join
50
-
51
194
  c.action do |global_options,options,args|
52
195
  PGit::StoryBranch::Application.new(global_options, options, args)
53
196
  end
54
197
  end
55
198
 
56
- # desc 'Wraps `git commit -m` and prepends the message with story id of the branch'
57
-
58
- # command :commit do |c|
59
- # arg_name 'Describe arguments to commit here'
60
- # c.action do |global_options,options,args|
61
- # puts "commit command ran"
62
- # end
63
- # end
64
-
199
+ desc 'Deal with iterations'
65
200
 
201
+ command :branch do |c|
202
+ c.desc "The scope of the iteration. Valid scopes are 'current', 'current_backlog', 'backlog', and 'done'"
203
+ c.default_value :current_backlog
204
+ c.flag :s, :scope
205
+ c.action do |global_options,options,args|
206
+ bilateral_story = PGit::Bilateral::Story.new(options)
207
+ bilateral_story.execute!
208
+ end
209
+ end
66
210
  desc 'Initializes configuration file'
67
-
68
211
  arg_name 'path/to/config_file'
69
212
 
70
- # command :init_config do |c|
71
- # c.action do |global_options,options,args|
72
- # puts "init_config command ran"
73
- # end
74
- # end
75
-
76
213
  pre do |global,command,options,args|
77
214
  # Pre logic here
78
215
  # Return true to proceed; false to abort and not call the
79
216
  # chosen command
80
217
  # Use skips_pre before a command to skip this block
81
218
  # on that command only
219
+ # $trace = true if global.fetch(:trace)
220
+ $trace = true if global.fetch(:trace)
221
+ Rainbow.enabled = global.fetch(:color)
82
222
  true
83
223
  end
84
224
 
@@ -91,7 +231,9 @@ end
91
231
  on_error do |exception|
92
232
  # Error logic here
93
233
  # return false to skip default error handling
94
- true
234
+ warn Rainbow("error: #{exception}").color(:red)
235
+ exception.backtrace.each { |e| warn Rainbow(e).color(:red) } if $trace
236
+ exit 1
95
237
  end
96
238
 
97
239
  exit run(ARGV)
@@ -1,22 +1,52 @@
1
1
  require 'json'
2
+ require 'rainbow'
3
+ require 'interactive'
4
+ require 'active_model'
5
+ require 'pgit/root.rb'
6
+ require 'pgit/validators/project_validator'
7
+ require 'pgit/pivotal/request'
8
+ require 'pgit/pivotal/request/query'
9
+ require 'pgit/pivotal/collection_request'
10
+ require 'pgit/pivotal/individual_request'
11
+ require 'pgit/helpers/string_extensions'
12
+ require 'pgit/helpers/heredoc'
13
+ require 'pgit/helpers/query_methods'
14
+ require 'pgit/response_handler'
15
+ require 'pgit/bilateral/handle_back'
16
+ require 'pgit/bilateral/handle_choose_story'
17
+ require 'pgit/bilateral/story'
2
18
  require 'pgit/error'
3
- require 'pgit/configuration/layout_error'
4
- require 'pgit/configuration/not_found_error'
5
- require 'pgit/configuration/project_missing_error'
6
- require 'pgit/configuration/missing_attributes_error'
7
- require 'pgit/configuration/validator'
19
+ require 'pgit/error/user'
20
+ require 'pgit/error/external'
8
21
  require 'pgit/configuration'
22
+ require 'pgit/command'
23
+ require 'pgit/command/application'
24
+ require 'pgit/command/add'
25
+ require 'pgit/command/edit'
26
+ require 'pgit/command/remove'
27
+ require 'pgit/command/run'
28
+ require 'pgit/command/show'
9
29
  require 'pgit/current_branch'
10
- require 'pgit/current_project/no_paths_match_working_dir_error'
30
+ require 'pgit/project'
31
+ require 'pgit/project/application'
32
+ require 'pgit/project/reuse_api_token_adder'
33
+ require 'pgit/project/interactive_adder'
34
+ require 'pgit/project/add'
35
+ require 'pgit/project/remove'
36
+ require 'pgit/pivotal/story'
37
+ require 'pgit/pivotal/iteration'
38
+ require 'pgit/pivotal/iterations'
39
+ require 'pgit/pivotal/project'
40
+ require 'pgit/pivotal/projects'
11
41
  require 'pgit/current_project/validator'
12
42
  require 'pgit/current_project'
13
- require 'pgit/installer/configuration'
14
- require 'pgit/name_parser'
43
+ require 'pgit/installer/bash_auto_completion'
15
44
  require 'pgit/pivotal_request_validator'
16
- require 'pgit/external_error'
17
- require 'pgit/story'
18
45
  require 'pgit/story_branch'
46
+ require 'pgit/story_branch/name_parser'
47
+ require 'pgit/story_branch/story_id_parser'
19
48
  require 'pgit/story_branch/application'
49
+ require 'pgit/status'
20
50
  require 'pgit/version.rb'
21
51
  require 'yaml'
22
52
 
@@ -0,0 +1,22 @@
1
+ module PGit
2
+ module Bilateral
3
+ class HandleBack
4
+ def initialize(options)
5
+ @parent_question = options.fetch(:parent_question)
6
+ @response = options.fetch(:response)
7
+ end
8
+
9
+ def execute!
10
+ if response_can_be_handled?
11
+ @parent_question.reask!
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def response_can_be_handled?
18
+ @response.back?
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,31 @@
1
+ require 'pgit'
2
+
3
+ module PGit
4
+ module Bilateral
5
+ class HandleChooseStory < ResponseHandler
6
+ def initialize(options)
7
+ @response = options.fetch(:response)
8
+ @stories = options.fetch(:stories)
9
+ @response_handlers = [PGit::Bilateral::HandleBack]
10
+ name_parser = PGit::StoryBranch::NameParser.new(chosen_story)
11
+ story_branch = PGit::StoryBranch.new(name_parser)
12
+
13
+ story_branch.start
14
+ end
15
+
16
+ private
17
+
18
+ def chosen_story
19
+ @stories[@response.to_i]
20
+ end
21
+
22
+ def options(new_response)
23
+ { response: new_response, stories: @stories, parent_question: @parent_question }
24
+ end
25
+
26
+ def response_can_be_handled?
27
+ false
28
+ end
29
+ end
30
+ end
31
+ end