kennel 1.68.0 → 1.69.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: cb534c9bfadda4d374201e3e6b00eddbe5596af1376b8e11e071b27c7d1eaa28
4
- data.tar.gz: 33566de8715eb98743470f5d40f9e77744a1932de3900652cf8f01b72ffbe5f6
3
+ metadata.gz: daadbdb69c86de7a0dcdec2bc1eeaedd4b0c2221e2059d241db57e717a8876b6
4
+ data.tar.gz: 1d93147d3d88468564c6c9fcfd0a1fa3926df23d44961b876273e24ac642c851
5
5
  SHA512:
6
- metadata.gz: 57b28c3702ce5bf31b81dcfc104e61cb4ef936564df0575ef65812dc0d2224202c71d120f53b82527464dd50f545388e7d130600941b2fb75e9e2361b1dc499a
7
- data.tar.gz: 97b1954e09f674ce834ad717fa90112f8e1e905d244040b0d2360b41f0bfde0955da5d69a86985964525efd2aa89ee13fdcbd22beffcbea2911aa5a795906788
6
+ metadata.gz: 7737e951ba0e6f34bdec5c4c000e64852acfcc1939d19385a7a92d9b88821c5d6efe0f29f1d8a292692c3ae8b85bd248af0f05ed3e591595da5d2ee41382fd37
7
+ data.tar.gz: 62989fb72a5bc60f052449ecf4d380f59f7e945a8d1857e7f3e789549d8625eac8ffd51c2a946b4f0367cd2d439b2ecb02eb99f79cb42202bb020dadf8a6b612
@@ -19,6 +19,7 @@ module Kennel
19
19
  end
20
20
  @expected.each { |e| add_tracking_id e }
21
21
  calculate_diff
22
+ prevent_irreversible_partial_updates
22
23
  end
23
24
 
24
25
  def plan
@@ -42,7 +43,6 @@ module Kennel
42
43
  Kennel.out.puts "Created #{e.class.api_resource} #{tracking_id(e.as_json)} #{e.url(reply.fetch(:id))}"
43
44
  end
44
45
 
45
- block_irreversible_partial_updates
46
46
  @update.each do |id, e|
47
47
  @api.update e.class.api_resource, id, e.as_json
48
48
  Kennel.out.puts "Updated #{e.class.api_resource} #{tracking_id(e.as_json)} #{e.url(id)}"
@@ -151,7 +151,7 @@ module Kennel
151
151
  return if list.empty?
152
152
  list.each do |_, e, a, diff|
153
153
  api_resource = (e ? e.class.api_resource : a.fetch(:api_resource))
154
- Kennel.out.puts Utils.color(color, "#{step} #{api_resource} #{tracking_id(e&.as_json || a)}")
154
+ Kennel.out.puts Utils.color(color, "#{step} #{api_resource} #{e&.tracking_id || tracking_id(a)}")
155
155
  print_diff(diff) if diff # only for update
156
156
  end
157
157
  end
@@ -159,12 +159,12 @@ module Kennel
159
159
  def print_diff(diff)
160
160
  diff.each do |type, field, old, new|
161
161
  if type == "+"
162
- temp = new.inspect
163
- new = old.inspect
162
+ temp = Utils.pretty_inspect(new)
163
+ new = Utils.pretty_inspect(old)
164
164
  old = temp
165
165
  else # ~ and -
166
- old = old.inspect
167
- new = new.inspect
166
+ old = Utils.pretty_inspect(old)
167
+ new = Utils.pretty_inspect(new)
168
168
  end
169
169
 
170
170
  if (old + new).size > 100
@@ -177,18 +177,30 @@ module Kennel
177
177
  end
178
178
  end
179
179
 
180
- def block_irreversible_partial_updates
180
+ # Do not add tracking-id when working with existing ids on a branch,
181
+ # so resource do not get deleted from merges to master.
182
+ # Also make sure the diff still makes sense, by kicking out the now noop-update.
183
+ #
184
+ # Note: ideally we'd never add tracking in the first place, but at that point we do not know the diff yet
185
+ def prevent_irreversible_partial_updates
181
186
  return unless @project_filter
182
- return if @update.none? do |_, e, _, diff|
183
- e.id && diff.any? do |_, field, old, new = nil|
184
- TRACKING_FIELDS.include?(field.to_sym) && tracking_value(old) != tracking_value(new)
187
+ @update.select! do |_, e, _, diff|
188
+ next true unless e.id # short circuit for performance
189
+
190
+ diff.select! do |field_diff|
191
+ (_, field, old, new) = field_diff
192
+ next true unless tracking_field?(field)
193
+
194
+ if (old_tracking = tracking_value(old))
195
+ old_tracking == tracking_value(new) || raise("do not update! (atm unreachable)")
196
+ else
197
+ field_diff[3] = remove_tracking_id(e) # make plan output match update
198
+ old != field_diff[3]
199
+ end
185
200
  end
201
+
202
+ !diff.empty?
186
203
  end
187
- raise <<~TEXT
188
- Updates with PROJECT= filter should not update tracking id in #{TRACKING_FIELDS.join("/")} of resources with a set `id:`,
189
- since this makes them get deleted by a full update.
190
- Remove the `id:` to test them out, which will result in a copy being created and later deleted.
191
- TEXT
192
204
  end
193
205
 
194
206
  def resolve_linked_tracking_ids(actual)
@@ -212,6 +224,13 @@ module Kennel
212
224
  json[field] = "#{json[field]}\n-- Managed by kennel #{e.tracking_id} in #{e.project.class.file_location}, do not modify manually".lstrip
213
225
  end
214
226
 
227
+ def remove_tracking_id(e)
228
+ json = e.as_json
229
+ field = tracking_field(json)
230
+ value = json[field]
231
+ json[field] = value.dup.sub!(/\n-- Managed by kennel .*/, "") || raise("did not find tracking id in #{value}")
232
+ end
233
+
215
234
  def tracking_id(a)
216
235
  tracking_value a[tracking_field(a)]
217
236
  end
@@ -223,5 +242,9 @@ module Kennel
223
242
  def tracking_field(a)
224
243
  TRACKING_FIELDS.detect { |f| a.key?(f) }
225
244
  end
245
+
246
+ def tracking_field?(field)
247
+ TRACKING_FIELDS.include?(field.to_sym)
248
+ end
226
249
  end
227
250
  end
@@ -142,6 +142,17 @@ module Kennel
142
142
  else []
143
143
  end
144
144
  end
145
+
146
+ # TODO: use awesome-print or similar, but it has too many monkey-patches
147
+ # https://github.com/amazing-print/amazing_print/issues/36
148
+ def pretty_inspect(object)
149
+ string = object.inspect
150
+ string.gsub!(/:([a-z_]+)=>/, "\\1: ")
151
+ 10.times do
152
+ string.gsub!(/{(\S.*?\S)}/, "{ \\1 }") || break
153
+ end
154
+ string
155
+ end
145
156
  end
146
157
  end
147
158
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.68.0"
3
+ VERSION = "1.69.0"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kennel
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.68.0
4
+ version: 1.69.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-11 00:00:00.000000000 Z
11
+ date: 2020-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday