Skip to content

Commit

Permalink
Fix feature flag checks
Browse files Browse the repository at this point in the history
  • Loading branch information
kbukum1 committed Jan 31, 2025
1 parent 64aed8b commit 36e4730
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
48 changes: 32 additions & 16 deletions updater/lib/dependabot/dependency_snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,31 +119,47 @@ def job_group
@dependency_group_engine.find_group(name: T.must(job.dependency_group_to_refresh))
end

sig { params(group: Dependabot::DependencyGroup, excluding_dependencies: T::Hash[String, T::Set[String]]).void }
# rubocop:disable Metrics/PerceivedComplexity
sig do
params(
group: Dependabot::DependencyGroup,
excluding_dependencies: T::Hash[String, T::Set[String]]
)
.void
end
def mark_group_handled(group, excluding_dependencies = {})
Dependabot.logger.info("Marking group '#{group.name}' as handled.")

directories.each do |directory|
@current_directory = directory

# add the existing dependencies in the group so individual updates don't try to update them
dependencies_in_existing_prs = dependencies_in_existing_pr_for_group(group)

dependencies_in_existing_prs = dependencies_in_existing_prs.filter do |dep|
!dep["directory"] || dep["directory"] == directory
if Dependabot::Experiments.enabled?(:allow_refresh_for_existing_pr_dependencies)
# add the existing dependencies in the group so individual updates don't try to update them
dependencies_in_existing_prs = dependencies_in_existing_pr_for_group(group)

dependencies_in_existing_prs = dependencies_in_existing_prs.filter do |dep|
!dep["directory"] || dep["directory"] == directory
end

# also add dependencies that might be in the group, as a rebase would add them;
# this avoids individual PR creation that immediately is superseded by a group PR supersede
current_dependencies = group.dependencies.map(&:name).reject do |dep|
excluding_dependencies[directory]&.include?(dep)
end

add_handled_dependencies(current_dependencies.concat(dependencies_in_existing_prs.filter_map do |dep|
dep["dependency-name"]
end))
else
# add the existing dependencies in the group so individual updates don't try to update them
add_handled_dependencies(dependencies_in_existing_pr_for_group(group).filter_map { |d| d["dependency-name"] })
# also add dependencies that might be in the group, as a rebase would add them;
# this avoids individual PR creation that immediately is superseded by a group PR supersede
add_handled_dependencies(group.dependencies.map(&:name))
end

# also add dependencies that might be in the group, as a rebase would add them;
# this avoids individual PR creation that immediately is superseded by a group PR supersede
current_dependencies = group.dependencies.map(&:name).reject do |dep|
excluding_dependencies[directory]&.include?(dep)
end

add_handled_dependencies(current_dependencies.concat(dependencies_in_existing_prs.filter_map do |dep|
dep["dependency-name"]
end))
end
end
# rubocop:enable Metrics/PerceivedComplexity

sig { params(dependency_names: T.any(String, T::Array[String])).void }
def add_handled_dependencies(dependency_names)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,10 @@ def process_group_dependencies(job_group)

existing_pr_dependencies = {}

enable = Dependabot::Experiments.enabled?(:allow_refresh_for_existing_pr_dependencies)

# Preprocess to discover existing group PRs and add their dependencies to the handled list before processing
# the refresh. This prevents multiple PRs from being created for the same dependency during the refresh.
dependency_snapshot.groups.each do |group|
if enable
if Dependabot::Experiments.enabled?(:allow_refresh_for_existing_pr_dependencies)
# Gather all dependencies in existing PRs so other groups will not consider them as handled when they
# are not also in the PR of the group being checked, preventing erroneous PR closures
group_pr_deps = dependency_snapshot.dependencies_in_existing_pr_for_group(group)
Expand Down

0 comments on commit 36e4730

Please sign in to comment.