jiralicious 0.4.3 → 0.5.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 (52) hide show
  1. data/.document +5 -5
  2. data/.gitignore +11 -11
  3. data/.rspec +1 -1
  4. data/.ruby-gemset +1 -1
  5. data/.travis.yml +10 -10
  6. data/Gemfile +4 -4
  7. data/LICENSE +22 -22
  8. data/README.md +99 -94
  9. data/Rakefile +16 -16
  10. data/gemfiles/newest.gemfile +3 -3
  11. data/gemfiles/oldest.gemfile +6 -6
  12. data/jiralicious.gemspec +37 -37
  13. data/lib/jiralicious.rb +2 -0
  14. data/lib/jiralicious/base.rb +226 -226
  15. data/lib/jiralicious/component.rb +103 -0
  16. data/lib/jiralicious/custom_field_option.rb +45 -45
  17. data/lib/jiralicious/errors.rb +27 -27
  18. data/lib/jiralicious/field.rb +58 -58
  19. data/lib/jiralicious/issue/fields.rb +197 -197
  20. data/lib/jiralicious/issue/watchers.rb +92 -92
  21. data/lib/jiralicious/project.rb +116 -64
  22. data/lib/jiralicious/session.rb +61 -61
  23. data/lib/jiralicious/version.rb +4 -4
  24. data/lib/jiralicious/versions.rb +150 -0
  25. data/spec/components_spec.rb +74 -0
  26. data/spec/configuration_spec.rb +41 -41
  27. data/spec/field_parser_spec.rb +73 -73
  28. data/spec/fixtures/avatar.json +6 -6
  29. data/spec/fixtures/avatar_custom.json +15 -15
  30. data/spec/fixtures/avatar_list.json +15 -15
  31. data/spec/fixtures/avatar_temp.json +6 -6
  32. data/spec/fixtures/comment_single.json +28 -28
  33. data/spec/fixtures/component.json +39 -0
  34. data/spec/fixtures/component_ric.json +4 -0
  35. data/spec/fixtures/component_updated.json +39 -0
  36. data/spec/fixtures/jira.yml +7 -7
  37. data/spec/fixtures/project_componets.json +80 -0
  38. data/spec/fixtures/project_versions.json +22 -0
  39. data/spec/fixtures/test.json +23 -23
  40. data/spec/fixtures/version.json +11 -0
  41. data/spec/fixtures/version_ric.json +5 -0
  42. data/spec/fixtures/version_uic.json +4 -0
  43. data/spec/fixtures/version_updated.json +11 -0
  44. data/spec/issue_spec.rb +385 -385
  45. data/spec/jiralicious_spec.rb +16 -16
  46. data/spec/project_spec.rb +25 -2
  47. data/spec/search_result_spec.rb +54 -54
  48. data/spec/support/configuration.rb +11 -11
  49. data/spec/support/http.rb +147 -111
  50. data/spec/versions_spec.rb +84 -0
  51. metadata +189 -170
  52. checksums.yaml +0 -7
@@ -1,226 +1,226 @@
1
- # encoding: utf-8
2
- require "uri"
3
- module Jiralicious
4
- ##
5
- # The Base class encapsulates all of the default functionality necessary in order
6
- # to properly manage the Hashie::Trash object within the Jiralicious framework.
7
- #
8
- class Base < Hashie::Trash
9
-
10
- ##
11
- # Includes functionality from FieldParser
12
- #
13
- include Jiralicious::Parsers::FieldParser
14
-
15
- ##
16
- # Used to identify if the class has been loaded
17
- #
18
- attr_accessor :loaded
19
-
20
- ##
21
- # Trash Extention properties_from_hash
22
- # Adds an underscore (_) before a numeric field.
23
- # This ensures that numeric fields will be treated as strings.
24
- #
25
- # [Arguments]
26
- # :hash (required) hash to be added to properties
27
- #
28
- def properties_from_hash(hash)
29
- hash.inject({}) do |newhash, (k, v)|
30
- k = k.gsub("-", "_")
31
- k = "_#{k.to_s}" if k =~ /^\d/
32
- self.class.property :"#{k}"
33
- newhash[k] = v
34
- newhash
35
- end
36
- end
37
-
38
- class << self
39
- ##
40
- # Finds the specified key in relation to the current class.
41
- # This is based on the inheritance and will create an error
42
- # if called from the Base Class directly.
43
- #
44
- # [Arguments]
45
- # :key (required) object key to find
46
- #
47
- # :reload (required) is object reloading forced
48
- #
49
- def find(key, options = {})
50
- response = fetch({:key => key})
51
- if options[:reload] == true
52
- response
53
- else
54
- new(response.parsed_response)
55
- end
56
- end
57
-
58
- ##
59
- # Searches for all objects of the inheritance class. This
60
- # method can create very large datasets and is not recommended
61
- # for any request that could slow down either Jira or the
62
- # Ruby application.
63
- #
64
- def find_all
65
- response = fetch()
66
- new(response)
67
- end
68
-
69
- ##
70
- # Generates the endpoint_name based on the current inheritance class.
71
- #
72
- def endpoint_name
73
- self.name.split('::').last.downcase
74
- end
75
-
76
- ##
77
- # Generates the parent_name based on the current inheritance class.
78
- #
79
- def parent_name
80
- arr = self.name.split('::')
81
- arr[arr.length-2].downcase
82
- end
83
-
84
- ##
85
- # uses the options to build the URI options necessary to handle the
86
- # request. Some options are defaulted if not explicit while others
87
- # are only necessary under specific conditions.
88
- #
89
- #
90
- # [Arguments]
91
- # :key (optional) key of object to fetch
92
- #
93
- # :method (optional) limited to the standard request types default of :get
94
- #
95
- # :parent (optional) boolean will the parent object be used
96
- #
97
- # :parent_key (optional) parent's key (must set :parent to use)
98
- #
99
- # :body (optional) fields to be sent with the fetch
100
- #
101
- # :body_override (optional) corrects issues in :body if set
102
- #
103
- # :body_to_params (optional) forces body to be appended to URI
104
- #
105
- # :url (optional) overrides auto generated URI with custom URI
106
- #
107
- def fetch(options = {})
108
- options[:method] = :get unless [:get, :post, :put, :delete].include?(options[:method])
109
- options[:parent_uri] = "#{parent_name}/#{options[:parent_key]}/" unless options[:parent].nil?
110
- if !options[:body_override]
111
- options[:body_uri] = (options[:body].is_a? Hash) ? options[:body] : {:body => options[:body]}
112
- else
113
- options[:body_uri] = options[:body]
114
- end
115
- if options[:body_to_params]
116
- options[:params_uri] = "?#{options[:body].to_params}" unless options[:body].nil? || options[:body].empty?
117
- options[:body_uri] = nil
118
- end
119
- options[:url_uri] = options[:url].nil? ? "#{Jiralicious.rest_path}/#{options[:parent_uri]}#{endpoint_name}/#{options[:key]}#{options[:params_uri]}" : "#{options[:url]}#{options[:params_uri]}"
120
- Jiralicious.session.request(options[:method], options[:url_uri], :handler => handler, :body => options[:body_uri].to_json)
121
- end
122
-
123
- ##
124
- # Configures the default handler. This can be overridden in
125
- # the child class to provide additional error handling.
126
- #
127
- def handler
128
- Proc.new do |response|
129
- case response.code
130
- when 200..204
131
- response
132
- when 400
133
- raise Jiralicious::TransitionError.new(response.inspect)
134
- when 404
135
- raise Jiralicious::IssueNotFound.new(response.inspect)
136
- else
137
- raise Jiralicious::JiraError.new(response.inspect)
138
- end
139
- end
140
- end
141
-
142
- ##
143
- # Validates that the provided key is not malformed
144
- #
145
- #
146
- def issueKey_test(key, no_throw = false)
147
- if key.nil? || !(/^[A-Z]+-[0-9]+$/i =~ key)
148
- raise Jiralicious::JiraError.new("The key #{key} is invalid") unless no_throw
149
- return false
150
- end
151
- return true
152
- end
153
-
154
- alias :all :find_all
155
- end
156
-
157
- ##
158
- # Generates the endpoint_name based on the current inheritance class.
159
- #
160
- def endpoint_name
161
- self.class.endpoint_name
162
- end
163
-
164
- ##
165
- # Generates the parent_name based on the current inheritance class.
166
- #
167
- def parent_name
168
- self.class.parent_name
169
- end
170
-
171
- ##
172
- # Searches for all objects of the inheritance class. This method can
173
- # create very large datasets and is not recommended for any request
174
- # that could slow down either Jira or the Ruby application.
175
- #
176
- def all
177
- self.class.all
178
- end
179
-
180
- ##
181
- # Returns the the logical form of the loaded member. This used
182
- # to determine if the object is loaded and ready for usage.
183
- #
184
- def loaded?
185
- !!self.loaded
186
- end
187
-
188
- ##
189
- # Default reload method is blank. For classes that implement lazy loading
190
- # this method will be overridden with the necessary functionality.
191
- #
192
- def reload
193
- end
194
-
195
- ##
196
- # Overrides the default method_missing check. This override is used in lazy
197
- # loading to ensure that the requested field or method is truly unavailable.
198
- #
199
- # [Arguments]
200
- # :meth (system)
201
- #
202
- # :args (system)
203
- #
204
- # :block (system)
205
- #
206
- def method_missing(meth, *args, &block)
207
- if !loaded?
208
- self.loaded = true
209
- reload
210
- self.send(meth, *args, &block)
211
- else
212
- super
213
- end
214
- end
215
-
216
- ##
217
- # Validates if the provided object is a numeric value
218
- #
219
- # [Arguments]
220
- # :object (required) object to be tested
221
- #
222
- def numeric?(object)
223
- true if Float(object) rescue false
224
- end
225
- end
226
- end
1
+ # encoding: utf-8
2
+ require "uri"
3
+ module Jiralicious
4
+ ##
5
+ # The Base class encapsulates all of the default functionality necessary in order
6
+ # to properly manage the Hashie::Trash object within the Jiralicious framework.
7
+ #
8
+ class Base < Hashie::Trash
9
+
10
+ ##
11
+ # Includes functionality from FieldParser
12
+ #
13
+ include Jiralicious::Parsers::FieldParser
14
+
15
+ ##
16
+ # Used to identify if the class has been loaded
17
+ #
18
+ attr_accessor :loaded
19
+
20
+ ##
21
+ # Trash Extention properties_from_hash
22
+ # Adds an underscore (_) before a numeric field.
23
+ # This ensures that numeric fields will be treated as strings.
24
+ #
25
+ # [Arguments]
26
+ # :hash (required) hash to be added to properties
27
+ #
28
+ def properties_from_hash(hash)
29
+ hash.inject({}) do |newhash, (k, v)|
30
+ k = k.gsub("-", "_")
31
+ k = "_#{k.to_s}" if k =~ /^\d/
32
+ self.class.property :"#{k}"
33
+ newhash[k] = v
34
+ newhash
35
+ end
36
+ end
37
+
38
+ class << self
39
+ ##
40
+ # Finds the specified key in relation to the current class.
41
+ # This is based on the inheritance and will create an error
42
+ # if called from the Base Class directly.
43
+ #
44
+ # [Arguments]
45
+ # :key (required) object key to find
46
+ #
47
+ # :reload (required) is object reloading forced
48
+ #
49
+ def find(key, options = {})
50
+ response = fetch({:key => key})
51
+ if options[:reload] == true
52
+ response
53
+ else
54
+ new(response.parsed_response)
55
+ end
56
+ end
57
+
58
+ ##
59
+ # Searches for all objects of the inheritance class. This
60
+ # method can create very large datasets and is not recommended
61
+ # for any request that could slow down either Jira or the
62
+ # Ruby application.
63
+ #
64
+ def find_all
65
+ response = fetch()
66
+ new(response)
67
+ end
68
+
69
+ ##
70
+ # Generates the endpoint_name based on the current inheritance class.
71
+ #
72
+ def endpoint_name
73
+ self.name.split('::').last.downcase
74
+ end
75
+
76
+ ##
77
+ # Generates the parent_name based on the current inheritance class.
78
+ #
79
+ def parent_name
80
+ arr = self.name.split('::')
81
+ arr[arr.length-2].downcase
82
+ end
83
+
84
+ ##
85
+ # uses the options to build the URI options necessary to handle the
86
+ # request. Some options are defaulted if not explicit while others
87
+ # are only necessary under specific conditions.
88
+ #
89
+ #
90
+ # [Arguments]
91
+ # :key (optional) key of object to fetch
92
+ #
93
+ # :method (optional) limited to the standard request types default of :get
94
+ #
95
+ # :parent (optional) boolean will the parent object be used
96
+ #
97
+ # :parent_key (optional) parent's key (must set :parent to use)
98
+ #
99
+ # :body (optional) fields to be sent with the fetch
100
+ #
101
+ # :body_override (optional) corrects issues in :body if set
102
+ #
103
+ # :body_to_params (optional) forces body to be appended to URI
104
+ #
105
+ # :url (optional) overrides auto generated URI with custom URI
106
+ #
107
+ def fetch(options = {})
108
+ options[:method] = :get unless [:get, :post, :put, :delete].include?(options[:method])
109
+ options[:parent_uri] = "#{parent_name}/#{options[:parent_key]}/" unless options[:parent].nil?
110
+ if !options[:body_override]
111
+ options[:body_uri] = (options[:body].is_a? Hash) ? options[:body] : {:body => options[:body]}
112
+ else
113
+ options[:body_uri] = options[:body]
114
+ end
115
+ if options[:body_to_params]
116
+ options[:params_uri] = "?#{options[:body].to_params}" unless options[:body].nil? || options[:body].empty?
117
+ options[:body_uri] = nil
118
+ end
119
+ options[:url_uri] = options[:url].nil? ? "#{Jiralicious.rest_path}/#{options[:parent_uri]}#{endpoint_name}/#{options[:key]}#{options[:params_uri]}" : "#{options[:url]}#{options[:params_uri]}"
120
+ Jiralicious.session.request(options[:method], options[:url_uri], :handler => handler, :body => options[:body_uri].to_json)
121
+ end
122
+
123
+ ##
124
+ # Configures the default handler. This can be overridden in
125
+ # the child class to provide additional error handling.
126
+ #
127
+ def handler
128
+ Proc.new do |response|
129
+ case response.code
130
+ when 200..204
131
+ response
132
+ when 400
133
+ raise Jiralicious::TransitionError.new(response.inspect)
134
+ when 404
135
+ raise Jiralicious::IssueNotFound.new(response.inspect)
136
+ else
137
+ raise Jiralicious::JiraError.new(response.inspect)
138
+ end
139
+ end
140
+ end
141
+
142
+ ##
143
+ # Validates that the provided key is not malformed
144
+ #
145
+ #
146
+ def issueKey_test(key, no_throw = false)
147
+ if key.nil? || !(/^[A-Z]+-[0-9]+$/i =~ key)
148
+ raise Jiralicious::JiraError.new("The key #{key} is invalid") unless no_throw
149
+ return false
150
+ end
151
+ return true
152
+ end
153
+
154
+ alias :all :find_all
155
+ end
156
+
157
+ ##
158
+ # Generates the endpoint_name based on the current inheritance class.
159
+ #
160
+ def endpoint_name
161
+ self.class.endpoint_name
162
+ end
163
+
164
+ ##
165
+ # Generates the parent_name based on the current inheritance class.
166
+ #
167
+ def parent_name
168
+ self.class.parent_name
169
+ end
170
+
171
+ ##
172
+ # Searches for all objects of the inheritance class. This method can
173
+ # create very large datasets and is not recommended for any request
174
+ # that could slow down either Jira or the Ruby application.
175
+ #
176
+ def all
177
+ self.class.all
178
+ end
179
+
180
+ ##
181
+ # Returns the the logical form of the loaded member. This used
182
+ # to determine if the object is loaded and ready for usage.
183
+ #
184
+ def loaded?
185
+ !!self.loaded
186
+ end
187
+
188
+ ##
189
+ # Default reload method is blank. For classes that implement lazy loading
190
+ # this method will be overridden with the necessary functionality.
191
+ #
192
+ def reload
193
+ end
194
+
195
+ ##
196
+ # Overrides the default method_missing check. This override is used in lazy
197
+ # loading to ensure that the requested field or method is truly unavailable.
198
+ #
199
+ # [Arguments]
200
+ # :meth (system)
201
+ #
202
+ # :args (system)
203
+ #
204
+ # :block (system)
205
+ #
206
+ def method_missing(meth, *args, &block)
207
+ if !loaded?
208
+ self.loaded = true
209
+ reload
210
+ self.send(meth, *args, &block)
211
+ else
212
+ super
213
+ end
214
+ end
215
+
216
+ ##
217
+ # Validates if the provided object is a numeric value
218
+ #
219
+ # [Arguments]
220
+ # :object (required) object to be tested
221
+ #
222
+ def numeric?(object)
223
+ true if Float(object) rescue false
224
+ end
225
+ end
226
+ end
@@ -0,0 +1,103 @@
1
+ # encoding: utf-8
2
+ module Jiralicious
3
+ class Component < Jiralicious::Field
4
+ ##
5
+ # Holds the Component Key
6
+ #
7
+ property :component_key, :from => :id
8
+
9
+ class << self
10
+ ##
11
+ # Creates a new component
12
+ #
13
+ # [Arguments]
14
+ # :details (required) Component details to be created
15
+ #
16
+ def create(details)
17
+ response = fetch({:method => :post, :body => details})
18
+ new(response.parsed_response)
19
+ end
20
+
21
+ ##
22
+ # Returns the number of Issues associated with the Component
23
+ #
24
+ # [Arguments]
25
+ # :id (required) Component to count
26
+ #
27
+ def related_issue_counts(id)
28
+ response = fetch({:key => "#{id}/relatedIssueCounts"})
29
+ response.parsed_response['id'] = id
30
+ Field.new(response.parsed_response)
31
+ end
32
+
33
+ ##
34
+ # Removes/Deletes a Component
35
+ #
36
+ # [Arguments]
37
+ # :remove_id (required) Component to remove/delete
38
+ #
39
+ # :target_id (optional) Component to move issues to
40
+ #
41
+ def remove(remove_id, target_id = nil)
42
+ body = {}
43
+ if !target_id.nil?
44
+ body.merge!("movIssuesTo"=>target_id)
45
+ end
46
+ fetch({:method => :delete, :key => remove_id, :body_to_params => true, :body => body}).parsed_response
47
+ end
48
+
49
+ ##
50
+ # Updates a component
51
+ #
52
+ # [Arguments]
53
+ # :id (required) Component to be updated
54
+ #
55
+ # :details (required) Details of the component to be updated
56
+ #
57
+ def update(id, details)
58
+ response = fetch({:method => :put, :key => id, :body => details})
59
+ new(response.parsed_response)
60
+ end
61
+ end
62
+
63
+ ##
64
+ # Finds all watchers based on the provided Issue Key
65
+ #
66
+ def find
67
+ self.class.find_by_id(self.component_key)
68
+ end
69
+
70
+ ##
71
+ # Returns the number of Issues associated with the Component
72
+ #
73
+ # [Arguments]
74
+ # :id (required) Component to count
75
+ #
76
+ def related_issue_counts
77
+ self.class.related_issue_counts(self.component_key).issueCount
78
+ end
79
+
80
+ ##
81
+ # Removes/Deletes a Component
82
+ #
83
+ # [Arguments]
84
+ # :target_id (optional) Component to move issues to
85
+ #
86
+ def remove(target = nil)
87
+ self.class.remove(self.component_key, target)
88
+ end
89
+
90
+ ##
91
+ # Updates a component
92
+ #
93
+ # [Arguments]
94
+ # :details (required) Details of the component to be updated
95
+ #
96
+ def update(details)
97
+ details.each do |k, v|
98
+ self.send("#{k.to_s}=", v)
99
+ end
100
+ self.class.update(self.component_key, details)
101
+ end
102
+ end
103
+ end