zensana 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b94c9bb7aedae5805ed90054a3a565bb872d4c73
4
- data.tar.gz: bfc11506fedbc028540e80e809dcd6ff58b2def4
3
+ metadata.gz: 1832214144fb9cf8e0af229da4ad08ca2f3977e8
4
+ data.tar.gz: 7887bc8414164f1945aefb1c1a3c7b877330c8ad
5
5
  SHA512:
6
- metadata.gz: 4e9f316b42b0ab2bfca14c28d8b31fdf88ad6cf3273cc6dbb06dd62e39bd6e9551ad3878a4465dea6b6ef536839fc68d8719a81b3b9251e1c8a5b70c7228ecd3
7
- data.tar.gz: 9c9dba2fd5d2f4bab8b28c36f60adabdf29cc655932802791ab8c122e378e27a0921147cf40c507c0ec534398ecc76f45b77b7507af7df2a38969dbbc3663266
6
+ metadata.gz: 979c0c4796428272d3fa60676b28c344fde588686b1f98e7cd2a690e0d0de45ba3f1f5bd82ff6b282b02d5b87c760d8e12c8815f49b9f099c1dc1976e962b7cf
7
+ data.tar.gz: df196da8ba97fe840b8903e184f66b47342d329f9449a37f1427af4169995faa2c6d1dafc62c36078138e6ac05d26e08ecaf66c29b0dfcd7fb574820324280f5
@@ -1,3 +1,5 @@
1
+ require 'pry'
2
+
1
3
  module Zensana
2
4
  class Command::Project < Zensana::Command
3
5
 
@@ -31,7 +33,7 @@ module Zensana
31
33
  option :completed, type: 'boolean', aliases: '-c', default: false, desc: 'include tasks that are completed'
32
34
  option :global_tags, type: 'array', aliases: '-t', default: ['zensana'], desc: 'array of tag(s) to be applied to every ticket imported'
33
35
  option :stories, type: 'boolean', aliases: '-s', default: true, desc: 'import stories as comments'
34
- option :default_user, type: 'string', aliases: '-u', default: nil, desc: 'set a default user to assign to tickets'
36
+ option :default_user, type: 'string', aliases: '-u', default: nil, desc: 'set a default user to assign to invalid asana user items'
35
37
  option :verified, type: 'boolean', aliases: '-v', default: true, desc: '`false` will send email to zendesk users created'
36
38
  def convert(project)
37
39
  @asana_project = Zensana::Asana::Project.new(project)
@@ -51,6 +53,16 @@ using options #{options}
51
53
  exit
52
54
  end
53
55
 
56
+ if options[:default_user]
57
+ default_user = Zensana::Zendesk::User.new
58
+ if default_user.find(options[:default_user])
59
+ options[:default_user] = default_user
60
+ else
61
+ say "\nDefault user '#{options[:default_user]}' does not exist in ZenDesk!\n", :red
62
+ exit(1)
63
+ end
64
+ end
65
+
54
66
  # LIFO tags for recursive tagging
55
67
  #
56
68
  # `project_tag_list` holds the project tags
@@ -110,6 +122,9 @@ using options #{options}
110
122
  if task.attributes['completed'] && !options[:completed]
111
123
  say "\nSkipping completed task: #{task.name}! ", :yellow
112
124
  return
125
+ elsif task.attributes['name'].nil? || task.attributes['name'].empty?
126
+ say "\nSkipping blank task: #{task.id}! ", :yellow
127
+ return
113
128
  end
114
129
 
115
130
  # sections contribute their tags but nothing else
@@ -171,13 +186,13 @@ using options #{options}
171
186
 
172
187
  Task attributes: #{task.attributes}
173
188
  EOF
174
- :assignee_id => zendesk_assignee_id(task),
189
+ :assignee_id => zendesk_assignee_id(task.attributes['assignee']),
175
190
  :created_at => task.created_at,
176
191
  :tags => flatten_tags(project_tags, section_tags),
177
192
  :comments => comments
178
193
  )
179
194
  ticket.import
180
- say "\n >>> ticket imported "
195
+ say "\n >>> ticket successfully imported ", :green
181
196
  end
182
197
 
183
198
  # rinse and repeat for subtasks and their subtasks and ...
@@ -194,42 +209,44 @@ using options #{options}
194
209
 
195
210
  # lookup up asana user on zendesk and
196
211
  # optionally create new if not exists
212
+ # NOTE: if asana user is invalid we
213
+ # must substitute the default user
197
214
  #
198
215
  # return: zendesk user or nil
199
216
  #
200
217
  def asana_to_zendesk_user(spec, create)
201
218
  key = spec.is_a?(Hash) ? spec['id'] : spec
202
219
  asana = Zensana::Asana::User.new(key)
203
- zendesk = Zensana::Zendesk::User.new
204
- zendesk.find(asana.email)
205
- rescue NotFound
206
- if create
207
- zendesk.create(
208
- :email => asana.email,
209
- :name => asana.name,
210
- :verified => options[:verified]
211
- )
212
- zendesk
220
+ unless asana.attributes['email']
221
+ raise NotFound, "Invalid asana email in #{asana}; please provide 'default_user' option" unless options[:default_user]
222
+ zendesk = options[:default_user]
213
223
  else
214
- nil
224
+ zendesk = Zensana::Zendesk::User.new
225
+ unless zendesk.find(asana.email)
226
+ if create
227
+ zendesk.create(
228
+ :email => asana.email,
229
+ :name => asana.name,
230
+ :verified => options[:verified]
231
+ )
232
+ else
233
+ zendesk = nil
234
+ end
235
+ end
215
236
  end
216
- else
217
237
  zendesk
218
238
  end
219
239
 
220
- # lookup the asana task assignee in zendesk and
240
+ # lookup the asana user in zendesk and
221
241
  # return their id if they are an agent or admin
222
242
  #
223
- def zendesk_assignee_id(task)
224
- assignee_id = nil
225
- if (assignee_key = options[:default_user] || task.attributes['assignee'])
226
- if (assignee = asana_to_zendesk_user(assignee_key, false))
227
- if assignee.attributes && assignee.attributes['role'] != 'end-user'
228
- assignee_id = assignee.attributes['id']
229
- end
243
+ def zendesk_assignee_id(asana_user_id)
244
+ if (assignee = asana_to_zendesk_user(asana_user_id, false))
245
+ if assignee.attributes && assignee.attributes['role'] != 'end-user'
246
+ assignee_id = assignee.attributes['id']
230
247
  end
231
248
  end
232
- assignee_id
249
+ assignee_id || (options[:default_user] ? options[:default_user].attributes['id'] : nil)
233
250
  end
234
251
 
235
252
  # download the attachments to the local file system
@@ -264,10 +281,15 @@ using options #{options}
264
281
  [].tap do |tokens|
265
282
  attachments.each do |attachment|
266
283
  tries = 3
284
+ file = attachment.full_path
267
285
  begin
268
286
  uploader = Zensana::Zendesk::Attachment.new
269
- tokens << uploader.upload(attachment.full_path)['token']
270
- print '.'
287
+ if uploader.too_big?(file)
288
+ say "\n --> skip: #{file} exceeds filesize limit! ", :red
289
+ else
290
+ tokens << uploader.upload(attachment.full_path)['token']
291
+ print '.'
292
+ end
271
293
  rescue
272
294
  retry unless (tries-= 1).zero?
273
295
  raise
@@ -3,6 +3,8 @@ module Zensana
3
3
  class Attachment
4
4
  include Zensana::Zendesk::Access
5
5
 
6
+ MAX_ATTACHMENT_SIZE = 2*10**6
7
+
6
8
  attr_reader :attributes
7
9
 
8
10
  def initialize
@@ -13,6 +15,10 @@ module Zensana
13
15
  @attributes = upload_file(filename)
14
16
  end
15
17
 
18
+ def too_big?(file)
19
+ File.size(file).to_f > MAX_ATTACHMENT_SIZE
20
+ end
21
+
16
22
  def method_missing(name, *args, &block)
17
23
  attributes[name.to_s] || super
18
24
  end
@@ -21,9 +21,8 @@ module Zensana
21
21
 
22
22
  def create(attributes)
23
23
  validate_keys attributes
24
- email = attributes['email'] || attributes['user']['email']
25
- raise AlreadyExists, "User '#{email}' already exists" if lookup_by_email(email)
26
- rescue NotFound
24
+ email = attributes['email'] || (attributes['user'] && attributes['user']['email'])
25
+ raise AlreadyExists, "User '#{email}' already exists" if email && lookup_by_email(email)
27
26
  user = create_user(attributes)
28
27
  update_cache user
29
28
  @attributes = user
@@ -3,7 +3,7 @@ require 'httmultiparty'
3
3
  module Zensana
4
4
  class Zendesk
5
5
  include HTTMultiParty
6
- default_timeout 10
6
+ default_timeout 20
7
7
  #debug_output
8
8
 
9
9
  def self.inst
@@ -1,3 +1,3 @@
1
1
  module Zensana
2
- VERSION = "1.1.2"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zensana
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Warren Bain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-21 00:00:00.000000000 Z
11
+ date: 2015-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httmultiparty