diff --git a/docker/lib/dependabot/docker/file_fetcher.rb b/docker/lib/dependabot/docker/file_fetcher.rb index e0bb1267344..abfb5161718 100644 --- a/docker/lib/dependabot/docker/file_fetcher.rb +++ b/docker/lib/dependabot/docker/file_fetcher.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require "dependabot/docker/utils/helpers" require "dependabot/experiments" require "dependabot/file_fetchers" require "dependabot/file_fetchers/base" @@ -9,7 +10,6 @@ module Docker class FileFetcher < Dependabot::FileFetchers::Base YAML_REGEXP = /^[^\.]+\.ya?ml$/i DOCKER_REGEXP = /dockerfile/i - HELM_REGEXP = /values[\-a-zA-Z_0-9]*\.ya?ml$/i def self.required_files_in?(filenames) filenames.any? { |f| f.match?(DOCKER_REGEXP) } or @@ -86,7 +86,7 @@ def likely_kubernetes_resource?(resource) def correctly_encoded_yamlfiles candidate_files = yamlfiles.select { |f| f.content.valid_encoding? } candidate_files.select do |f| - if f.type == "file" && f.name.match?(HELM_REGEXP) + if f.type == "file" && Utils.likely_helm_chart?(f) true else # This doesn't handle multi-resource files, but it shouldn't matter, since the first resource diff --git a/docker/lib/dependabot/docker/file_updater.rb b/docker/lib/dependabot/docker/file_updater.rb index 05ab0a4d6aa..1ca62e2958b 100644 --- a/docker/lib/dependabot/docker/file_updater.rb +++ b/docker/lib/dependabot/docker/file_updater.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require "dependabot/docker/utils/helpers" require "dependabot/file_updaters" require "dependabot/file_updaters/base" require "dependabot/errors" @@ -152,7 +153,7 @@ def private_registry_url(file) end def updated_yaml_content(file) - updated_content = file.name == "values.yaml" ? update_helm(file) : update_image(file) + updated_content = Utils.likely_helm_chart?(file) ? update_helm(file) : update_image(file) raise "Expected content to change!" if updated_content == file.content diff --git a/docker/lib/dependabot/docker/utils/helpers.rb b/docker/lib/dependabot/docker/utils/helpers.rb new file mode 100644 index 00000000000..f0546e8c373 --- /dev/null +++ b/docker/lib/dependabot/docker/utils/helpers.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Dependabot + module Docker + module Utils + HELM_REGEXP = /values[\-a-zA-Z_0-9]*\.ya?ml$/i + + def self.likely_helm_chart?(file) + file.name.match?(HELM_REGEXP) + end + end + end +end diff --git a/docker/spec/dependabot/docker/file_updater_spec.rb b/docker/spec/dependabot/docker/file_updater_spec.rb index 24b4400ee85..bcdfdc86263 100644 --- a/docker/spec/dependabot/docker/file_updater_spec.rb +++ b/docker/spec/dependabot/docker/file_updater_spec.rb @@ -1139,7 +1139,7 @@ let(:helmfile) do Dependabot::DependencyFile.new( content: helmfile_body, - name: "values.yaml" + name: "values.yaml" # TODO not sure if I need to replace the filenames here or if I can override later in a specific test ) end let(:helmfile_body) { fixture("helm", "yaml", "values.yaml") } diff --git a/docker/spec/dependabot/docker/utils/helpers_spec.rb b/docker/spec/dependabot/docker/utils/helpers_spec.rb new file mode 100644 index 00000000000..7c2d75ce6ac --- /dev/null +++ b/docker/spec/dependabot/docker/utils/helpers_spec.rb @@ -0,0 +1,33 @@ +# # frozen_string_literal: true + +require "dependabot/dependency_file" +require "dependabot/docker/utils/helpers" +require "spec_helper" + +RSpec.describe Dependabot::Docker::Utils.likely_helm_chart? do + describe "#likely_helm_chart?" do + matching_filenames = [ + "other-values.yml", + "other-values.yaml", + "other_values.yml", + "other_values.yaml", + "values.yml", + "values.yaml", + "values-other.yml", + "values-other.yaml", + "values_other.yml", + "values_other.yaml", + "values2.yml", + "values2.yaml" + ] + matching_filenames.each do |fname| + it "should return `true` for matching value '#{fname}'" do + fake_file = Dependabot::DependencyFile.new( + name: fname, + content: "fake content" + ) + expect(self.likely_helm_chart?(fake_file)).to be true + end + end + end +end