zensana 1.0.0 → 1.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea308a2a19d3adbe4fbd80bca3ddc3a09042668b
4
- data.tar.gz: fa62e437c65bd88ebf8a2ec4ff0d716ae04813f8
3
+ metadata.gz: b18b7ff525379225c8f69bce1b3ea35a6e0d792b
4
+ data.tar.gz: 4a4230204921505fcd69183c7d1d1e61e2edcdd9
5
5
  SHA512:
6
- metadata.gz: d0383bcc73118353f5c0bacf11beb5fd10ce72bd6b663ceafddf5ca521b5a6387d80aec6b221a6646f5104a93ec1bc51fe9e7db65428b71def38b6c11a8132a2
7
- data.tar.gz: 1b81528f9917e9f6982e81355c0fa595711625c26fe286f1ec209920b9b0c5ffef6772d5cd9e890ca8d836e60cbe30e83f0d85939e66e5732175103f76140ebb
6
+ metadata.gz: 01a350826753a4d61e3ac7fe73089540d2745b7c114707e5dafecb383616e95e3aa3cd34b40379977473268c690a2756f6c60d635dafe309f0392a263f62377c
7
+ data.tar.gz: a575ccec62f200adf69cf5a84086d518c4348c9f3368ff28b418c2c480f28af80214bcc59218c08380dde36d9bc41e21be4c360a1919594c0e27da78604f17a1
data/README.md CHANGED
@@ -4,6 +4,8 @@ This gem provides access to the Asana API and ZenDesk Ticket Import API
4
4
  for the purpose of importing tasks from Asana Projects into ZenDesk
5
5
  tickets.
6
6
 
7
+ [![Gem Version](https://badge.fury.io/rb/zensana.svg)](http://badge.fury.io/rb/zensana)
8
+
7
9
  ## Installation
8
10
 
9
11
  Add this line to your application's Gemfile:
@@ -27,12 +27,12 @@ module Zensana
27
27
  end
28
28
 
29
29
  desc 'convert PROJECT', 'Convert PROJECT tasks to ZenDesk tickets (exact ID or NAME required)'
30
- option :attachments, type: 'boolean', aliases: '-a', default: true, desc: 'download and upload any attachments'
31
- option :completed, type: 'boolean', aliases: '-c', default: false, desc: 'include tasks that are completed'
32
- option :default_user, type: 'string', aliases: '-u', default: nil, desc: 'set a default user to assign to tickets'
33
- # option :followers, type: 'boolean', aliases: '-f', default: false, desc: 'add followers of tasks to tickets'
34
- option :stories, type: 'boolean', aliases: '-s', default: true, desc: 'import stories as comments'
35
- option :verified, type: 'boolean', aliases: '-v', default: true, desc: '`false` will send email to zendesk users created'
30
+ option :attachments, type: 'boolean', aliases: '-a', default: true, desc: 'download and upload any attachments'
31
+ option :completed, type: 'boolean', aliases: '-c', default: false, desc: 'include tasks that are completed'
32
+ option :global_tags, type: 'array', aliases: '-t', default: ['zensana'], desc: 'array of tag(s) to be applied to every ticket imported'
33
+ 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'
35
+ option :verified, type: 'boolean', aliases: '-v', default: true, desc: '`false` will send email to zendesk users created'
36
36
  def convert(project)
37
37
  @asana_project = Zensana::Asana::Project.new(project)
38
38
  say <<-BANNER
@@ -60,7 +60,11 @@ using options #{options}
60
60
  # `section_tag_list` holds the tags for the last
61
61
  # section task which are also added to tickets
62
62
  #
63
- tags = [ 'zensana', 'imported' ]
63
+ tags = [ 'imported' ]
64
+ options[:global_tags].each do |t|
65
+ tags << normalize(t)
66
+ end
67
+ puts tags
64
68
  project_tags = [] << tags
65
69
  section_tags = []
66
70
 
@@ -114,10 +118,10 @@ using options #{options}
114
118
  if task.is_section?
115
119
  say "\nProcessing section: #{task.section_name} "
116
120
  section_tags.pop
117
- section_tags.push task.tags << snake_case(task.section_name)
121
+ section_tags.push task.tags << normalize(task.section_name)
118
122
  else
119
123
  say "\nProcessing task: #{task.name} "
120
- project_tags.push snake_case(task.tags)
124
+ project_tags.push normalize(task.tags)
121
125
 
122
126
  if Zensana::Zendesk::Ticket.external_id_exists?(task.id)
123
127
  say "\n >>> skip ticket creation, task already imported ", :yellow
@@ -156,9 +160,10 @@ using options #{options}
156
160
 
157
161
  # if assignee is not an agent then leave unassigned
158
162
  if (assignee_key = options[:default_user] || task.attributes['assignee'])
159
- unless (assignee = asana_to_zendesk_user(assignee_key, false)) &&
160
- (assignee.role != 'end-user')
161
- assignee = nil
163
+ if (assignee = asana_to_zendesk_user(assignee_key, false))
164
+ unless assignee.attributes && assignee.attributes['role'] != 'end-user'
165
+ assignee = nil
166
+ end
162
167
  end
163
168
  end
164
169
 
@@ -176,12 +181,13 @@ using options #{options}
176
181
 
177
182
  Task attributes: #{task.attributes}
178
183
  EOF
179
- :assignee_id => assignee ? assignee.id : '',
184
+ :assignee_id => assignee ? assignee.id : nil,
180
185
  :created_at => task.created_at,
181
186
  :tags => flatten_tags(project_tags, section_tags),
182
187
  :comments => comments
183
188
  )
184
189
  ticket.import
190
+ say "\n >>> ticket imported "
185
191
  end
186
192
 
187
193
  # rinse and repeat for subtasks and their subtasks and ...
@@ -275,19 +281,19 @@ using options #{options}
275
281
  tags.flatten.uniq
276
282
  end
277
283
 
278
- def snake_case(thing)
284
+ def normalize(thing)
279
285
  case
280
286
  when thing.is_a?(String)
281
- snake_case_it thing
287
+ normalize_it thing
282
288
  when thing.is_a?(Array)
283
- thing.map { |a| snake_case a }
289
+ thing.map { |a| normalize a }
284
290
  else
285
- raise ArgumentError, "I don't know how to snake_case instances of #{thing.class}"
291
+ raise ArgumentError, "I don't know how to normalize instances of #{thing.class}"
286
292
  end
287
293
  end
288
294
 
289
- def snake_case_it(thing)
290
- thing.gsub(/(.)([A-Z])/,'\1_\2').gsub(' ', '_').downcase
295
+ def normalize_it(thing)
296
+ thing.gsub(/(\/| |-)+/,'_').downcase
291
297
  end
292
298
  end
293
299
  end
@@ -53,8 +53,9 @@ module Zensana
53
53
 
54
54
  def lookup_by_email(email)
55
55
  unless (user = read_cache(email))
56
- user = search("email:#{email}")
57
- update_cache user
56
+ if (user = search("email:#{email}"))
57
+ update_cache user
58
+ end
58
59
  end
59
60
  user
60
61
  end
@@ -78,7 +79,7 @@ module Zensana
78
79
  end
79
80
 
80
81
  def update_cache(user)
81
- [ :id, :email ].each do |attr|
82
+ [ 'id', 'email' ].each do |attr|
82
83
  key = user[attr].to_s
83
84
  cache[key] = user
84
85
  end
@@ -1,3 +1,3 @@
1
1
  module Zensana
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zensana
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Warren Bain