Skip to content

Commit

Permalink
Revert Changes to updated_files_regex method with latest regex from t…
Browse files Browse the repository at this point in the history
…he API (#10457)

* reverted changes to updated_files_regex and match it with latest regex from api
  • Loading branch information
honeyankit authored Aug 17, 2024
1 parent 3e52778 commit 02f7d23
Show file tree
Hide file tree
Showing 37 changed files with 160 additions and 245 deletions.
25 changes: 7 additions & 18 deletions bundler/lib/dependabot/bundler/file_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,13 @@ class FileUpdater < Dependabot::FileUpdaters::Base
require_relative "file_updater/gemspec_updater"
require_relative "file_updater/lockfile_updater"

def self.updated_files_regex(allowlist_enabled = false)
if allowlist_enabled
[
# Matches Gemfile, Gemfile.lock, gems.rb, gems.locked, .gemspec files, and anything in vendor directory
%r{^(Gemfile(\.lock)?|gems\.(rb|locked)|.*\.gemspec|vendor/.*)$},
# Matches the same files in any subdirectory
%r{^.*\/(Gemfile|Gemfile\.lock|gems\.rb|gems\.locked)$}
]
else
# Old regex. After 100% rollout of the allowlist, this will be removed.
[
/^Gemfile$/,
/^Gemfile\.lock$/,
/^gems\.rb$/,
/^gems\.locked$/,
/^*\.gemspec$/
]
end
def self.updated_files_regex
[
# Matches Gemfile, Gemfile.lock, gems.rb, gems.locked, .gemspec files, and anything in vendor directory
%r{^(Gemfile(\.lock)?|gems\.(rb|locked)|.*\.gemspec|vendor/.*)$},
# Matches the same files in any subdirectory
%r{^.*/(Gemfile|Gemfile\.lock|gems\.rb|gems\.locked)$}
]
end

# rubocop:disable Metrics/PerceivedComplexity
Expand Down
4 changes: 1 addition & 3 deletions bundler/spec/dependabot/bundler/file_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@
it_behaves_like "a dependency file updater"

describe "#updated_files_regex" do
subject(:updated_files_regex) { described_class.updated_files_regex(allowlist_enabled) }

let(:allowlist_enabled) { true }
subject(:updated_files_regex) { described_class.updated_files_regex }

it "is not empty" do
expect(updated_files_regex).not_to be_empty
Expand Down
6 changes: 3 additions & 3 deletions cargo/lib/dependabot/cargo/file_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class FileUpdater < Dependabot::FileUpdaters::Base
require_relative "file_updater/manifest_updater"
require_relative "file_updater/lockfile_updater"

def self.updated_files_regex(_ = false)
def self.updated_files_regex
[
/^Cargo\.toml$/,
/^Cargo\.lock$/
/Cargo\.toml$/, # Matches Cargo.toml in the root directory or any subdirectory
/Cargo\.lock$/ # Matches Cargo.lock in the root directory or any subdirectory
]
end

Expand Down
10 changes: 6 additions & 4 deletions cargo/spec/dependabot/cargo/file_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@
it_behaves_like "a dependency file updater"

describe "#updated_files_regex" do
subject(:updated_files_regex) { described_class.updated_files_regex(allowlist_enabled) }

let(:allowlist_enabled) { false } # default value
subject(:updated_files_regex) { described_class.updated_files_regex }

it "is not empty" do
expect(updated_files_regex).not_to be_empty
Expand All @@ -68,7 +66,11 @@
it "returns true for files that should be updated" do
matching_files = [
"Cargo.toml",
"Cargo.lock"
"Cargo.lock",
"some_project/Cargo.toml",
"some_project/Cargo.lock",
"some_project/subdir/Cargo.toml",
"some_project/subdir/Cargo.lock"
]

matching_files.each do |file_name|
Expand Down
4 changes: 2 additions & 2 deletions common/lib/dependabot/file_updaters/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class Base
sig { returns(T::Hash[Symbol, T.untyped]) }
attr_reader :options

sig { overridable.params(allowlist_enabled: T::Boolean).returns(T::Array[Regexp]) }
def self.updated_files_regex(allowlist_enabled = false)
sig { overridable.returns(T::Array[Regexp]) }
def self.updated_files_regex
raise NotImplementedError
end

Expand Down
2 changes: 1 addition & 1 deletion composer/lib/dependabot/composer/file_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class FileUpdater < Dependabot::FileUpdaters::Base
require_relative "file_updater/manifest_updater"
require_relative "file_updater/lockfile_updater"

def self.updated_files_regex(_ = false)
def self.updated_files_regex
[
/^composer\.json$/,
/^composer\.lock$/
Expand Down
4 changes: 1 addition & 3 deletions composer/spec/dependabot/composer/file_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@
it_behaves_like "a dependency file updater"

describe "#updated_files_regex" do
subject(:updated_files_regex) { described_class.updated_files_regex(allowlist_enabled) }

let(:allowlist_enabled) { false } # default value
subject(:updated_files_regex) { described_class.updated_files_regex }

it "is not empty" do
expect(updated_files_regex).not_to be_empty
Expand Down
4 changes: 2 additions & 2 deletions devcontainers/lib/dependabot/devcontainers/file_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ module Devcontainers
class FileUpdater < Dependabot::FileUpdaters::Base
extend T::Sig

sig { override.params(_: T::Boolean).returns(T::Array[Regexp]) }
def self.updated_files_regex(_ = false)
sig { override.returns(T::Array[Regexp]) }
def self.updated_files_regex
[
/^\.?devcontainer\.json$/,
/^\.?devcontainer-lock\.json$/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
it_behaves_like "a dependency file updater"

describe "#updated_files_regex" do
subject(:updated_files_regex) { described_class.updated_files_regex(allowlist_enabled) }

let(:allowlist_enabled) { false } # default value
subject(:updated_files_regex) { described_class.updated_files_regex }

it "is not empty" do
expect(updated_files_regex).not_to be_empty
Expand Down
4 changes: 2 additions & 2 deletions docker/lib/dependabot/docker/file_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class FileUpdater < Dependabot::FileUpdaters::Base
YAML_REGEXP = /^[^\.].*\.ya?ml$/i
DOCKER_REGEXP = /dockerfile/i

sig { override.params(_: T::Boolean).returns(T::Array[Regexp]) }
def self.updated_files_regex(_ = false)
sig { override.returns(T::Array[Regexp]) }
def self.updated_files_regex
[
DOCKER_REGEXP,
YAML_REGEXP
Expand Down
4 changes: 1 addition & 3 deletions docker/spec/dependabot/docker/file_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@
it_behaves_like "a dependency file updater"

describe "#updated_files_regex" do
subject(:updated_files_regex) { described_class.updated_files_regex(allowlist_enabled) }

let(:allowlist_enabled) { false } # default value
subject(:updated_files_regex) { described_class.updated_files_regex }

it "is not empty" do
expect(updated_files_regex).not_to be_empty
Expand Down
2 changes: 1 addition & 1 deletion elm/lib/dependabot/elm/file_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Elm
class FileUpdater < Dependabot::FileUpdaters::Base
require_relative "file_updater/elm_json_updater"

def self.updated_files_regex(_ = false)
def self.updated_files_regex
[
/^elm\.json$/
]
Expand Down
4 changes: 1 addition & 3 deletions elm/spec/dependabot/elm/file_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@
it_behaves_like "a dependency file updater"

describe "#updated_files_regex" do
subject(:updated_files_regex) { described_class.updated_files_regex(allowlist_enabled) }

let(:allowlist_enabled) { false } # default value
subject(:updated_files_regex) { described_class.updated_files_regex }

it "is not empty" do
expect(updated_files_regex).not_to be_empty
Expand Down
17 changes: 5 additions & 12 deletions git_submodules/lib/dependabot/git_submodules/file_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,11 @@ module GitSubmodules
class FileUpdater < Dependabot::FileUpdaters::Base
extend T::Sig

sig { override.params(allowlist_enabled: T::Boolean).returns(T::Array[Regexp]) }
def self.updated_files_regex(allowlist_enabled = false)
if allowlist_enabled
[
/^\.gitmodules$/, # Matches the .gitmodules file in the root directory
%r{^.+/\.git$}, # Matches the .git file inside any submodule directory
%r{^\.git/modules/.+} # Matches any files under .git/modules directory where submodule data is stored
]
else
# Old regex. After 100% rollout of the allowlist, this will be removed.
[]
end
sig { override.returns(T::Array[Regexp]) }
def self.updated_files_regex
[
/^.*/
]
end

sig { override.returns(T::Array[Dependabot::DependencyFile]) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@
it_behaves_like "a dependency file updater"

describe "#updated_files_regex" do
subject(:updated_files_regex) { described_class.updated_files_regex(allowlist_enabled) }

let(:allowlist_enabled) { true }
subject(:updated_files_regex) { described_class.updated_files_regex }

it "is not empty" do
expect(updated_files_regex).not_to be_empty
Expand All @@ -88,21 +86,6 @@
expect(updated_files_regex).to(be_any { |regex| file_name.match?(regex) })
end
end

it "returns false for files that should not be updated" do
non_matching_files = [
"README.md",
".github/workflow/main.yml",
"some_random_file.rb",
"requirements.txt",
"package-lock.json",
"package.json"
]

non_matching_files.each do |file_name|
expect(updated_files_regex).not_to(be_any { |regex| file_name.match?(regex) })
end
end
end
end

Expand Down
17 changes: 9 additions & 8 deletions github_actions/lib/dependabot/github_actions/file_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ module GithubActions
class FileUpdater < Dependabot::FileUpdaters::Base
extend T::Sig

sig { override.params(allowlist_enabled: T::Boolean).returns(T::Array[Regexp]) }
def self.updated_files_regex(allowlist_enabled = false)
if allowlist_enabled
[%r{\.github/workflows?/.+\.ya?ml$}]
else
# Old regex. After 100% rollout of the allowlist, this will be removed.
[%r{\.github/workflows/.+\.ya?ml$}]
end
sig { override.returns(T::Array[Regexp]) }
def self.updated_files_regex
[
# Matches .yml or .yaml files in the .github/workflows directories
%r{\.github/workflows/.+\.ya?ml$},

# Matches .yml or .yaml files in the root directory or any subdirectory
%r{(?:^|/).+\.ya?ml$}
]
end

sig { override.returns(T::Array[Dependabot::DependencyFile]) }
Expand Down
15 changes: 10 additions & 5 deletions github_actions/spec/dependabot/github_actions/file_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@
it_behaves_like "a dependency file updater"

describe "#updated_files_regex" do
subject(:updated_files_regex) { described_class.updated_files_regex(allowlist_enabled) }

let(:allowlist_enabled) { true }
subject(:updated_files_regex) { described_class.updated_files_regex }

it "is not empty" do
expect(updated_files_regex).not_to be_empty
Expand All @@ -80,9 +78,16 @@
context "when files match the regex patterns" do
it "returns true for files that should be updated" do
matching_files = [
".github/workflow/main.yml",
"action.yml",
"action.yaml",
"foo/bar/action.yml",
"foo/bar/action.yaml",
".github/workflows/main.yml",
".github/workflows/ci-test.yaml",
".github/workflows/workflow.yml"
".github/workflows/action.yml",
".github/workflows/123-foo.yml",
"/.github/workflows/workflow.yml",
"/.github/workflows/123-foo-bar.yml"
]

matching_files.each do |file_name|
Expand Down
22 changes: 7 additions & 15 deletions go_modules/lib/dependabot/go_modules/file_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,13 @@ def initialize(dependencies:, dependency_files:, credentials:, repo_contents_pat
use_repo_contents_stub if repo_contents_path.nil?
end

sig { override.params(allowlist_enabled: T::Boolean).returns(T::Array[Regexp]) }
def self.updated_files_regex(allowlist_enabled = false)
if allowlist_enabled
[
/^go\.mod$/,
/^go\.sum$/,
%r{^vendor/.*}
]
else
# Old regex. After 100% rollout of the allowlist, this will be removed.
[
/^go\.mod$/,
/^go\.sum$/
]
end
sig { override.returns(T::Array[Regexp]) }
def self.updated_files_regex
[
/^go\.mod$/,
/^go\.sum$/,
%r{^vendor/.*}
]
end

sig { override.returns(T::Array[Dependabot::DependencyFile]) }
Expand Down
4 changes: 1 addition & 3 deletions go_modules/spec/dependabot/go_modules/file_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@
it_behaves_like "a dependency file updater"

describe "#updated_files_regex" do
subject(:updated_files_regex) { described_class.updated_files_regex(allowlist_enabled) }

let(:allowlist_enabled) { true }
subject(:updated_files_regex) { described_class.updated_files_regex }

it "is not empty" do
expect(updated_files_regex).not_to be_empty
Expand Down
23 changes: 11 additions & 12 deletions gradle/lib/dependabot/gradle/file_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@ class FileUpdater < Dependabot::FileUpdaters::Base

SUPPORTED_BUILD_FILE_NAMES = %w(build.gradle build.gradle.kts).freeze

def self.updated_files_regex(allowlist_enabled = false)
if allowlist_enabled
[
# Matches build.gradle or build.gradle.kts in root directory
%r{(^|.*/)build\.gradle(\.kts)?$},
# Matches gradle/libs.versions.toml in root or any subdirectory
%r{(^|.*/)?gradle/libs\.versions\.toml$}
]
else
# Old regex. After 100% rollout of the allowlist, this will be removed.
[/^build\.gradle(\.kts)?$/, %r{/build\.gradle(\.kts)?$}, %r{/gradle/libs\.versions\.toml$}]
end
def self.updated_files_regex
[
# Matches build.gradle or build.gradle.kts in root directory
%r{(^|.*/)build\.gradle(\.kts)?$},
# Matches gradle/libs.versions.toml in root or any subdirectory
%r{(^|.*/)?gradle/libs\.versions\.toml$},
# Matches settings.gradle or settings.gradle.kts in root or any subdirectory
%r{(^|.*/)settings\.gradle(\.kts)?$},
# Matches dependencies.gradle in root or any subdirectory
%r{(^|.*/)dependencies\.gradle$}
]
end

def updated_dependency_files
Expand Down
12 changes: 8 additions & 4 deletions gradle/spec/dependabot/gradle/file_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@
it_behaves_like "a dependency file updater"

describe "#updated_files_regex" do
subject(:updated_files_regex) { described_class.updated_files_regex(allowlist_enabled) }

let(:allowlist_enabled) { true }
subject(:updated_files_regex) { described_class.updated_files_regex }

it "is not empty" do
expect(updated_files_regex).not_to be_empty
Expand All @@ -67,10 +65,16 @@
matching_files = [
"build.gradle",
"build.gradle.kts",
"settings.gradle",
"settings.gradle.kts",
"subproject/build.gradle",
"subproject/build.gradle.kts",
"subproject/settings.gradle",
"subproject/settings.gradle.kts",
"gradle/libs.versions.toml",
"subproject/gradle/libs.versions.toml"
"subproject/gradle/libs.versions.toml",
"dependencies.gradle",
"subproject/dependencies.gradle"
]

matching_files.each do |file_name|
Expand Down
Loading

0 comments on commit 02f7d23

Please sign in to comment.