From f466479502a4ad61e09ca13f506f817381c5cccb Mon Sep 17 00:00:00 2001 From: Jurre Stender Date: Thu, 10 Aug 2023 13:55:17 +0200 Subject: [PATCH 1/2] Update ignore condition table Previously the ignore conditions weren't showing, because we were assuming symbol keys, when these keys are strings and formatted in kebab-case. --- .../pull_request_creator/message_builder.rb | 6 +++--- .../message_builder_spec.rb | 18 ++++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/common/lib/dependabot/pull_request_creator/message_builder.rb b/common/lib/dependabot/pull_request_creator/message_builder.rb index bd8a977afe..7f26ae7127 100644 --- a/common/lib/dependabot/pull_request_creator/message_builder.rb +++ b/common/lib/dependabot/pull_request_creator/message_builder.rb @@ -529,18 +529,18 @@ def ignore_conditions_table # Filter out the conditions where from_config_file is false and dependency is in @dependencies valid_ignore_conditions = @ignore_conditions.select do |ic| - !ic[:from_config_file] && dependencies.any? { |dep| dep.name == ic[:dependency_name] } + ic["source"] == "@dependabot ignore command" && dependencies.any? { |dep| dep.name == ic["dependency-name"] } end # Return an empty string if no valid ignore conditions after filtering return "" if valid_ignore_conditions.empty? # Sort them by updated_at (or created_at if updated_at is nil), taking the latest 20 - sorted_ignore_conditions = valid_ignore_conditions.sort_by { |ic| ic[:updated_at] || ic[:created_at] }.last(20) + sorted_ignore_conditions = valid_ignore_conditions.sort_by { |ic| ic["updated-at"] }.last(20) # Map each condition to a row string table_rows = sorted_ignore_conditions.map do |ic| - "| #{ic[:dependency_name]} | [#{ic[:version_requirement]}] |" + "| #{ic['dependency-name']} | [#{ic['version-requirement']}] |" end summary = "Most Recent Ignore Conditions Applied to This Pull Request" diff --git a/common/spec/dependabot/pull_request_creator/message_builder_spec.rb b/common/spec/dependabot/pull_request_creator/message_builder_spec.rb index 2f9948781c..1af39d1f70 100644 --- a/common/spec/dependabot/pull_request_creator/message_builder_spec.rb +++ b/common/spec/dependabot/pull_request_creator/message_builder_spec.rb @@ -2301,11 +2301,10 @@ def commits_details(base:, head:) ) ignore_conditions.push( { - dependency_name: "business#{i}", - version_requirement: "<= 1.#{i}.0", - from_config_file: false, - updated_at: Time.now, - created_at: Time.now - (i * 86_400) + "dependency-name" => "business#{i}", + "version-requirement" => "<= 1.#{i}.0", + "source" => "@dependabot ignore command", + "updated_at" => Time.now } ) end @@ -2409,11 +2408,10 @@ def commits_details(base:, head:) ) ignore_conditions.push( { - dependency_name: "business#{i}", - version_requirement: "<= 1.#{i}.0", - from_config_file: false, - updated_at: Time.now, - created_at: Time.now - (i * 86_400) + "dependency-name" => "business#{i}", + "version-requirement" => "<= 1.#{i}.0", + "source" => "@dependabot ignore command", + "updated_at" => Time.now } ) end From 7d6b96351e13874b80662a262f42c49eacb08edd Mon Sep 17 00:00:00 2001 From: Jurre Stender Date: Thu, 10 Aug 2023 14:09:27 +0200 Subject: [PATCH 2/2] Use regex match instead of string equality --- common/lib/dependabot/pull_request_creator/message_builder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/lib/dependabot/pull_request_creator/message_builder.rb b/common/lib/dependabot/pull_request_creator/message_builder.rb index 7f26ae7127..b62d38ec6c 100644 --- a/common/lib/dependabot/pull_request_creator/message_builder.rb +++ b/common/lib/dependabot/pull_request_creator/message_builder.rb @@ -529,7 +529,7 @@ def ignore_conditions_table # Filter out the conditions where from_config_file is false and dependency is in @dependencies valid_ignore_conditions = @ignore_conditions.select do |ic| - ic["source"] == "@dependabot ignore command" && dependencies.any? { |dep| dep.name == ic["dependency-name"] } + ic["source"] =~ /\A@dependabot ignore/ && dependencies.any? { |dep| dep.name == ic["dependency-name"] } end # Return an empty string if no valid ignore conditions after filtering