factor-connector-pivotal 0.0.4 → 0.0.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 395bb44b325addb67f1c98a97e81d3cb8015cc61
4
- data.tar.gz: c5ed28b450c79840a2a56b8c3693f4df31da7220
3
+ metadata.gz: 6ec2d33b676c4d7c3c31621673b0152a1380edfd
4
+ data.tar.gz: 89820942da1391d91a85eea42e50ca2f953b8968
5
5
  SHA512:
6
- metadata.gz: d0f5faadbaddf65bdd1a9441ac11460ce6fe4704428d528b354035ebc98a0f89a7428101aa795383267c23908e3d3bf64a37dfc9fdc25537dcc47d5e10aefed9
7
- data.tar.gz: 0d4ccc513e93249b4cc7681b244326c227eb766d3b3676ee6a03414e8e85b465278e2e34d5ee9e281c5377919de742d53e9c754c99a199cef5344742aab0349f
6
+ metadata.gz: fc96c7b261b3ddd820cf86ca8887b869307921a7c4404225e2a28d17da933df1bca56622905b2857cdebefcdf4fa19b3f86d1a94132d1ed2f2dddce05c28c1f4
7
+ data.tar.gz: 3b4b588eaac07b5e067fa96d0a1fc20dea82bcfecf90fb0d294d49d1c97b5e436ada821e8730f4a6b4e11fdb10c754d800c4a2e52b28c031ebef327b37619a94
@@ -0,0 +1,115 @@
1
+ require 'factor-connector-api'
2
+ require 'pivotal-api'
3
+
4
+ Factor::Connector.service 'pivotal_comments' do
5
+ action 'get' do |params|
6
+ api_key = params['api_key']
7
+ project_id = params['project']
8
+ story_id = params['story']
9
+ id = params['id']
10
+
11
+ fail 'API Key (api_key) are required' unless api_key
12
+ fail 'Project ID (project) is required' unless project_id
13
+ fail 'Project ID (project) must be an integer' unless project_id.is_a?(Integer)
14
+ fail 'Story ID (story) is required' unless story_id
15
+ fail 'Story ID (story) must be an Integer' unless story_id.is_a?(Integer)
16
+ fail 'Comment ID (id) is required' unless id
17
+ fail 'Comment ID (id) must be an integer' unless id.is_a?(Integer)
18
+
19
+
20
+ info 'Initializing Pivotal Tracker Client'
21
+ client = PivotalApi::Client.new(token: api_key)
22
+
23
+ info "Creating comment"
24
+ begin
25
+ comment = client.projects.stories.comments.get project_id, story_id, id
26
+ rescue
27
+ fail "Failed to get comment, check your credentials"
28
+ end
29
+
30
+ action_callback comment.to_hash
31
+ end
32
+
33
+ action 'all' do |params|
34
+ api_key = params['api_key']
35
+ project_id = params['project']
36
+ story_id = params['story']
37
+
38
+ fail 'API Key (api_key) are required' unless api_key
39
+ fail 'Project ID (project) is required' unless project_id
40
+ fail 'Project ID (project) must be an integer' unless project_id.is_a?(Integer)
41
+ fail 'Story ID (story) is required' unless story_id
42
+ fail 'Story ID (story) must be an Integer' unless story_id.is_a?(Integer)
43
+
44
+
45
+ info 'Initializing Pivotal Tracker Client'
46
+ client = PivotalApi::Client.new(token: api_key)
47
+
48
+ info "Getting comments"
49
+ begin
50
+ comments = client.projects.stories.comments.all(project_id, story_id).map {|n| n.to_hash}
51
+ rescue
52
+ fail "Failed to get comments, check your credentials"
53
+ end
54
+
55
+ action_callback comments
56
+ end
57
+
58
+ action 'create' do |params|
59
+ api_key = params['api_key']
60
+ project_id = params['project']
61
+ story_id = params['story']
62
+
63
+ fail 'API Key (api_key) are required' unless api_key
64
+ fail 'Project ID (project) is required' unless project_id
65
+ fail 'Project ID (project) must be an integer' unless project_id.is_a?(Integer)
66
+ fail 'Story ID (story) is required' unless story_id
67
+ fail 'Story ID (story) must be an Integer' unless story_id.is_a?(Integer)
68
+
69
+
70
+ info 'Initializing Pivotal Tracker Client'
71
+ client = PivotalApi::Client.new(token: api_key)
72
+
73
+ fields = %w(text person_id commit_identifier commit_type)
74
+ comment_fields = params.select do |key, value|
75
+ fields.include?(key)
76
+ end
77
+
78
+ begin
79
+ comment = client.projects.stories.comments.create project_id, story_id, comment_fields
80
+ rescue
81
+ fail "Failed to create the comment, check the fields"
82
+ end
83
+
84
+ action_callback comment.to_hash
85
+ end
86
+
87
+ action 'delete' do |params|
88
+ api_key = params['api_key']
89
+ project_id = params['project']
90
+ story_id = params['story']
91
+ id = params['id']
92
+
93
+ fail 'API Key (api_key) are required' unless api_key
94
+ fail 'Project ID (project) is required' unless project_id
95
+ fail 'Project ID (project) must be an integer' unless project_id.is_a?(Integer)
96
+ fail 'Story ID (story) is required' unless story_id
97
+ fail 'Story ID (story) must be an Integer' unless story_id.is_a?(Integer)
98
+ fail 'Comment ID (id) is required' unless id
99
+ fail 'Comment ID (id) must be an integer' unless id.is_a?(Integer)
100
+
101
+
102
+ info 'Initializing Pivotal Tracker Client'
103
+ client = PivotalApi::Client.new(token: api_key)
104
+
105
+ info "Creating comment"
106
+ begin
107
+ client.projects.stories.comments.delete project_id, story_id, id
108
+ rescue
109
+ fail "Failed to delete comment, check your credentials"
110
+ end
111
+
112
+ action_callback
113
+ end
114
+
115
+ end
@@ -0,0 +1,84 @@
1
+ require 'factor-connector-api'
2
+ require 'pivotal-api'
3
+
4
+ Factor::Connector.service 'pivotal_labels' do
5
+ action 'all' do |params|
6
+ api_key = params['api_key']
7
+ project_id = params['project']
8
+ story_id = params['story']
9
+
10
+ fail 'API Key (api_key) are required' unless api_key
11
+ fail 'Project ID (project) is required' unless project_id
12
+ fail 'Project ID (project) must be an integer' unless project_id.is_a?(Integer)
13
+ fail 'Story ID (story) is required' unless story_id
14
+ fail 'Story ID (story) must be an Integer' unless story_id.is_a?(Integer)
15
+
16
+
17
+ info 'Initializing Pivotal Tracker Client'
18
+ client = PivotalApi::Client.new(token: api_key)
19
+
20
+ info "Getting labels"
21
+ begin
22
+ labels = client.projects.stories.labels.all(project_id, story_id).map {|n| n.to_hash}
23
+ rescue
24
+ fail "Failed to get labels, check your credentials"
25
+ end
26
+
27
+ action_callback labels
28
+ end
29
+
30
+ action 'create' do |params|
31
+ api_key = params['api_key']
32
+ project_id = params['project']
33
+ story_id = params['story']
34
+ name = params['name']
35
+
36
+ fail 'API Key (api_key) are required' unless api_key
37
+ fail 'Project ID (project) is required' unless project_id
38
+ fail 'Project ID (project) must be an integer' unless project_id.is_a?(Integer)
39
+ fail 'Story ID (story) is required' unless story_id
40
+ fail 'Story ID (story) must be an Integer' unless story_id.is_a?(Integer)
41
+ fail 'Name (name) of label is required' unless name
42
+
43
+
44
+ info 'Initializing Pivotal Tracker Client'
45
+ client = PivotalApi::Client.new(token: api_key)
46
+
47
+ begin
48
+ label = client.projects.stories.labels.create project_id, story_id, name: name
49
+ rescue
50
+ fail "Failed to create the label, check the fields"
51
+ end
52
+
53
+ action_callback label.to_hash
54
+ end
55
+
56
+ action 'delete' do |params|
57
+ api_key = params['api_key']
58
+ project_id = params['project']
59
+ story_id = params['story']
60
+ id = params['id']
61
+
62
+ fail 'API Key (api_key) are required' unless api_key
63
+ fail 'Project ID (project) is required' unless project_id
64
+ fail 'Project ID (project) must be an integer' unless project_id.is_a?(Integer)
65
+ fail 'Story ID (story) is required' unless story_id
66
+ fail 'Story ID (story) must be an Integer' unless story_id.is_a?(Integer)
67
+ fail 'Label ID (id) is required' unless id
68
+ fail 'Label ID (id) must be an integer' unless id.is_a?(Integer)
69
+
70
+
71
+ info 'Initializing Pivotal Tracker Client'
72
+ client = PivotalApi::Client.new(token: api_key)
73
+
74
+ info 'Deleting label'
75
+ begin
76
+ client.projects.stories.labels.delete project_id, story_id, id
77
+ rescue
78
+ fail "Failed to get label, check your credentials"
79
+ end
80
+
81
+ action_callback
82
+ end
83
+
84
+ end
@@ -1,5 +1,5 @@
1
1
  require 'factor-connector-api'
2
- require 'pivotal-tracker'
2
+ require 'pivotal-api'
3
3
 
4
4
  Factor::Connector.service 'pivotal_projects' do
5
5
  action 'get' do |params|
@@ -11,27 +11,16 @@ Factor::Connector.service 'pivotal_projects' do
11
11
  fail 'Project ID (id) must be an integer' unless id.is_a?(Integer)
12
12
 
13
13
  info 'Initializing Pivotal Tracker Client'
14
- PivotalTracker::Client.token = api_key
14
+ client = PivotalApi::Client.new(token: api_key)
15
15
 
16
16
  info "Getting project with ID #{id.to_s}"
17
17
  begin
18
- raw_project = PivotalTracker::Project.find(id)
18
+ project = client.projects.get id
19
19
  rescue
20
20
  fail "Failed to get the project with id #{id.to_s}, check your credentials"
21
21
  end
22
- fail "No project with id #{id.to_s} found" unless raw_project
23
-
24
- project = raw_project.instance_variables.each_with_object({}) do |v, h|
25
- val = raw_project.instance_variable_get(v)
26
- id = v.to_s.delete('@')
27
- if val.is_a?(DateTime)
28
- h[id] = val.iso8601
29
- else
30
- h[id] = val
31
- end
32
- end
33
22
 
34
- action_callback project
23
+ action_callback project.to_hash
35
24
  end
36
25
 
37
26
  action 'all' do |params|
@@ -40,18 +29,13 @@ Factor::Connector.service 'pivotal_projects' do
40
29
  fail 'API Key (api_key) are required' unless api_key
41
30
 
42
31
  info 'Initializing Pivotal Tracker Client'
43
- PivotalTracker::Client.token = api_key
32
+ client = PivotalApi::Client.new(token: api_key)
44
33
 
45
34
  info 'Getting list of projects'
46
- projects = PivotalTracker::Project.all.map do |project|
47
- project.instance_variables.each_with_object({}) do |v, h|
48
- val = p.instance_variable_get(v)
49
- if val.is_a?(DateTime)
50
- h[v.to_s.delete('@')] = val.iso8601
51
- else
52
- h[v.to_s.delete('@')] = val
53
- end
54
- end
35
+ begin
36
+ projects = client.projects.all.map {|p| p.to_hash}
37
+ rescue
38
+ fail 'Failed to get the projects, check your credentials'
55
39
  end
56
40
 
57
41
  action_callback projects
@@ -1,5 +1,5 @@
1
1
  require 'factor-connector-api'
2
- require 'pivotal-tracker'
2
+ require 'pivotal-api'
3
3
 
4
4
  Factor::Connector.service 'pivotal_stories' do
5
5
  action 'get' do |params|
@@ -13,85 +13,37 @@ Factor::Connector.service 'pivotal_stories' do
13
13
  fail 'Story ID (id) is required' unless id
14
14
  fail 'Story ID (id) must be an Integer' unless id.is_a?(Integer)
15
15
 
16
-
17
16
  info 'Initializing Pivotal Tracker Client'
18
- PivotalTracker::Client.token = api_key
19
-
20
- info "Getting project with ID #{project_id.to_s}"
21
- begin
22
- project = PivotalTracker::Project.find(project_id)
23
- rescue
24
- fail "Failed to get the project with id #{project_id.to_s}, check your credentials"
25
- end
26
-
27
- fail "No project with id #{project_id.to_s} found" unless project
17
+ client = PivotalApi::Client.new(token: api_key)
28
18
 
29
19
  info "Getting story with id #{id.to_s}"
30
20
  begin
31
- raw_story = project.stories.find(id)
21
+ story = client.projects.stories.get(project_id,id)
32
22
  rescue
33
23
  fail "Failed to get stories, check your credentials and filter"
34
24
  end
35
25
 
36
- fail "No stories found" unless raw_story
37
-
38
-
39
- story = raw_story.instance_variables.each_with_object({}) do |v, h|
40
- val = raw_story.instance_variable_get(v)
41
- if val.is_a?(DateTime)
42
- h[v.to_s.delete('@')] = val.iso8601
43
- else
44
- h[v.to_s.delete('@')] = val
45
- end
46
- end
47
-
48
- action_callback story
26
+ action_callback story.to_hash
49
27
  end
50
28
 
51
29
  action 'all' do |params|
52
30
  api_key = params['api_key']
53
31
  project_id = params['project']
54
- filter = params['filter'] || {}
55
32
 
56
33
  fail 'API Key (api_key) are required' unless api_key
57
34
  fail 'Project ID (project_id) is required' unless project_id
58
35
  fail 'Project ID (project_id) must be an integer' unless project_id.is_a?(Integer)
59
- fail 'Filter (filter) must be a Hash' unless filter.is_a?(Hash)
60
-
61
36
 
62
37
  info 'Initializing Pivotal Tracker Client'
63
- PivotalTracker::Client.token = api_key
64
-
65
- info "Getting project with ID #{project_id.to_s}"
66
- begin
67
- project = PivotalTracker::Project.find(project_id)
68
- rescue
69
- fail "Failed to get the project with id #{project_id.to_s}, check your credentials"
70
- end
71
-
72
- fail "No project with id #{project_id.to_s} found" unless project
38
+ client = PivotalApi::Client.new(token: api_key)
73
39
 
74
- info 'Getting list of stories'
40
+ info "Getting stories for project with id #{project_id}"
75
41
  begin
76
- stories = filter == {} ? project.stories.all : project.stories.all(filter)
42
+ stories = client.projects.stories.all(project_id).map {|story| story.to_hash}
77
43
  rescue
78
44
  fail "Failed to get stories, check your credentials and filter"
79
45
  end
80
46
 
81
- fail "No stories found" unless stories
82
-
83
-
84
- stories = stories.map do |story|
85
- story.instance_variables.each_with_object({}) do |v, h|
86
- val = story.instance_variable_get(v)
87
- if val.is_a?(DateTime)
88
- h[v.to_s.delete('@')] = val.iso8601
89
- else
90
- h[v.to_s.delete('@')] = val
91
- end
92
- end
93
- end
94
-
95
47
  action_callback stories
96
48
  end
97
49
 
@@ -104,42 +56,19 @@ Factor::Connector.service 'pivotal_stories' do
104
56
  fail 'Project ID (project_id) must be an integer' unless project_id.is_a?(Integer)
105
57
 
106
58
  info 'Initializing Pivotal Tracker Client'
107
- PivotalTracker::Client.token = api_key
108
-
109
- info "Getting project with ID #{project_id.to_s}"
110
- begin
111
- project = PivotalTracker::Project.find(project_id)
112
- rescue
113
- fail "Failed to get the project with id #{project_id.to_s}, check your credentials"
114
- end
59
+ client = PivotalApi::Client.new(token: api_key)
115
60
 
116
- fail "No project with id #{project_id.to_s} found" unless project
61
+ fields = %w(name description story_type current_state estimate accepted_at deadline requested_by_id owner_ids labels label_ids follower_ids created_at integration_id external_id)
117
62
 
118
-
119
- fields = %w(name description story_type estimate current_state requested_by owned_by labels jira_id jira_url other_id zendesk_id zendesk_url integration_id deadline)
120
-
121
- story_fields = params.select do |key, value|
122
- fields.include?(key)
123
- end
63
+ story_fields = params.select { |key, value| fields.include?(key) }
124
64
 
125
65
  begin
126
- raw_story = project.stories.create(story_fields)
66
+ story = client.projects.stories.create project_id, story_fields
127
67
  rescue
128
68
  fail "Failed to create the story, check the fields"
129
69
  end
130
70
 
131
- fail "Failed to create the story" unless raw_story
132
-
133
- story = raw_story.instance_variables.each_with_object({}) do |v, h|
134
- val = raw_story.instance_variable_get(v)
135
- if val.is_a?(DateTime)
136
- h[v.to_s.delete('@')] = val.iso8601
137
- else
138
- h[v.to_s.delete('@')] = val
139
- end
140
- end
141
-
142
- action_callback story
71
+ action_callback story.to_hash
143
72
  end
144
73
 
145
74
  action 'update' do |params|
@@ -155,48 +84,19 @@ Factor::Connector.service 'pivotal_stories' do
155
84
 
156
85
 
157
86
  info 'Initializing Pivotal Tracker Client'
158
- PivotalTracker::Client.token = api_key
159
-
160
- info "Getting project with ID #{project_id.to_s}"
161
- begin
162
- project = PivotalTracker::Project.find(project_id)
163
- rescue
164
- fail "Failed to get the project with id #{project_id.to_s}, check your credentials"
165
- end
166
-
167
- fail "No project with id #{project_id.to_s} found" unless project
168
-
169
- info "Getting story with id #{id.to_s}"
170
- begin
171
- story = project.stories.find(id)
172
- rescue
173
- fail "Failed to get stories, check your credentials and filter"
174
- end
175
-
176
- fail "No stories found" unless story
177
-
178
- fields = %w(name description story_type estimate current_state requested_by owned_by labels jira_id jira_url other_id zendesk_id zendesk_url integration_id deadline)
87
+ client = PivotalApi::Client.new(token: api_key)
88
+
89
+ fields = %w(name description story_type current_state estimate accepted_at deadline requested_by_id owner_ids labels label_ids follower_ids created_at integration_id external_id)
179
90
 
180
- story_fields = params.select do |key, value|
181
- fields.include?(key)
182
- end
91
+ story_fields = params.select { |key, value| fields.include?(key) }
183
92
 
184
93
  begin
185
- new_story = story.update(story_fields)
94
+ story = client.projects.stories.update project_id, id, story_fields
186
95
  rescue
187
96
  fail "Failed to update the story for unknown reason"
188
97
  end
189
98
 
190
- return_story = new_story.instance_variables.each_with_object({}) do |v, h|
191
- val = new_story.instance_variable_get(v)
192
- if val.is_a?(DateTime)
193
- h[v.to_s.delete('@')] = val.iso8601
194
- else
195
- h[v.to_s.delete('@')] = val
196
- end
197
- end
198
-
199
- action_callback return_story
99
+ action_callback story.to_hash
200
100
  end
201
101
 
202
102
  action 'delete' do |params|
@@ -210,47 +110,16 @@ Factor::Connector.service 'pivotal_stories' do
210
110
  fail 'Story ID (id) is required' unless id
211
111
  fail 'Story ID (id) must be an Integer' unless id.is_a?(Integer)
212
112
 
213
-
214
113
  info 'Initializing Pivotal Tracker Client'
215
- PivotalTracker::Client.token = api_key
216
-
217
- info "Getting project with ID #{project_id.to_s}"
218
- begin
219
- project = PivotalTracker::Project.find(project_id)
220
- rescue
221
- fail "Failed to get the project with id #{project_id.to_s}, check your credentials"
222
- end
223
-
224
- fail "No project with id #{project_id.to_s} found" unless project
225
-
226
- info "Getting story with id #{id.to_s}"
114
+ client = PivotalApi::Client.new(token: api_key)
115
+
116
+ info "Deleting story with id #{id.to_s}"
227
117
  begin
228
- story = project.stories.find(id)
118
+ client.projects.stories.delete project_id, id
229
119
  rescue
230
120
  fail "Failed to get stories, check your credentials and filter"
231
121
  end
232
122
 
233
- warn "No stories found" unless story
234
-
235
- if story
236
- begin
237
- new_story = story.delete
238
- rescue
239
- fail "Failed to delete story for unknown reason"
240
- end
241
- else
242
- warn "No stories found, nothing to delete"
243
- end
244
-
245
- return_story = new_story.instance_variables.each_with_object({}) do |v, h|
246
- val = new_story.instance_variable_get(v)
247
- if val.is_a?(DateTime)
248
- h[v.to_s.delete('@')] = val.iso8601
249
- else
250
- h[v.to_s.delete('@')] = val
251
- end
252
- end
253
-
254
- action_callback return_story
123
+ action_callback
255
124
  end
256
125
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factor-connector-pivotal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maciej Skierkowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-09 00:00:00.000000000 Z
11
+ date: 2015-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: factor-connector-api
@@ -25,19 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.0.13
27
27
  - !ruby/object:Gem::Dependency
28
- name: pivotal-tracker
28
+ name: pivotal-api
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.5.12
33
+ version: 0.3.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.5.12
40
+ version: 0.3.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: codeclimate-test-reporter
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -101,7 +101,8 @@ executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
- - lib/factor/connector/pivotal_notes.rb
104
+ - lib/factor/connector/pivotal_comments.rb
105
+ - lib/factor/connector/pivotal_labels.rb
105
106
  - lib/factor/connector/pivotal_projects.rb
106
107
  - lib/factor/connector/pivotal_stories.rb
107
108
  homepage: https://factor.io
@@ -128,3 +129,4 @@ signing_key:
128
129
  specification_version: 4
129
130
  summary: Pivotal Tracker Factor.io Connector
130
131
  test_files: []
132
+ has_rdoc:
@@ -1,176 +0,0 @@
1
- require 'factor-connector-api'
2
- require 'pivotal-tracker'
3
-
4
- Factor::Connector.service 'pivotal_notes' do
5
- action 'get' do |params|
6
- api_key = params['api_key']
7
- project_id = params['project']
8
- story_id = params['story']
9
- id = params['id']
10
-
11
- fail 'API Key (api_key) are required' unless api_key
12
- fail 'Project ID (project) is required' unless project_id
13
- fail 'Project ID (project) must be an integer' unless project_id.is_a?(Integer)
14
- fail 'Story ID (story) is required' unless story_id
15
- fail 'Story ID (story) must be an Integer' unless story_id.is_a?(Integer)
16
- fail 'Note ID (id) is required' unless id
17
- fail 'Note ID (id) must be an integer' unless id.is_a?(Integer)
18
-
19
-
20
- info 'Initializing Pivotal Tracker Client'
21
- PivotalTracker::Client.token = api_key
22
-
23
- info "Getting project with ID #{project_id.to_s}"
24
- begin
25
- project = PivotalTracker::Project.find(project_id)
26
- rescue
27
- fail "Failed to get the project with id #{project_id.to_s}, check your credentials"
28
- end
29
-
30
- fail "No project with id #{project_id.to_s} found" unless project
31
-
32
- info "Getting story with id #{story_id.to_s}"
33
- begin
34
- story = project.stories.find(story_id)
35
- rescue
36
- fail "Failed to get stories, check your credentials"
37
- end
38
-
39
- fail "No stories found" unless story
40
-
41
- info "Getting note with id #{id.to_s}"
42
- begin
43
- raw_note = story.notes.find(id)
44
- rescue
45
- fail "Failed to get note, check your credentials"
46
- end
47
-
48
- fail "No note found" unless raw_note
49
-
50
- return_note = raw_note.instance_variables.each_with_object({}) do |v, h|
51
- val = raw_note.instance_variable_get(v)
52
- if val.is_a?(DateTime)
53
- h[v.to_s.delete('@')] = val.iso8601
54
- else
55
- h[v.to_s.delete('@')] = val
56
- end
57
- end
58
-
59
- action_callback return_note
60
- end
61
-
62
- action 'all' do |params|
63
- api_key = params['api_key']
64
- project_id = params['project']
65
- story_id = params['story']
66
-
67
- fail 'API Key (api_key) are required' unless api_key
68
- fail 'Project ID (project) is required' unless project_id
69
- fail 'Project ID (project) must be an integer' unless project_id.is_a?(Integer)
70
- fail 'Story ID (story) is required' unless story_id
71
- fail 'Story ID (story) must be an Integer' unless story_id.is_a?(Integer)
72
-
73
-
74
- info 'Initializing Pivotal Tracker Client'
75
- PivotalTracker::Client.token = api_key
76
-
77
- info "Getting project with ID #{project_id.to_s}"
78
- begin
79
- project = PivotalTracker::Project.find(project_id)
80
- rescue
81
- fail "Failed to get the project with id #{project_id.to_s}, check your credentials"
82
- end
83
-
84
- fail "No project with id #{project_id.to_s} found" unless project
85
-
86
- info "Getting story with id #{story_id.to_s}"
87
- begin
88
- story = project.stories.find(story_id)
89
- rescue
90
- fail "Failed to get stories, check your credentials"
91
- end
92
-
93
- fail "No stories found" unless story
94
-
95
- info "Getting notes from story"
96
- begin
97
- raw_notes = story.notes.all
98
- rescue
99
- fail "Failed to get note, check your credentials"
100
- end
101
-
102
- fail "No note found" unless raw_notes
103
-
104
- return_notes = raw_notes.map do |raw_note|
105
- raw_note.instance_variables.each_with_object({}) do |v, h|
106
- val = raw_note.instance_variable_get(v)
107
- if val.is_a?(DateTime)
108
- h[v.to_s.delete('@')] = val.iso8601
109
- else
110
- h[v.to_s.delete('@')] = val
111
- end
112
- end
113
- end
114
-
115
- action_callback return_notes
116
- end
117
-
118
- action 'create' do |params|
119
- api_key = params['api_key']
120
- project_id = params['project']
121
- story_id = params['story']
122
-
123
- fail 'API Key (api_key) are required' unless api_key
124
- fail 'Project ID (project_id) is required' unless project_id
125
- fail 'Project ID (project_id) must be an integer' unless project_id.is_a?(Integer)
126
- fail 'Story ID (story) is required' unless story_id
127
- fail 'Story ID (story) must be an Integer' unless story_id.is_a?(Integer)
128
-
129
-
130
- info 'Initializing Pivotal Tracker Client'
131
- PivotalTracker::Client.token = api_key
132
-
133
- info "Getting project with ID #{project_id.to_s}"
134
- begin
135
- project = PivotalTracker::Project.find(project_id)
136
- rescue
137
- fail "Failed to get the project with id #{project_id.to_s}, check your credentials"
138
- end
139
-
140
- fail "No project with id #{project_id.to_s} found" unless project
141
-
142
- info "Getting story with id #{story_id.to_s}"
143
- begin
144
- story = project.stories.find(story_id)
145
- rescue
146
- fail "Failed to get stories, check your credentials"
147
- end
148
-
149
- fail "No stories found" unless story
150
-
151
- fields = %w(text author noted_at)
152
- note_fields = params.select do |key, value|
153
- fields.include?(key)
154
- end
155
-
156
- begin
157
- raw_note = story.notes.create(note_fields)
158
- rescue
159
- fail "Failed to create the note, check the fields"
160
- end
161
-
162
- fail "Failed to create the note" unless raw_note
163
-
164
- return_note = raw_note.instance_variables.each_with_object({}) do |v, h|
165
- val = raw_note.instance_variable_get(v)
166
- if val.is_a?(DateTime)
167
- h[v.to_s.delete('@')] = val.iso8601
168
- else
169
- h[v.to_s.delete('@')] = val
170
- end
171
- end
172
-
173
- action_callback return_note
174
- end
175
-
176
- end