Skip to content

Commit

Permalink
Fix for group PRs being closed on refresh when nothing has changed (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhys Koedijk authored Jul 22, 2024
1 parent d8cf1c0 commit 512ac38
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions updater/lib/tinglesoftware/dependabot/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,30 @@ def initialize(azure_client: nil, experiments: nil)
)
end

def for_pull_request_update(dependency_names: nil, dependency_group_name: nil)
@updating_a_pull_request = true
@dependencies = dependency_names
@dependency_group_to_refresh = dependency_group_name
self
end

#
# Reconfigure the job to update all dependencies.
# The job will focus on creating new pull requests for all discovered dependencies.
# This is the default configuration when a job is created.
#
def for_all_updates(dependency_names: nil)
@updating_a_pull_request = false
@dependencies = dependency_names || []
@dependency_group_to_refresh = nil
@existing_pull_requests = _existing_pull_requests
@existing_group_pull_requests = _existing_group_pull_requests
self
end

#
# Reconfigure the job to update a single pull request.
# The job will focus on updating or closing any existing pull request with the given dependencies or group name.
#
def for_pull_request_update(dependency_names: nil, dependency_group_name: nil)
@updating_a_pull_request = true
@dependencies = dependency_names
@dependency_group_to_refresh = dependency_group_name
@existing_pull_requests = _existing_pull_requests
@existing_group_pull_requests = _existing_group_pull_requests
self
end

Expand Down Expand Up @@ -346,11 +359,21 @@ def azure_merge_strategy
end

def _existing_pull_requests
open_pull_requests.filter_map { |pr| pr["updated_dependencies"] }.select { |d| d.is_a?(Array) }
open_pull_requests.filter_map { |pr| pr["updated_dependencies"] }
.select { |d| d.is_a?(Array) }
end

def _existing_group_pull_requests
open_pull_requests.filter_map { |pr| pr["updated_dependencies"] }.select { |d| d.is_a?(Hash) }
update_group_name = dependency_group_to_refresh
open_pull_requests.filter_map { |pr| pr["updated_dependencies"] }
.select { |d| d.is_a?(Hash) }
# If we are updating an existing group PR, we must only return PRs that match the group name
# of the current job. This is because "refresh_group_update_pull_request.rb" will mark all
# dependencies of all other group PRs as "handled" to prevent multiple PRs from being reated
# during the refresh. However, when we operate in the "do everything in a single job" mode,
# this has the side effect of causing Dependabot to think the other group PRs have already
# been handled; it then closes them with "update_no_longer_possible". We don't want this.
.select { |d| update_group_name.nil? || d["dependency-group-name"] == update_group_name }
end

def existing_pull_request_with_updated_dependencies(updated_dependencies)
Expand Down

0 comments on commit 512ac38

Please sign in to comment.