tracker_api 1.8.0 → 1.12.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 (50) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +2 -1
  3. data/README.md +4 -0
  4. data/lib/tracker_api.rb +12 -0
  5. data/lib/tracker_api/client.rb +8 -6
  6. data/lib/tracker_api/endpoints/blockers.rb +20 -0
  7. data/lib/tracker_api/endpoints/iteration.rb +35 -0
  8. data/lib/tracker_api/endpoints/release.rb +17 -0
  9. data/lib/tracker_api/endpoints/releases.rb +20 -0
  10. data/lib/tracker_api/endpoints/review.rb +21 -0
  11. data/lib/tracker_api/endpoints/reviews.rb +21 -0
  12. data/lib/tracker_api/endpoints/search.rb +1 -1
  13. data/lib/tracker_api/endpoints/stories.rb +10 -0
  14. data/lib/tracker_api/error.rb +12 -2
  15. data/lib/tracker_api/resources/blocker.rb +18 -0
  16. data/lib/tracker_api/resources/cycle_time_details.rb +21 -0
  17. data/lib/tracker_api/resources/daily_history_container.rb +13 -0
  18. data/lib/tracker_api/resources/iteration.rb +14 -0
  19. data/lib/tracker_api/resources/project.rb +13 -0
  20. data/lib/tracker_api/resources/release.rb +29 -0
  21. data/lib/tracker_api/resources/review.rb +35 -0
  22. data/lib/tracker_api/resources/review_type.rb +15 -0
  23. data/lib/tracker_api/resources/story.rb +26 -0
  24. data/lib/tracker_api/version.rb +1 -1
  25. data/test/client_test.rb +52 -52
  26. data/test/comment_test.rb +13 -13
  27. data/test/error_test.rb +8 -2
  28. data/test/file_attachment_test.rb +4 -4
  29. data/test/iteration_test.rb +31 -0
  30. data/test/minitest_helper.rb +5 -2
  31. data/test/project_test.rb +59 -47
  32. data/test/release_test.rb +22 -0
  33. data/test/review_test.rb +27 -0
  34. data/test/story_test.rb +65 -48
  35. data/test/task_test.rb +3 -3
  36. data/test/vcr/cassettes/create_attachments.json +1 -1
  37. data/test/vcr/cassettes/create_comment_with_attachment.json +1 -1
  38. data/test/vcr/cassettes/delete_an_attachment.json +1 -1
  39. data/test/vcr/cassettes/delete_attachments.json +1 -1
  40. data/test/vcr/cassettes/get_current_iteration.json +1 -1
  41. data/test/vcr/cassettes/get_cycle_time_details.json +1 -0
  42. data/test/vcr/cassettes/get_daily_history_container.json +1 -0
  43. data/test/vcr/cassettes/get_releases.json +1 -0
  44. data/test/vcr/cassettes/get_story_reviews.json +1 -0
  45. data/test/vcr/cassettes/release_stories.json +1 -0
  46. data/test/vcr/cassettes/save_review.json +1 -0
  47. data/test/vcr/cassettes/search_project.json +1 -1
  48. data/test/workspace_test.rb +5 -5
  49. data/tracker_api.gemspec +1 -1
  50. metadata +35 -6
@@ -0,0 +1,35 @@
1
+ module TrackerApi
2
+ module Resources
3
+ class Review
4
+ include Shared::Base
5
+
6
+ attribute :client
7
+
8
+ attribute :id, Integer
9
+ attribute :story_id, Integer
10
+ attribute :project_id, Integer
11
+ attribute :review_type_id, Integer
12
+ attribute :reviewer_id, Integer
13
+ attribute :status, String # (unstarted, in_review, pass, revise)
14
+ attribute :created_at, DateTime
15
+ attribute :updated_at, DateTime
16
+ attribute :kind, String
17
+ attribute :review_type, ReviewType
18
+
19
+ class UpdateRepresenter < Representable::Decorator
20
+ include Representable::JSON
21
+
22
+ property :id
23
+ property :review_type_id
24
+ property :reviewer_id
25
+ property :status
26
+ end
27
+
28
+ def save
29
+ raise ArgumentError, 'Cannot update a review with an unknown story_id.' if story_id.nil?
30
+
31
+ Endpoints::Review.new(client).update(self, UpdateRepresenter.new(Review.new(dirty_attributes)))
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ module TrackerApi
2
+ module Resources
3
+ class ReviewType
4
+ include Shared::Base
5
+
6
+ attribute :id, Integer
7
+ attribute :project_id, Integer
8
+ attribute :name, String
9
+ attribute :hidden, Boolean
10
+ attribute :created_at, DateTime
11
+ attribute :updated_at, DateTime
12
+ attribute :kind, String
13
+ end
14
+ end
15
+ end
@@ -8,6 +8,7 @@ module TrackerApi
8
8
  attribute :accepted_at, DateTime
9
9
  attribute :after_id, Integer
10
10
  attribute :before_id, Integer
11
+ attribute :blockers, [Blocker]
11
12
  attribute :comment_ids, [Integer]
12
13
  attribute :comments, [Comment]
13
14
  attribute :created_at, DateTime
@@ -31,6 +32,7 @@ module TrackerApi
31
32
  attribute :project_id, Integer
32
33
  attribute :requested_by, Person
33
34
  attribute :requested_by_id, Integer
35
+ attribute :reviews, [Review]
34
36
  attribute :story_type, String # (feature, bug, chore, release)
35
37
  attribute :task_ids, [Integer]
36
38
  attribute :tasks, [Task]
@@ -54,6 +56,7 @@ module TrackerApi
54
56
  property :deadline
55
57
  property :requested_by_id
56
58
  property :owner_ids, if: ->(_) { !owner_ids.blank? }
59
+ property :project_id
57
60
 
58
61
  # Use render_empty: false to address: https://github.com/dashofcode/tracker_api/issues/110
59
62
  # - The default value of the labels attribute in Resources::Story is an empty array.
@@ -117,6 +120,10 @@ module TrackerApi
117
120
  Endpoints::Activity.new(client).get_story(project_id, id, params)
118
121
  end
119
122
 
123
+ def blockers(params = {})
124
+ Endpoints::Blockers.new(client).get(project_id, id, params)
125
+ end
126
+
120
127
  # Provides a list of all the comments on the story.
121
128
  #
122
129
  # @param [Hash] params
@@ -165,6 +172,17 @@ module TrackerApi
165
172
  end
166
173
  end
167
174
 
175
+ # Returns the story's original ("undirtied") project_id
176
+ #
177
+ # @return Integer
178
+ def project_id
179
+ if dirty_attributes.key?(:project_id)
180
+ original_attributes[:project_id]
181
+ else
182
+ @project_id
183
+ end
184
+ end
185
+
168
186
  # @param [Hash] params attributes to create the task with
169
187
  # @return [Task] newly created Task
170
188
  def create_task(params)
@@ -187,6 +205,14 @@ module TrackerApi
187
205
 
188
206
  Endpoints::Story.new(client).update(self, UpdateRepresenter.new(Story.new(self.dirty_attributes)))
189
207
  end
208
+
209
+ def reviews(params = {})
210
+ if params.blank? && @reviews.present?
211
+ @reviews
212
+ else
213
+ @reviews = Endpoints::Reviews.new(client).get(project_id, id, params)
214
+ end
215
+ end
190
216
  end
191
217
  end
192
218
  end
@@ -1,3 +1,3 @@
1
1
  module TrackerApi
2
- VERSION = '1.8.0'
2
+ VERSION = '1.12.0'
3
3
  end
@@ -2,7 +2,7 @@ require_relative 'minitest_helper'
2
2
 
3
3
  describe TrackerApi do
4
4
  it 'has a version' do
5
- ::TrackerApi::VERSION.wont_be_nil
5
+ _(::TrackerApi::VERSION).wont_be_nil
6
6
  end
7
7
  end
8
8
 
@@ -13,10 +13,10 @@ describe TrackerApi::Client do
13
13
  token: '12345',
14
14
  logger: LOGGER)
15
15
 
16
- client.url.must_equal 'http://test.com'
17
- client.api_version.must_equal '/foo-bar/1'
18
- client.token.must_equal '12345'
19
- client.logger.must_equal LOGGER
16
+ _(client.url).must_equal 'http://test.com'
17
+ _(client.api_version).must_equal '/foo-bar/1'
18
+ _(client.token).must_equal '12345'
19
+ _(client.logger).must_equal LOGGER
20
20
  end
21
21
 
22
22
  describe '.projects' do
@@ -27,18 +27,18 @@ describe TrackerApi::Client do
27
27
  VCR.use_cassette('get all projects', record: :new_episodes) do
28
28
  projects = client.projects(fields: ':default,account,current_velocity,labels(name),epics(:default,label(name))')
29
29
 
30
- projects.wont_be_empty
30
+ _(projects).wont_be_empty
31
31
  project = projects.first
32
- project.must_be_instance_of TrackerApi::Resources::Project
33
- project.id.must_equal pt_user[:project_id]
32
+ _(project).must_be_instance_of TrackerApi::Resources::Project
33
+ _(project.id).must_equal pt_user[:project_id]
34
34
 
35
- project.account.must_be_instance_of TrackerApi::Resources::Account
35
+ _(project.account).must_be_instance_of TrackerApi::Resources::Account
36
36
 
37
- project.labels.wont_be_empty
38
- project.labels.first.must_be_instance_of TrackerApi::Resources::Label
37
+ _(project.labels).wont_be_empty
38
+ _(project.labels.first).must_be_instance_of TrackerApi::Resources::Label
39
39
 
40
- project.epics.wont_be_empty
41
- project.epics.first.must_be_instance_of TrackerApi::Resources::Epic
40
+ _(project.epics).wont_be_empty
41
+ _(project.epics.first).must_be_instance_of TrackerApi::Resources::Epic
42
42
  end
43
43
  end
44
44
  end
@@ -52,11 +52,11 @@ describe TrackerApi::Client do
52
52
  VCR.use_cassette('get project', record: :new_episodes) do
53
53
  project = client.project(project_id)
54
54
 
55
- project.must_be_instance_of TrackerApi::Resources::Project
56
- project.id.must_equal project_id
55
+ _(project).must_be_instance_of TrackerApi::Resources::Project
56
+ _(project.id).must_equal project_id
57
57
 
58
- project.account.must_be_nil
59
- project.account_id.wont_be_nil
58
+ _(project.account).must_be_nil
59
+ _(project.account_id).wont_be_nil
60
60
  end
61
61
  end
62
62
  end
@@ -69,9 +69,9 @@ describe TrackerApi::Client do
69
69
  VCR.use_cassette('get workspace', record: :new_episodes) do
70
70
  workspace = client.workspace(pt_user[:workspace_id])
71
71
 
72
- workspace.must_be_instance_of TrackerApi::Resources::Workspace
73
- workspace.id.must_equal pt_user[:workspace_id]
74
- workspace.name.wont_be_empty
72
+ _(workspace).must_be_instance_of TrackerApi::Resources::Workspace
73
+ _(workspace.id).must_equal pt_user[:workspace_id]
74
+ _(workspace.name).wont_be_empty
75
75
  end
76
76
  end
77
77
  end
@@ -85,10 +85,10 @@ describe TrackerApi::Client do
85
85
  VCR.use_cassette('get all workspaces', record: :new_episodes) do
86
86
  workspaces = client.workspaces(fields: ':default,projects(id,name)')
87
87
 
88
- workspaces.wont_be_empty
88
+ _(workspaces).wont_be_empty
89
89
  workspace = workspaces.first
90
- workspace.must_be_instance_of TrackerApi::Resources::Workspace
91
- workspace.id.must_equal pt_user[:workspace_id]
90
+ _(workspace).must_be_instance_of TrackerApi::Resources::Workspace
91
+ _(workspace.id).must_equal pt_user[:workspace_id]
92
92
  end
93
93
  end
94
94
  end
@@ -105,10 +105,10 @@ describe TrackerApi::Client do
105
105
  VCR.use_cassette('get me', record: :new_episodes) do
106
106
  me = client.me
107
107
 
108
- me.must_be_instance_of TrackerApi::Resources::Me
109
- me.username.must_equal username
108
+ _(me).must_be_instance_of TrackerApi::Resources::Me
109
+ _(me.username).must_equal username
110
110
 
111
- me.projects.map(&:project_id).must_include project_id
111
+ _(me.projects.map(&:project_id)).must_include project_id
112
112
  end
113
113
  end
114
114
  end
@@ -124,14 +124,14 @@ describe TrackerApi::Client do
124
124
 
125
125
  # skip pagination with a hugh limit
126
126
  unpaged_stories = project.stories(limit: 300)
127
- unpaged_stories.wont_be_empty
128
- unpaged_stories.length.must_be :>, 7
127
+ _(unpaged_stories).wont_be_empty
128
+ _(unpaged_stories.length).must_be :>, 7
129
129
 
130
130
  # force pagination with a small limit
131
131
  paged_stories = project.stories(limit: 7)
132
- paged_stories.wont_be_empty
133
- paged_stories.length.must_equal unpaged_stories.length
134
- paged_stories.map(&:id).sort.uniq.must_equal unpaged_stories.map(&:id).sort.uniq
132
+ _(paged_stories).wont_be_empty
133
+ _(paged_stories.length).must_equal unpaged_stories.length
134
+ _(paged_stories.map(&:id).sort.uniq).must_equal unpaged_stories.map(&:id).sort.uniq
135
135
  end
136
136
  end
137
137
 
@@ -141,8 +141,8 @@ describe TrackerApi::Client do
141
141
 
142
142
  # force no pagination
143
143
  stories = project.stories(limit: 7, auto_paginate: false)
144
- stories.wont_be_empty
145
- stories.length.must_equal 7
144
+ _(stories).wont_be_empty
145
+ _(stories.length).must_equal 7
146
146
  end
147
147
  end
148
148
 
@@ -152,8 +152,8 @@ describe TrackerApi::Client do
152
152
 
153
153
  done_iterations = project.iterations(scope: :done, offset: -12, limit: 5)
154
154
 
155
- done_iterations.wont_be_empty
156
- done_iterations.length.must_be :<=, 12
155
+ _(done_iterations).wont_be_empty
156
+ _(done_iterations.length).must_be :<=, 12
157
157
  end
158
158
  end
159
159
  end
@@ -166,8 +166,8 @@ describe TrackerApi::Client do
166
166
  VCR.use_cassette('client: get single story by story id', record: :new_episodes) do
167
167
  story = client.story('66728004', fields: ':default,owned_by')
168
168
 
169
- story.must_be_instance_of TrackerApi::Resources::Story
170
- story.owned_by.wont_be_nil
169
+ _(story).must_be_instance_of TrackerApi::Resources::Story
170
+ _(story.owned_by).wont_be_nil
171
171
  end
172
172
  end
173
173
  end
@@ -180,8 +180,8 @@ describe TrackerApi::Client do
180
180
  VCR.use_cassette('client: get single epic by epic id', record: :new_episodes) do
181
181
  epic = client.epic('1087314', fields: ':default,label_id')
182
182
 
183
- epic.must_be_instance_of TrackerApi::Resources::Epic
184
- epic.label_id.wont_be_nil
183
+ _(epic).must_be_instance_of TrackerApi::Resources::Epic
184
+ _(epic.label_id).wont_be_nil
185
185
  end
186
186
  end
187
187
  end
@@ -194,13 +194,13 @@ describe TrackerApi::Client do
194
194
  VCR.use_cassette('get all notifications', record: :new_episodes) do
195
195
  notifications = client.notifications
196
196
 
197
- notifications.wont_be_empty
197
+ _(notifications).wont_be_empty
198
198
  notification = notifications.first
199
- notification.must_be_instance_of TrackerApi::Resources::Notification
199
+ _(notification).must_be_instance_of TrackerApi::Resources::Notification
200
200
 
201
- notification.project.id.must_equal pt_user[:project_id]
202
- notification.story.must_be_instance_of TrackerApi::Resources::Story
203
- notification.performer.must_be_instance_of TrackerApi::Resources::Person
201
+ _(notification.project.id).must_equal pt_user[:project_id]
202
+ _(notification.story).must_be_instance_of TrackerApi::Resources::Story
203
+ _(notification.performer).must_be_instance_of TrackerApi::Resources::Person
204
204
  end
205
205
  end
206
206
  end
@@ -213,19 +213,19 @@ describe TrackerApi::Client do
213
213
  VCR.use_cassette('get my activities', record: :new_episodes) do
214
214
  activities = client.activity(fields: ':default')
215
215
 
216
- activities.wont_be_empty
216
+ _(activities).wont_be_empty
217
217
  activity = activities.first
218
- activity.must_be_instance_of TrackerApi::Resources::Activity
218
+ _(activity).must_be_instance_of TrackerApi::Resources::Activity
219
219
 
220
- activity.changes.wont_be_empty
221
- activity.changes.first.must_be_instance_of TrackerApi::Resources::Change
220
+ _(activity.changes).wont_be_empty
221
+ _(activity.changes.first).must_be_instance_of TrackerApi::Resources::Change
222
222
 
223
- activity.primary_resources.wont_be_empty
224
- activity.primary_resources.first.must_be_instance_of TrackerApi::Resources::PrimaryResource
223
+ _(activity.primary_resources).wont_be_empty
224
+ _(activity.primary_resources.first).must_be_instance_of TrackerApi::Resources::PrimaryResource
225
225
 
226
- activity.project.must_be_instance_of TrackerApi::Resources::Project
226
+ _(activity.project).must_be_instance_of TrackerApi::Resources::Project
227
227
 
228
- activity.performed_by.must_be_instance_of TrackerApi::Resources::Person
228
+ _(activity.performed_by).must_be_instance_of TrackerApi::Resources::Person
229
229
  end
230
230
  end
231
231
  end
@@ -17,8 +17,8 @@ describe TrackerApi::Resources::Comment do
17
17
  comment = story.create_comment(text: text)
18
18
  end
19
19
 
20
- comment.text.must_equal text
21
- comment.clean?.must_equal true
20
+ _(comment.text).must_equal text
21
+ _(comment.clean?).must_equal true
22
22
  end
23
23
 
24
24
  it 'can create a comment with file attachment' do
@@ -28,9 +28,9 @@ describe TrackerApi::Resources::Comment do
28
28
  VCR.use_cassette('create comment with attachment', record: :new_episodes) do
29
29
  comment = story.create_comment(text: text, files: files)
30
30
  end
31
- comment.text.must_equal text
32
- comment.attachments.size.must_equal 1
33
- comment.clean?.must_equal true
31
+ _(comment.text).must_equal text
32
+ _(comment.attachments.size).must_equal 1
33
+ _(comment.clean?).must_equal true
34
34
  end
35
35
 
36
36
  it 'can update an existing comment' do
@@ -41,16 +41,16 @@ describe TrackerApi::Resources::Comment do
41
41
  existing_comment.save
42
42
  end
43
43
 
44
- existing_comment.text.must_equal new_text
45
- existing_comment.clean?.must_equal true
44
+ _(existing_comment.text).must_equal new_text
45
+ _(existing_comment.clean?).must_equal true
46
46
  end
47
47
 
48
48
  it 'can create attachments in a comment' do
49
49
  files = [File.expand_path('../Gemfile', File.dirname(__FILE__))]
50
50
  VCR.use_cassette('create attachments', record: :new_episodes) do
51
51
  existing_comment.create_attachments(files: files)
52
- existing_comment.attachments.size.must_equal 1
53
- existing_comment.clean?.must_equal true
52
+ _(existing_comment.attachments.size).must_equal 1
53
+ _(existing_comment.clean?).must_equal true
54
54
  end
55
55
  end
56
56
 
@@ -58,9 +58,9 @@ describe TrackerApi::Resources::Comment do
58
58
  files = [File.expand_path('../Gemfile', File.dirname(__FILE__))]
59
59
  VCR.use_cassette('delete attachments', record: :new_episodes) do
60
60
  existing_comment.create_attachments(files: files)
61
- existing_comment.attachments.size.must_equal 1
61
+ _(existing_comment.attachments.size).must_equal 1
62
62
  existing_comment.delete_attachments
63
- existing_comment.attachments.size.must_equal 0
63
+ _(existing_comment.attachments.size).must_equal 0
64
64
  end
65
65
  end
66
66
 
@@ -68,10 +68,10 @@ describe TrackerApi::Resources::Comment do
68
68
  VCR.use_cassette('delete comment', record: :new_episodes) do
69
69
  current_story = project.story(story_id)
70
70
  new_comment_id = current_story.create_comment(text: "test comment").id
71
- current_story.comments.last.id.must_equal new_comment_id
71
+ _(current_story.comments.last.id).must_equal new_comment_id
72
72
  current_story.comments.last.delete
73
73
  current_story = project.story(story_id)
74
- current_story.comments.last.id.wont_equal new_comment_id
74
+ _(current_story.comments.last.id).wont_equal new_comment_id
75
75
  end
76
76
  end
77
77
  end
@@ -22,7 +22,7 @@ describe TrackerApi::Error do
22
22
  end
23
23
  end
24
24
  end
25
-
25
+
26
26
  it 'raises RuntimeError for HTTP status codes < 400 and > 500' do
27
27
  [399, 600].each do |status_code|
28
28
  mock_faraday_error(status_code)
@@ -35,7 +35,13 @@ describe TrackerApi::Error do
35
35
  # Simulate the error Faraday will raise with a specific HTTP status code so
36
36
  # we can test our rescuing of those errors
37
37
  def mock_faraday_error(status_code)
38
+ mocked_error_class = if (500..599).include?(status_code) && Faraday::VERSION.to_f >= 16.0
39
+ Faraday::ServerError
40
+ else
41
+ Faraday::ClientError
42
+ end
43
+
38
44
  ::Faraday::Connection.any_instance.stubs(:get).
39
- raises(::Faraday::Error::ClientError.new(nil, { status: status_code}))
45
+ raises(mocked_error_class.new(nil, { status: status_code}))
40
46
  end
41
47
  end
@@ -7,13 +7,13 @@ describe TrackerApi::Resources::FileAttachment do
7
7
  let(:project) { VCR.use_cassette('get project') { client.project(project_id) } }
8
8
  let(:story_id) { '66728004' }
9
9
  let(:story) { VCR.use_cassette('get story') { project.story(story_id) } }
10
-
10
+
11
11
  it 'can be deleted' do
12
12
  VCR.use_cassette('delete an attachment', record: :new_episodes) do
13
13
  comment_with_attachments = story.create_comment(text: "test comment", files: [File.expand_path('../Gemfile', File.dirname(__FILE__))])
14
- comment_with_attachments.attachments(reload: true).size.must_equal 1
14
+ _(comment_with_attachments.attachments(reload: true).size).must_equal 1
15
15
  comment_with_attachments.attachments.first.delete
16
- comment_with_attachments.attachments(reload: true).size.must_equal 1
16
+ _(comment_with_attachments.attachments(reload: true).size).must_equal 0
17
17
  end
18
18
  end
19
- end
19
+ end
@@ -0,0 +1,31 @@
1
+ require_relative 'minitest_helper'
2
+
3
+ describe TrackerApi::Resources::Iteration do
4
+ let(:pt_user) { PT_USER_1 }
5
+ let(:client) { TrackerApi::Client.new token: pt_user[:token] }
6
+ let(:project_id) { pt_user[:project_id] }
7
+ let(:project) { VCR.use_cassette('get project') { client.project(project_id) } }
8
+ let(:iteration) { VCR.use_cassette('get current iteration') { project.iterations(scope: "current").first } }
9
+
10
+ describe "#cycle_time_details" do
11
+ it "gets all cycle_time_details for this iteration" do
12
+ VCR.use_cassette('get cycle time details', record: :new_episodes) do
13
+ cycle_time_details = iteration.cycle_time_details
14
+
15
+ cycle_time_details.wont_be_empty
16
+ cycle_time_detail = cycle_time_details.first
17
+ cycle_time_detail.must_be_instance_of TrackerApi::Resources::CycleTimeDetails
18
+ end
19
+ end
20
+ end
21
+
22
+ describe "#get_history" do
23
+ it "gets all history for a particular iteration" do
24
+ VCR.use_cassette('get daily history container', record: :new_episodes) do
25
+ daily_history_container = iteration.get_history
26
+
27
+ daily_history_container.must_be_instance_of TrackerApi::Resources::DailyHistoryContainer
28
+ end
29
+ end
30
+ end
31
+ end