git-pivotal 0.2.3 → 0.8.0

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.
Files changed (71) hide show
  1. data/.gitignore +2 -0
  2. data/CHANGELOG +9 -1
  3. data/Rakefile +23 -10
  4. data/VERSION +1 -1
  5. data/bin/git-bug +0 -1
  6. data/bin/git-chore +0 -1
  7. data/bin/git-feature +0 -1
  8. data/bin/git-finish +0 -1
  9. data/bin/git-info +7 -0
  10. data/bin/git-pick +0 -1
  11. data/features/bug.feature +9 -0
  12. data/features/chore.feature +22 -0
  13. data/features/feature.feature +37 -0
  14. data/features/finish.feature +79 -0
  15. data/features/info.feature +39 -0
  16. data/features/step_definitions/steps.rb +18 -0
  17. data/features/support/env.rb +5 -0
  18. data/features/support/git-pivotal.rb +47 -0
  19. data/features/test_repo/readme +1 -0
  20. data/features/test_repo/working.git/COMMIT_EDITMSG +1 -0
  21. data/features/test_repo/working.git/HEAD +1 -0
  22. data/features/test_repo/working.git/config +8 -0
  23. data/features/test_repo/working.git/description +1 -0
  24. data/features/test_repo/working.git/hooks/applypatch-msg.sample +15 -0
  25. data/features/test_repo/working.git/hooks/commit-msg.sample +24 -0
  26. data/features/test_repo/working.git/hooks/post-commit.sample +8 -0
  27. data/features/test_repo/working.git/hooks/post-receive.sample +15 -0
  28. data/features/test_repo/working.git/hooks/post-update.sample +8 -0
  29. data/features/test_repo/working.git/hooks/pre-applypatch.sample +14 -0
  30. data/features/test_repo/working.git/hooks/pre-commit.sample +46 -0
  31. data/features/test_repo/working.git/hooks/pre-rebase.sample +169 -0
  32. data/features/test_repo/working.git/hooks/prepare-commit-msg.sample +36 -0
  33. data/features/test_repo/working.git/hooks/update.sample +128 -0
  34. data/features/test_repo/working.git/index +0 -0
  35. data/features/test_repo/working.git/info/exclude +6 -0
  36. data/features/test_repo/working.git/logs/HEAD +1 -0
  37. data/features/test_repo/working.git/logs/refs/heads/master +1 -0
  38. data/features/test_repo/working.git/objects/0c/6f7b1384910d1a2f137590095f008a06c7e00c +0 -0
  39. data/features/test_repo/working.git/objects/10/ecf2b7ce989f01f3f7266e712b48d9275f2635 +0 -0
  40. data/features/test_repo/working.git/objects/a5/71d56305df09fb060f6ccb730b46080d305beb +0 -0
  41. data/features/test_repo/working.git/refs/heads/master +1 -0
  42. data/git-pivotal.gemspec +49 -38
  43. data/lib/commands/base.rb +19 -9
  44. data/lib/commands/finish.rb +12 -9
  45. data/lib/commands/info.rb +31 -0
  46. data/lib/commands/pick.rb +26 -22
  47. data/lib/git-pivotal.rb +9 -0
  48. data/readme.markdown +13 -0
  49. data/spec/commands/base_spec.rb +20 -1
  50. data/spec/commands/bug_spec.rb +0 -1
  51. data/spec/commands/chore_spec.rb +0 -1
  52. data/spec/commands/feature_spec.rb +0 -1
  53. data/spec/commands/finish_spec.rb +1 -2
  54. data/spec/spec_helper.rb +4 -8
  55. metadata +61 -52
  56. data/lib/pivotal/api.rb +0 -17
  57. data/lib/pivotal/associations.rb +0 -17
  58. data/lib/pivotal/attributes.rb +0 -25
  59. data/lib/pivotal/base.rb +0 -73
  60. data/lib/pivotal/collection.rb +0 -63
  61. data/lib/pivotal/project.rb +0 -14
  62. data/lib/pivotal/story.rb +0 -44
  63. data/lib/pivotal.rb +0 -8
  64. data/spec/pivotal/api_spec.rb +0 -18
  65. data/spec/pivotal/associations_spec.rb +0 -13
  66. data/spec/pivotal/attributes_spec.rb +0 -31
  67. data/spec/pivotal/base_spec.rb +0 -77
  68. data/spec/pivotal/collection_spec.rb +0 -25
  69. data/spec/pivotal/project_spec.rb +0 -34
  70. data/spec/pivotal/story_spec.rb +0 -113
  71. data/spec/spec.opts +0 -1
data/lib/commands/pick.rb CHANGED
@@ -2,57 +2,61 @@ require 'commands/base'
2
2
 
3
3
  module Commands
4
4
  class Pick < Base
5
-
5
+
6
6
  def type
7
7
  raise Error("must define in subclass")
8
8
  end
9
-
9
+
10
10
  def plural_type
11
11
  raise Error("must define in subclass")
12
12
  end
13
-
13
+
14
14
  def branch_suffix
15
15
  raise Error("must define in subclass")
16
16
  end
17
-
17
+
18
18
  def run!
19
- super
19
+ response = super
20
+ return response if response > 0
20
21
 
21
22
  msg = "Retrieving latest #{plural_type} from Pivotal Tracker"
22
23
  if options[:only_mine]
23
24
  msg += " for #{options[:full_name]}"
24
25
  end
25
26
  put "#{msg}..."
26
-
27
+
27
28
  unless story
28
29
  put "No #{plural_type} available!"
29
30
  return 0
30
31
  end
31
-
32
+
32
33
  put "Story: #{story.name}"
33
34
  put "URL: #{story.url}"
34
35
 
35
36
  put "Updating #{type} status in Pivotal Tracker..."
36
- if story.start!(:owned_by => options[:full_name])
37
-
38
- suffix = branch_suffix
39
- unless options[:quiet]
40
- put "Enter branch name (will be prepended by #{story.id}) [#{suffix}]: ", false
41
- suffix = input.gets.chomp
42
-
43
- suffix = "feature" if suffix == ""
37
+ if story.update(:owned_by => options[:full_name], :current_state => :started)
38
+
39
+ suffix_or_prefix = ""
40
+ unless options[:quiet] || options[:defaults]
41
+ put "Enter branch name (will be #{options[:append_name] ? 'appended' : 'prepended'} by #{story.id}) [#{suffix_or_prefix}]: ", false
42
+ suffix_or_prefix = input.gets.chomp
44
43
  end
44
+ suffix_or_prefix = branch_suffix if suffix_or_prefix == ""
45
45
 
46
- branch = "#{story.id}-#{suffix}"
46
+ if options[:append_name]
47
+ branch = "#{suffix_or_prefix}-#{story.id}"
48
+ else
49
+ branch = "#{story.id}-#{suffix_or_prefix}"
50
+ end
47
51
  if get("git branch").match(branch).nil?
48
- put "Creating #{branch} branch..."
52
+ put "Switched to a new branch '#{branch}'"
49
53
  sys "git checkout -b #{branch}"
50
54
  end
51
-
55
+
52
56
  return 0
53
57
  else
54
58
  put "Unable to mark #{type} as started"
55
-
59
+
56
60
  return 1
57
61
  end
58
62
  end
@@ -61,10 +65,10 @@ module Commands
61
65
 
62
66
  def story
63
67
  return @story if @story
64
-
65
- conditions = { :story_type => type, :current_state => :unstarted }
68
+
69
+ conditions = { :story_type => type, :current_state => "unstarted", :limit => 1, :offset => 0 }
66
70
  conditions[:owned_by] = options[:full_name] if options[:only_mine]
67
- @story = project.stories.find(:conditions => conditions, :limit => 1).first
71
+ @story = project.stories.all(conditions).first
68
72
  end
69
73
  end
70
74
  end
@@ -0,0 +1,9 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+
3
+ require File.join('commands', 'base')
4
+ require File.join('commands', 'pick')
5
+ require File.join('commands', 'feature')
6
+ require File.join('commands', 'bug')
7
+ require File.join('commands', 'chore')
8
+ require File.join('commands', 'finish')
9
+ require File.join('commands', 'info')
data/readme.markdown CHANGED
@@ -27,6 +27,15 @@ When on a feature branch, this command will close the associated story in Pivota
27
27
  Removing 1234567-testing branch
28
28
  4 git-pivotal:master %
29
29
 
30
+ ###Git Info
31
+ When on a feature/bug/chore branch, this command will display the story information as recorded in Pivotal Tracker.
32
+
33
+ 5 git-pivotal:1234567-testing % git info
34
+ Story: Test git pivotal
35
+ URL: http://www.pivotaltracker.com/story/show/1234567
36
+ Description: The awesome story description
37
+ 6 git-pivotal:1234567-testing %
38
+
30
39
  ##Installation
31
40
  To install git-pivotal, simply run
32
41
 
@@ -50,6 +59,10 @@ The project id is best placed within your project's git config:
50
59
 
51
60
  git config -f .git/config pivotal.project-id 88888
52
61
 
62
+ If you would rather have the story id appended to the branch name (feature-123456) instead of prepending (123456-feature), you can configue that:
63
+
64
+ git config -f .git/config pivotal.append-name true
65
+
53
66
  If you're not interested in storing these options in git, you can pass them into git pivotal as command line arguments. See the usage guides for more details.
54
67
 
55
68
  ##TODO
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'commands/base'
3
2
 
4
3
  describe Commands::Base do
5
4
 
@@ -101,4 +100,24 @@ describe Commands::Base do
101
100
  @pick.run!
102
101
  end
103
102
 
103
+ it "should set the append name flag with the -a option" do
104
+ @pick = Commands::Base.new(@input, @output,"-a")
105
+ @pick.options[:append_name].should be_true
106
+ end
107
+
108
+ it "should set the append name flag from git config" do
109
+ Commands::Base.any_instance.stubs(:get).with("git config --get pivotal.append-name").returns("true")
110
+ @pick = Commands::Base.new
111
+ @pick.options[:append_name].should be_true
112
+ end
113
+
114
+ it "should set the append name flag with the --append-name" do
115
+ @pick = Commands::Base.new(@input, @output, "--append-name")
116
+ @pick.options[:append_name].should be_true
117
+ end
118
+
119
+ it "should default the append name flag if none is specified" do
120
+ @pick = Commands::Base.new
121
+ @pick.options[:append_name].should be_false
122
+ end
104
123
  end
@@ -1,4 +1,3 @@
1
- require 'commands/bug'
2
1
  require 'spec_helper'
3
2
 
4
3
  describe Commands::Bug do
@@ -1,4 +1,3 @@
1
- require 'commands/chore'
2
1
  require 'spec_helper'
3
2
 
4
3
  describe Commands::Chore do
@@ -1,4 +1,3 @@
1
- require 'commands/feature'
2
1
  require 'spec_helper'
3
2
 
4
3
  describe Commands::Feature do
@@ -1,4 +1,3 @@
1
- require 'commands/finish'
2
1
  require 'spec_helper'
3
2
 
4
3
  describe Commands::Finish do
@@ -46,7 +45,7 @@ describe Commands::Finish do
46
45
  # stub out git config requests
47
46
  Commands::Finish.any_instance.stubs(:get).with { |v| v =~ /git config/ }.returns("")
48
47
 
49
- Pivotal::Api.any_instance.stubs(:projects).returns(mock_projects)
48
+ PivotalTracker::Project.stubs(:find).returns(mock_projects)
50
49
 
51
50
  @finish = Commands::Finish.new(nil, nil, "-p", mock_project_id)
52
51
  @finish.stubs(:sys)
data/spec/spec_helper.rb CHANGED
@@ -1,18 +1,14 @@
1
- require 'rubygems'
1
+ require 'rspec'
2
2
  require 'mocha'
3
3
  require 'builder'
4
- require 'pivotal'
4
+ require 'lib/git-pivotal'
5
+
5
6
  require File.join(File.dirname(__FILE__), 'factories')
6
7
 
7
- Spec::Runner.configure do |config|
8
+ RSpec.configure do |config|
8
9
  config.mock_with :mocha
9
10
  end
10
11
 
11
12
  def stub_connection_to_pivotal
12
13
  RestClient::Resource.any_instance.stubs(:get).returns("")
13
- end
14
-
15
- def pivotal_api
16
- stub_connection_to_pivotal
17
- Pivotal::Api.new :api_token => 1
18
14
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-pivotal
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
- - 2
9
- - 3
10
- version: 0.2.3
7
+ - 8
8
+ - 0
9
+ version: 0.8.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Jeff Tucker
@@ -16,93 +15,93 @@ autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2010-07-23 00:00:00 -04:00
18
+ date: 2011-04-10 00:00:00 -04:00
20
19
  default_executable:
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
23
- name: nokogiri
22
+ name: builder
24
23
  prerelease: false
25
24
  requirement: &id001 !ruby/object:Gem::Requirement
26
25
  none: false
27
26
  requirements:
28
27
  - - ">="
29
28
  - !ruby/object:Gem::Version
30
- hash: 3
31
29
  segments:
32
30
  - 0
33
31
  version: "0"
34
32
  type: :runtime
35
33
  version_requirements: *id001
36
34
  - !ruby/object:Gem::Dependency
37
- name: rest-client
35
+ name: pivotal-tracker
38
36
  prerelease: false
39
37
  requirement: &id002 !ruby/object:Gem::Requirement
40
38
  none: false
41
39
  requirements:
42
40
  - - ~>
43
41
  - !ruby/object:Gem::Version
44
- hash: 7
45
42
  segments:
46
- - 1
47
- - 4
48
43
  - 0
49
- version: 1.4.0
44
+ - 3
45
+ - 1
46
+ version: 0.3.1
50
47
  type: :runtime
51
48
  version_requirements: *id002
52
49
  - !ruby/object:Gem::Dependency
53
- name: builder
50
+ name: rspec
54
51
  prerelease: false
55
52
  requirement: &id003 !ruby/object:Gem::Requirement
56
53
  none: false
57
54
  requirements:
58
- - - ">="
55
+ - - ~>
59
56
  - !ruby/object:Gem::Version
60
- hash: 3
61
57
  segments:
58
+ - 2
59
+ - 5
62
60
  - 0
63
- version: "0"
64
- type: :runtime
61
+ version: 2.5.0
62
+ type: :development
65
63
  version_requirements: *id003
66
64
  - !ruby/object:Gem::Dependency
67
- name: rspec
65
+ name: rcov
68
66
  prerelease: false
69
67
  requirement: &id004 !ruby/object:Gem::Requirement
70
68
  none: false
71
69
  requirements:
72
70
  - - ">="
73
71
  - !ruby/object:Gem::Version
74
- hash: 3
75
72
  segments:
76
73
  - 0
77
74
  version: "0"
78
75
  type: :development
79
76
  version_requirements: *id004
80
77
  - !ruby/object:Gem::Dependency
81
- name: rcov
78
+ name: cucumber
82
79
  prerelease: false
83
80
  requirement: &id005 !ruby/object:Gem::Requirement
84
81
  none: false
85
82
  requirements:
86
- - - ">="
83
+ - - ~>
87
84
  - !ruby/object:Gem::Version
88
- hash: 3
89
85
  segments:
90
86
  - 0
91
- version: "0"
87
+ - 9
88
+ - 2
89
+ version: 0.9.2
92
90
  type: :development
93
91
  version_requirements: *id005
94
92
  - !ruby/object:Gem::Dependency
95
- name: mocha
93
+ name: aruba
96
94
  prerelease: false
97
95
  requirement: &id006 !ruby/object:Gem::Requirement
98
96
  none: false
99
97
  requirements:
100
- - - ">="
98
+ - - ~>
101
99
  - !ruby/object:Gem::Version
102
- hash: 3
103
100
  segments:
104
101
  - 0
105
- version: "0"
102
+ - 2
103
+ - 3
104
+ version: 0.2.3
106
105
  type: :development
107
106
  version_requirements: *id006
108
107
  description: A collection of git utilities to ease integration with Pivotal Tracker
@@ -112,6 +111,7 @@ executables:
112
111
  - git-chore
113
112
  - git-feature
114
113
  - git-finish
114
+ - git-info
115
115
  - git-pick
116
116
  extensions: []
117
117
 
@@ -127,22 +127,48 @@ files:
127
127
  - bin/git-chore
128
128
  - bin/git-feature
129
129
  - bin/git-finish
130
+ - bin/git-info
130
131
  - bin/git-pick
132
+ - features/bug.feature
133
+ - features/chore.feature
134
+ - features/feature.feature
135
+ - features/finish.feature
136
+ - features/info.feature
137
+ - features/step_definitions/steps.rb
138
+ - features/support/env.rb
139
+ - features/support/git-pivotal.rb
140
+ - features/test_repo/readme
141
+ - features/test_repo/working.git/COMMIT_EDITMSG
142
+ - features/test_repo/working.git/HEAD
143
+ - features/test_repo/working.git/config
144
+ - features/test_repo/working.git/description
145
+ - features/test_repo/working.git/hooks/applypatch-msg.sample
146
+ - features/test_repo/working.git/hooks/commit-msg.sample
147
+ - features/test_repo/working.git/hooks/post-commit.sample
148
+ - features/test_repo/working.git/hooks/post-receive.sample
149
+ - features/test_repo/working.git/hooks/post-update.sample
150
+ - features/test_repo/working.git/hooks/pre-applypatch.sample
151
+ - features/test_repo/working.git/hooks/pre-commit.sample
152
+ - features/test_repo/working.git/hooks/pre-rebase.sample
153
+ - features/test_repo/working.git/hooks/prepare-commit-msg.sample
154
+ - features/test_repo/working.git/hooks/update.sample
155
+ - features/test_repo/working.git/index
156
+ - features/test_repo/working.git/info/exclude
157
+ - features/test_repo/working.git/logs/HEAD
158
+ - features/test_repo/working.git/logs/refs/heads/master
159
+ - features/test_repo/working.git/objects/0c/6f7b1384910d1a2f137590095f008a06c7e00c
160
+ - features/test_repo/working.git/objects/10/ecf2b7ce989f01f3f7266e712b48d9275f2635
161
+ - features/test_repo/working.git/objects/a5/71d56305df09fb060f6ccb730b46080d305beb
162
+ - features/test_repo/working.git/refs/heads/master
131
163
  - git-pivotal.gemspec
132
164
  - lib/commands/base.rb
133
165
  - lib/commands/bug.rb
134
166
  - lib/commands/chore.rb
135
167
  - lib/commands/feature.rb
136
168
  - lib/commands/finish.rb
169
+ - lib/commands/info.rb
137
170
  - lib/commands/pick.rb
138
- - lib/pivotal.rb
139
- - lib/pivotal/api.rb
140
- - lib/pivotal/associations.rb
141
- - lib/pivotal/attributes.rb
142
- - lib/pivotal/base.rb
143
- - lib/pivotal/collection.rb
144
- - lib/pivotal/project.rb
145
- - lib/pivotal/story.rb
171
+ - lib/git-pivotal.rb
146
172
  - readme.markdown
147
173
  - spec/commands/base_spec.rb
148
174
  - spec/commands/bug_spec.rb
@@ -151,14 +177,6 @@ files:
151
177
  - spec/commands/finish_spec.rb
152
178
  - spec/factories.rb
153
179
  - spec/factory.rb
154
- - spec/pivotal/api_spec.rb
155
- - spec/pivotal/associations_spec.rb
156
- - spec/pivotal/attributes_spec.rb
157
- - spec/pivotal/base_spec.rb
158
- - spec/pivotal/collection_spec.rb
159
- - spec/pivotal/project_spec.rb
160
- - spec/pivotal/story_spec.rb
161
- - spec/spec.opts
162
180
  - spec/spec_helper.rb
163
181
  has_rdoc: true
164
182
  homepage: http://github.com/trydionel/git-pivotal
@@ -174,7 +192,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
174
192
  requirements:
175
193
  - - ">="
176
194
  - !ruby/object:Gem::Version
177
- hash: 3
178
195
  segments:
179
196
  - 0
180
197
  version: "0"
@@ -183,7 +200,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
200
  requirements:
184
201
  - - ">="
185
202
  - !ruby/object:Gem::Version
186
- hash: 3
187
203
  segments:
188
204
  - 0
189
205
  version: "0"
@@ -202,11 +218,4 @@ test_files:
202
218
  - spec/commands/finish_spec.rb
203
219
  - spec/factories.rb
204
220
  - spec/factory.rb
205
- - spec/pivotal/api_spec.rb
206
- - spec/pivotal/associations_spec.rb
207
- - spec/pivotal/attributes_spec.rb
208
- - spec/pivotal/base_spec.rb
209
- - spec/pivotal/collection_spec.rb
210
- - spec/pivotal/project_spec.rb
211
- - spec/pivotal/story_spec.rb
212
221
  - spec/spec_helper.rb
data/lib/pivotal/api.rb DELETED
@@ -1,17 +0,0 @@
1
- module Pivotal
2
- class Api < Base
3
-
4
- attr_accessor :api_token
5
- has_collection :projects, :of => Pivotal::Project
6
-
7
- def initialize(options = {})
8
- super(options)
9
- @api_url = "https://www.pivotaltracker.com/services/v3"
10
- end
11
-
12
- def resource
13
- @resource ||= RestClient::Resource.new @api_url, :headers => { 'X-TrackerToken' => api_token, 'Content-Type' => 'application/xml' }
14
- end
15
-
16
- end
17
- end
@@ -1,17 +0,0 @@
1
- module Pivotal
2
- module Associations
3
-
4
- def self.included(base)
5
- base.extend ClassMethods
6
- end
7
-
8
- module ClassMethods
9
- def has_collection(name, options = {})
10
- define_method name do
11
- Pivotal::Collection.new resource[name], options[:of]
12
- end
13
- end
14
- end
15
-
16
- end
17
- end
@@ -1,25 +0,0 @@
1
- module Pivotal
2
- module Attributes
3
-
4
- def self.included(base)
5
- base.extend ClassMethods
6
-
7
- class << base
8
- attr_accessor :attributes
9
- end
10
- end
11
-
12
- module ClassMethods
13
- def has_attributes(*attributes)
14
- @attributes = attributes.map { |attribute| attribute.to_s }
15
-
16
- attributes.each do |attribute|
17
- define_method attribute do
18
- parsed_resource.xpath("*/" + attribute.to_s).text
19
- end
20
- end
21
- end
22
- end
23
-
24
- end
25
- end
data/lib/pivotal/base.rb DELETED
@@ -1,73 +0,0 @@
1
- require 'rubygems'
2
- gem 'rest-client', '~>1.4.0'
3
- require 'rest_client'
4
- require 'nokogiri'
5
- require 'builder'
6
-
7
- module Pivotal
8
- class Base
9
- include Pivotal::Associations
10
- include Pivotal::Attributes
11
-
12
- attr_accessor :resource, :xml
13
-
14
- def initialize(params = {})
15
- params.each do |key, value|
16
- send("#{key}=", value)
17
- end
18
- end
19
-
20
- def xml
21
- @xml ||= resource.get.body
22
- end
23
-
24
- def parsed_resource
25
- @parsed_resource ||= Nokogiri::XML(xml)
26
- end
27
-
28
- def update_attributes(options = {})
29
- begin
30
- resource.put generate_xml(options) do |response|
31
- if response.code == 200
32
- @xml = response.body
33
- return true
34
- else
35
- return false
36
- end
37
- end
38
- rescue RestClient::Exception
39
- return false
40
- end
41
- end
42
-
43
- class << self
44
- def name_as_xml_attribute
45
- self.name.gsub(/.+\:\:/, '').downcase
46
- end
47
-
48
- def xpath
49
- '//' + self.name_as_xml_attribute
50
- end
51
- end
52
-
53
- private
54
-
55
- def generate_xml(options = {})
56
- builder = Builder::XmlMarkup.new
57
- builder.__send__ self.class.name_as_xml_attribute do
58
- allowed_keys(options).each do |key, value|
59
- builder.__send__(key, value.to_s)
60
- end
61
- end
62
-
63
- builder.target!
64
- end
65
-
66
- def allowed_keys(options = {})
67
- options.reject do |key, _|
68
- !self.class.attributes.include? key.to_s
69
- end
70
- end
71
-
72
- end
73
- end
@@ -1,63 +0,0 @@
1
- require 'cgi'
2
-
3
- module Pivotal
4
- class Collection
5
-
6
- attr_accessor :resource, :component_class
7
-
8
- def initialize(resource, component_class)
9
- @resource, @component_class = resource, component_class
10
- end
11
-
12
- # Param queries will break our REST structure,
13
- # so if we find an :id parameter, accept it and
14
- # ignore all other params.
15
- def find(*args)
16
- params = args.last.is_a?(Hash) ? args.pop : {}
17
- finder = args.first
18
-
19
- return item(params[:id]) if params[:id]
20
- return item(finder) if finder.is_a?(Numeric)
21
-
22
- all(params)
23
- end
24
-
25
- def first
26
- all.first
27
- end
28
-
29
- private
30
-
31
- def item(id)
32
- component_class.new :resource => resource[id]
33
- end
34
-
35
- def filters(params = {})
36
- return "" if params.empty?
37
-
38
- param_url = []
39
- if params[:conditions]
40
- condition_string = params[:conditions].map { |k,v| "#{k}:#{v}" }.join " "
41
- param_url << "filter=#{CGI::escape(condition_string)}"
42
- end
43
-
44
- if params[:limit]
45
- param_url << "limit=#{params[:limit]}&offset=#{params[:offset]||0}"
46
- end
47
-
48
- "?" + param_url.join("&")
49
- end
50
-
51
- def build_collection_from_xml(xml = "")
52
- Nokogiri::XML(xml).xpath(component_class.xpath).map do |item|
53
- item_id = item.xpath("id").text
54
- component_class.new :resource => resource[item_id], :xml => item.to_xml
55
- end
56
- end
57
-
58
- def all(params = {})
59
- build_collection_from_xml resource[filters(params)].get.body
60
- end
61
-
62
- end
63
- end
@@ -1,14 +0,0 @@
1
- module Pivotal
2
- class Project < Base
3
-
4
- has_collection :stories, :of => Pivotal::Story
5
- has_attributes :id, :name, :iteration_length, :week_start_day,
6
- :point_scale, :account, :velocity_scheme,
7
- :current_velocity, :initial_velocity,
8
- :number_of_iterations_to_show, :labels,
9
- :allow_attachments, :public, :use_https,
10
- :bugs_and_chores_are_estimatable, :commit_mode,
11
- :last_activity_at, :memberships, :integrations
12
-
13
- end
14
- end