checkoff 0.175.0 → 0.177.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
  SHA256:
3
- metadata.gz: ad196605a8e7b9fb2a14a28040f8f7ee261f13aed5fa6aec8cfde037c174943d
4
- data.tar.gz: da12083f2d30e975a21464877c8ad47b63c63ea25f05d5599a1944d03c889dbd
3
+ metadata.gz: cbb883b9ef62b4b249ff411385dc4e46c47663f06a139dd30431b00cb959fdf2
4
+ data.tar.gz: f44e6e678f602f63360f84941886da95407b7f606c04ab0524edcac83ee82f2e
5
5
  SHA512:
6
- metadata.gz: b5a8ff3e8f5598e6392c7528057e7d0077bf95f10cab13faaaff4e09a78be8582d64426f27262f01d2568159ef35213ad2fbc2a4b564144f464a9b112ec5aeac
7
- data.tar.gz: 968285c9e60e3543ea60a858c0ab845e889b68fe41b2839f37a4163c893ef79449382299c2e413342740419b7812d7f70e2b3cd07d87f613fad7ad80f671e192
6
+ metadata.gz: f24579a26f058a5e7873d7b6b44cc76d2ab2caa884798e78a2d7e1650bdb3ceb74105126893038f4fe6138a0b5bcf3abbf5adf7f4a30c17df9440ab508ec93c5
7
+ data.tar.gz: '018b8d5246f00654b788f1014983e5b04bcbe79342562e0e93c0338024d85a485176c185eb1669b21955ac97d56e51b7dbee64205015913b8162e782fd9e23e0'
data/Gemfile.lock CHANGED
@@ -12,7 +12,7 @@ GIT
12
12
  PATH
13
13
  remote: .
14
14
  specs:
15
- checkoff (0.175.0)
15
+ checkoff (0.177.0)
16
16
  activesupport
17
17
  asana (> 0.10.0)
18
18
  cache_method
@@ -23,7 +23,7 @@ PATH
23
23
  GEM
24
24
  remote: https://rubygems.org/
25
25
  specs:
26
- activesupport (7.1.2)
26
+ activesupport (7.1.3)
27
27
  base64
28
28
  bigdecimal
29
29
  concurrent-ruby (~> 1.0, >= 1.0.2)
@@ -50,7 +50,7 @@ GEM
50
50
  concurrent-ruby
51
51
  childprocess (4.1.0)
52
52
  coderay (1.1.3)
53
- concurrent-ruby (1.2.2)
53
+ concurrent-ruby (1.2.3)
54
54
  connection_pool (2.4.1)
55
55
  crack (0.4.5)
56
56
  rexml
@@ -114,7 +114,7 @@ GEM
114
114
  mime-types (3.5.1)
115
115
  mime-types-data (~> 3.2015)
116
116
  mime-types-data (3.2023.1205)
117
- minitest (5.20.0)
117
+ minitest (5.21.1)
118
118
  minitest-profile (0.0.2)
119
119
  minitest-reporters (1.6.1)
120
120
  ansi
@@ -18,12 +18,15 @@ module Checkoff
18
18
 
19
19
  # @param filters [Array<Hash>, nil] The filters to match against
20
20
  # @param clients [Checkoff::Clients]
21
+ # @param tasks [Checkoff::Tasks]
21
22
  # @param client [Asana::Client]
22
23
  def initialize(filters:,
23
24
  clients: Checkoff::Clients.new,
25
+ tasks: Checkoff::Tasks.new,
24
26
  client: clients.client)
25
27
  @filters = filters
26
28
  @client = client
29
+ @tasks = tasks
27
30
  end
28
31
 
29
32
  # @param asana_event [Hash] The event that Asana sent
@@ -85,27 +88,43 @@ module Checkoff
85
88
  asana_event.fetch('parent', {})['gid'] == value
86
89
  when 'checkoff:resource.gid'
87
90
  asana_event.fetch('resource', {})['gid'] == value
91
+ when 'checkoff:fetched.section.gid'
92
+ fields = ['memberships.project.gid', 'memberships.project.name',
93
+ 'memberships.section.name', 'assignee', 'assignee_section']
94
+ task = uncached_fetch_task(key, asana_event, fields)
95
+ task_data = @tasks.task_to_h(task)
96
+ task_data.fetch('unwrapped').fetch('membership_by_section_gid').keys.include?(value)
88
97
  when 'checkoff:fetched.completed'
89
- # @type [Hash{String => String}]
90
- # @sg-ignore
91
- resource = asana_event.fetch('resource')
92
- # @type [String]
93
- resource_type = resource.fetch('resource_type')
94
- unless resource_type == 'task'
95
- raise "Teach me how to check #{key.inspect} on resource type #{resource_type.inspect}"
96
- end
97
-
98
- task_gid = resource.fetch('gid')
99
- options = {
100
- fields: ['completed_at'],
101
- }
102
- task = @client.tasks.find_by_id(task_gid, options: options)
98
+ fields = ['completed_at']
99
+ task = uncached_fetch_task(key, asana_event, fields)
103
100
  task_completed = !task.completed_at.nil?
104
101
  task_completed == value
105
102
  else
106
103
  raise "Unknown filter key #{key}"
107
104
  end
108
105
  end
106
+
107
+ # @param key [String]
108
+ # @param asana_event [Hash]
109
+ # @param fields [Array<String>]
110
+ #
111
+ # @return [Asana::Resources::Task]
112
+ def uncached_fetch_task(key, asana_event, fields)
113
+ # @type [Hash{String => String}]
114
+ # @sg-ignore
115
+ resource = asana_event.fetch('resource')
116
+ # @type [String]
117
+ resource_type = resource.fetch('resource_type')
118
+ unless resource_type == 'task'
119
+ raise "Teach me how to check #{key.inspect} on resource type #{resource_type.inspect}"
120
+ end
121
+
122
+ task_gid = resource.fetch('gid')
123
+ options = {
124
+ fields: fields,
125
+ }
126
+ @client.tasks.find_by_id(task_gid, options: options)
127
+ end
109
128
  end
110
129
  end
111
130
  end
@@ -12,7 +12,7 @@ module Checkoff
12
12
  task_hash = task.to_h
13
13
  task_hash['unwrapped'] = {}
14
14
  unwrap_custom_fields(task_hash)
15
- unwrap_memberships(task_hash)
15
+ unwrap_all_memberships(task_hash)
16
16
  task_hash['task'] = task.name
17
17
  task_hash
18
18
  end
@@ -39,15 +39,32 @@ module Checkoff
39
39
  task_hash['unwrapped']['custom_fields'] = unwrapped_custom_fields
40
40
  end
41
41
 
42
+ # @param [Hash<String, Hash, Array>] task_hash
43
+ # @param [Array<Hash>] memberships
44
+ #
45
+ # @return [void]
46
+ def add_user_task_list(task_hash, memberships)
47
+ return unless task_hash.key? 'assignee_section'
48
+
49
+ assignee_section = task_hash.fetch('assignee_section')
50
+ # @type [Hash]
51
+ assignee = task_hash.fetch('assignee')
52
+ memberships << {
53
+ 'section' => assignee_section.dup,
54
+ 'project' => {
55
+ 'gid' => assignee.fetch('gid'),
56
+ 'name' => :my_tasks,
57
+ },
58
+ }
59
+ end
60
+
42
61
  # @param task_hash [Hash]
43
62
  # @param resource [String]
63
+ # @param memberships [Array<Hash>]
44
64
  # @param key [String]
45
65
  #
46
66
  # @return [void]
47
- def unwrap_membership(task_hash, resource, key)
48
- # @sg-ignore
49
- # @type [Array<Hash>]
50
- memberships = task_hash.fetch('memberships', [])
67
+ def unwrap_memberships(task_hash, memberships, resource, key)
51
68
  # @sg-ignore
52
69
  # @type [Hash]
53
70
  unwrapped = task_hash.fetch('unwrapped')
@@ -58,11 +75,15 @@ module Checkoff
58
75
 
59
76
  # @param task_hash [Hash]
60
77
  # @return [void]
61
- def unwrap_memberships(task_hash)
62
- unwrap_membership(task_hash, 'section', 'gid')
63
- unwrap_membership(task_hash, 'section', 'name')
64
- unwrap_membership(task_hash, 'project', 'gid')
65
- unwrap_membership(task_hash, 'project', 'name')
78
+ def unwrap_all_memberships(task_hash)
79
+ # @sg-ignore
80
+ # @type [Array<Hash>]
81
+ memberships = task_hash.fetch('memberships', []).dup
82
+ add_user_task_list(task_hash, memberships)
83
+ unwrap_memberships(task_hash, memberships, 'section', 'gid')
84
+ unwrap_memberships(task_hash, memberships, 'section', 'name')
85
+ unwrap_memberships(task_hash, memberships, 'project', 'gid')
86
+ unwrap_memberships(task_hash, memberships, 'project', 'name')
66
87
  end
67
88
  end
68
89
  end
@@ -3,5 +3,5 @@
3
3
  # Command-line and gem client for Asana (unofficial)
4
4
  module Checkoff
5
5
  # Version of library
6
- VERSION = '0.175.0'
6
+ VERSION = '0.177.0'
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: checkoff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.175.0
4
+ version: 0.177.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vince Broz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-15 00:00:00.000000000 Z
11
+ date: 2024-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport