lib/command/base.rb in cpl-1.0.4 vs lib/command/base.rb in cpl-1.1.0

- old
+ new

@@ -204,11 +204,11 @@ cp.delete_workload(workload) end end def latest_image_from(items, app_name: config.app, name_only: true) - matching_items = items.filter { |item| item["name"].start_with?("#{app_name}:") } + matching_items = items.select { |item| item["name"].start_with?("#{app_name}:") } # Or special string to indicate no image available if matching_items.empty? name_only ? "#{app_name}:#{NO_IMAGE_AVAILABLE}" : nil else @@ -219,23 +219,29 @@ def latest_image(app = config.app, org = config.org) @latest_image ||= {} @latest_image[app] ||= begin - items = cp.image_query(app, org)["items"] + items = cp.query_images(app, org)["items"] latest_image_from(items, app_name: app) end end - def latest_image_next(app = config.app, org = config.org) + def latest_image_next(app = config.app, org = config.org, commit: nil) + commit ||= config.options[:commit] + @latest_image_next ||= {} @latest_image_next[app] ||= begin latest_image_name = latest_image(app, org) image = latest_image_name.split(":").first image += ":#{extract_image_number(latest_image_name) + 1}" - image += "_#{config.options[:commit]}" if config.options[:commit] + image += "_#{commit}" if commit image end + end + + def extract_image_commit(image_name) + image_name.match(/_(\h+)$/)&.captures&.first end # NOTE: use simplified variant atm, as shelljoin do different escaping # TODO: most probably need better logic for escaping various quotes def args_join(args)