apadmi_grout 2.4.0 → 2.6.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
  SHA256:
3
- metadata.gz: f7b05dbffa45a449751c8ce0eb6a0b8f66e2bf4ef5b9aeaa41617b3af4ea0fde
4
- data.tar.gz: b0b6bd5fbaa0459f2e76f285a521bdafc8e3317e492cd0ea7c4c58f7d5bfb8bb
3
+ metadata.gz: af094b716e2764d75b2f0729c40c82e2bb2ffe13f2775a2e2d6480540c471922
4
+ data.tar.gz: 7ab7d36c4e120a348ee74e2e67386fd1f497d40c5bb684951777edef79caf5c8
5
5
  SHA512:
6
- metadata.gz: 596f948aa2b574e36f3cba0ed4a596332f95f7c24d23c1f817ac1baa851e392ecb67222a7e18e871d1ab2fcd666d4f626944224bc843c576595581db68ef5281
7
- data.tar.gz: a1e727a0b3d8786525a0102cf736a9f50b04f9459edc58c81e418776b83ca913753e575152a92ac91040b98c6e920ed86140edfa43ceaaab24b42a28ec948d72
6
+ metadata.gz: 586a0f1eaf5d0ca433ad18a9c09965da229459bd172a217e04d1ee74a82cfc349cd7841093b40b29f8762bbf37310f3a0a423731bfd1ded2e55697f32663c0a5
7
+ data.tar.gz: f77fb691459927030db6f936f5768aa69fd72b5906c23f044bc8e885a6a7084a9bd20c723a5736008a0f42800d955ffd935e8200200bb8ea9c6ec882bcd92e2f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Core Changelog
2
2
 
3
+ ## [2.6.0] - 2023-09-20
4
+ * Add option to expand ADO tickets with additional information
5
+ * Add ability to assign users to ADO tickets
6
+
7
+ ## [2.5.0] - 2023-09-20
8
+ * Added more options to the ADO queries for more in granular filtering.
9
+
3
10
  ## [2.4.0] - 2023-09-04
4
11
  * No change - keeping version in sync with fastlane plugin.
5
12
 
@@ -4,7 +4,12 @@ module Apadmi
4
4
  module Grout
5
5
  AdoConfig = Struct.new(
6
6
  :flag_tag,
7
+ :expand_type,
7
8
  keyword_init: true
8
- )
9
+ ) do
10
+ def initialize(flag_tag:, expand_type: "none")
11
+ super
12
+ end
13
+ end
9
14
  end
10
15
  end
@@ -25,11 +25,12 @@ module Apadmi
25
25
 
26
26
  # Ado specific find tickets options
27
27
  class AdoFindTicketsOptions < FindTicketsOptions
28
- attr_reader :required_tags, :not_tags
28
+ attr_reader :required_tags, :not_tags, :additional_fields
29
29
 
30
- def initialize(required_tags: [], not_tags: [])
30
+ def initialize(required_tags: [], not_tags: [], additional_fields: {})
31
31
  @required_tags = required_tags
32
32
  @not_tags = not_tags
33
+ @additional_fields = additional_fields
33
34
  end
34
35
 
35
36
  def ==(other)
@@ -37,7 +38,7 @@ module Apadmi
37
38
  end
38
39
 
39
40
  def state
40
- [@required_tags, @not_tags]
41
+ [@required_tags, @not_tags, @additional_fields]
41
42
  end
42
43
  end
43
44
  end
@@ -24,7 +24,7 @@ module Apadmi
24
24
 
25
25
  keys = keys.map { |k| sanitise_key(k) } # Allows supporting raw keys, and keys prefixed with a hash which is common ADO practice
26
26
 
27
- res = @network_service.do_get("/wit/workitems?ids=#{keys.join(",")}&errorPolicy=omit&api-version=7.1-preview.2")
27
+ res = @network_service.do_get("/wit/workitems?ids=#{keys.join(",")}&$expand=#{@ado_config.expand_type}&errorPolicy=omit&api-version=7.1-preview.2")
28
28
  parsed = JSON.parse(res.body)
29
29
  items = parsed["value"]
30
30
 
@@ -40,24 +40,16 @@ module Apadmi
40
40
 
41
41
  # @return [Array<Apadmi::Grout::Issue>]
42
42
  def search_unblocked_issues(component, status, ticket_types = [], options = nil)
43
- tags = (options&.required_tags || []).push(*component).filter { |it| !it.blank? }
44
- not_tags = (options&.not_tags || []).filter { |it| !it.blank? }
45
-
46
- raise "Tags can either be required or not required, not both" unless (tags & not_tags).empty?
47
-
48
- tags_filter = tags.map { |tag| " AND [System.Tags] CONTAINS '#{tag}' " }.join(" ")
49
- not_tags_filter = not_tags.map { |tag| " AND [System.Tags] NOT CONTAINS '#{tag}'" }.join(" ")
50
-
51
43
  status_filter = ("AND [System.State]='#{status}' " unless status.blank?) || ""
52
44
  type_filter = ("AND [System.WorkItemType] IN (#{ticket_types.map { |t| "'#{t}'" }.join(", ")})" unless ticket_types.empty?) || ""
45
+ options_filter = get_options_filter(component, options)
53
46
  wiql = %(
54
47
  Select [System.Id]
55
48
  From WorkItems
56
49
  Where [System.Id] >= 1
57
50
  #{status_filter}
58
- #{tags_filter}
59
- #{not_tags_filter}
60
51
  #{type_filter}
52
+ #{options_filter}
61
53
  )
62
54
 
63
55
  get_issues_by_wiql(wiql)
@@ -90,6 +82,12 @@ module Apadmi
90
82
  @network_service.do_post("/wit/workitems/#{key}/comments?#{API_VERSION_PARAM}-preview.3", payload.to_json)
91
83
  end
92
84
 
85
+ # @param String key
86
+ # @param [Array<Hash>] payload
87
+ def update_ticket(key, payload)
88
+ @network_service.do_patch("/wit/workitems/#{key}?#{API_VERSION_PARAM}", payload.to_json)
89
+ end
90
+
93
91
  # @param [String] key
94
92
  # @param [String] tag
95
93
  def add_tag(key, tag)
@@ -98,7 +96,7 @@ module Apadmi
98
96
  "path" => "/fields/System.Tags",
99
97
  "value" => tag
100
98
  }]
101
- @network_service.do_patch("/wit/workitems/#{key}?#{API_VERSION_PARAM}", payload.to_json)
99
+ update_ticket(key, payload)
102
100
  end
103
101
 
104
102
  # @param [String] key
@@ -112,7 +110,7 @@ module Apadmi
112
110
  "path" => "/fields/System.Tags",
113
111
  "value" => new_tags.join("; ")
114
112
  }]
115
- @network_service.do_patch("/wit/workitems/#{key}?#{API_VERSION_PARAM}", payload.to_json)
113
+ update_ticket(key, payload)
116
114
  end
117
115
 
118
116
  # @param [String] key
@@ -140,7 +138,7 @@ module Apadmi
140
138
  "path" => "/fields/Microsoft.VSTS.Build.IntegrationBuild",
141
139
  "value" => versions.join("; ")
142
140
  }]
143
- @network_service.do_patch("/wit/workitems/#{key}?#{API_VERSION_PARAM}", payload.to_json)
141
+ update_ticket(key, payload)
144
142
  end
145
143
 
146
144
  # @param [String] key
@@ -161,7 +159,27 @@ module Apadmi
161
159
  "path" => "/fields/System.State",
162
160
  "value" => state_name
163
161
  }]
164
- @network_service.do_patch("/wit/workitems/#{key}?#{API_VERSION_PARAM}", payload.to_json)
162
+ update_ticket(key, payload)
163
+ end
164
+
165
+ # @param [String] key
166
+ # @param [String] user
167
+ def assign_to_user(key, user)
168
+ key = sanitise_key(key)
169
+
170
+ payload = if user
171
+ [{
172
+ "op": "add",
173
+ "path": "/fields/System.AssignedTo",
174
+ "value": user
175
+ }]
176
+ else
177
+ [{
178
+ "op": "remove",
179
+ "path": "/fields/System.AssignedTo"
180
+ }]
181
+ end
182
+ update_ticket(key, payload)
165
183
  end
166
184
 
167
185
  # @param [String] key
@@ -194,6 +212,28 @@ module Apadmi
194
212
  ids = items.map { |item| item["id"] } || []
195
213
  find_issues_by_keys(ids)
196
214
  end
215
+
216
+ # @param component [String] Included to be consistent with JIRA, this will boil down to a tag in ADO
217
+ # @param options [Apadmi::Grout::AdoFindTicketsOptions] options as defined to query
218
+
219
+ # @return [String]
220
+ def get_options_filter(component, options = nil)
221
+ tags = (options&.required_tags || []).push(*component).filter { |it| !it.blank? }
222
+ not_tags = (options&.not_tags || []).filter { |it| !it.blank? }
223
+ additional_fields = (options&.additional_fields || {}).reject { |k, _v| k.blank? }
224
+
225
+ raise "Tags can either be required or not required, not both" unless (tags & not_tags).empty?
226
+
227
+ tags_filter = tags.map { |tag| " AND [System.Tags] CONTAINS '#{tag}' " }.join(" ")
228
+ not_tags_filter = not_tags.map { |tag| " AND [System.Tags] NOT CONTAINS '#{tag}'" }.join(" ")
229
+ additional_fields_filter = additional_fields.collect { |k, v| "AND [#{k}]='#{v}'" }.join(" ")
230
+
231
+ %(
232
+ #{tags_filter}
233
+ #{not_tags_filter}
234
+ #{additional_fields_filter}
235
+ )
236
+ end
197
237
  end
198
238
  end
199
239
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Apadmi
4
4
  module Grout
5
- VERSION = "2.4.0"
5
+ VERSION = "2.6.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apadmi_grout
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Apadmi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-04 00:00:00.000000000 Z
11
+ date: 2023-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday