Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docker/lib/dependabot/docker/file_fetcher.rb
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion docker/lib/dependabot/docker/file_updater.rb
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions docker/lib/dependabot/docker/utils/helpers.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion docker/spec/dependabot/docker/file_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self: this fixture seems to be for all the helm chart tests, so will likely need to refactor things a bit... but no need to fully test that the other filename permutations have exhaustive descriptions as that is the kind of thing that will slow down CI over time... just ensure some basic sanity checking to ensure the updater is picking it up, and then rely on the existing tests to verify that the updater is doing the right thing once it picks it up...

)
end
let(:helmfile_body) { fixture("helm", "yaml", "values.yaml") }
Expand Down
33 changes: 33 additions & 0 deletions docker/spec/dependabot/docker/utils/helpers_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a static method on the class, not sure that this is the proper way to call it? Writing this was a reminder I really need to spend some time on basic ruby syntax tutorials... 😀

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