Skip to content

Commit

Permalink
added feature support for unignore_commands
Browse files Browse the repository at this point in the history
  • Loading branch information
honeyankit committed Jul 31, 2023
1 parent 237e0b0 commit ca4115b
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 6 deletions.
24 changes: 19 additions & 5 deletions common/lib/dependabot/pull_request_creator/message_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,31 @@ def pr_name
end

def pr_message
msg = "#{suffixed_pr_message_header}" \
"#{commit_message_intro}" \
"#{metadata_cascades}" \
"#{ignore_conditions_table}" \
"#{prefixed_pr_message_footer}"
# TODO: Remove unignore_commands? feature flag once we are confident
# that it is working as expected
msg = if unignore_commands?
"#{suffixed_pr_message_header}" \
"#{commit_message_intro}" \
"#{metadata_cascades}" \
"#{ignore_conditions_table}" \
"#{prefixed_pr_message_footer}"
else
"#{suffixed_pr_message_header}" \
"#{commit_message_intro}" \
"#{metadata_cascades}" \
"#{prefixed_pr_message_footer}"
end

truncate_pr_message(msg)
rescue StandardError => e
Dependabot.logger.error("Error while generating PR message: #{e.message}")
suffixed_pr_message_header + prefixed_pr_message_footer
end

def unignore_commands?
Experiments.enabled?(:unignore_commands)
end

# Truncate PR message as determined by the pr_message_max_length and pr_message_encoding instance variables
# The encoding is used when calculating length, all messages are returned as ruby UTF_8 encoded string
def truncate_pr_message(msg)
Expand Down
105 changes: 104 additions & 1 deletion common/spec/dependabot/pull_request_creator/message_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2216,7 +2216,7 @@ def commits_details(base:, head:)
end
end

context "with ignore conditions", :vcr do
context "with ignore conditions when feature flag is enabled", :vcr do
let(:dependency2) do
Dependabot::Dependency.new(
name: "business2",
Expand Down Expand Up @@ -2297,6 +2297,7 @@ def commits_details(base:, head:)
headers: {
"content-type" => "application/x-git-upload-pack-advertisement"
}

)
ignore_conditions.push(
{
Expand All @@ -2308,6 +2309,7 @@ def commits_details(base:, head:)
}
)
end
Dependabot::Experiments.register(:unignore_commands, true)
end

it "has the correct message" do
Expand All @@ -2322,6 +2324,107 @@ def commits_details(base:, head:)
end
end

context "with ignore conditions when feature flag is disabled", :vcr do
let(:dependency2) do
Dependabot::Dependency.new(
name: "business2",
version: "1.8.0",
previous_version: "1.7.0",
package_manager: "dummy",
requirements: [],
previous_requirements: []
)
end
let(:dependency3) do
Dependabot::Dependency.new(
name: "business3",
version: "1.5.0",
previous_version: "1.4.0",
package_manager: "dummy",
requirements: [],
previous_requirements: []
)
end
let(:dependency4) do
Dependabot::Dependency.new(
name: "business4",
version: "2.1.1",
previous_version: "2.1.0",
package_manager: "dummy",
requirements: [],
previous_requirements: []
)
end
let(:dependency5) do
Dependabot::Dependency.new(
name: "business5",
version: "0.17.0",
previous_version: "0.16.2",
package_manager: "dummy",
requirements: [],
previous_requirements: []
)
end
let(:dependencies) { [dependency, dependency2, dependency3, dependency4, dependency5] }

before do
(2..5).each do |i|
repo_url = "https://api.github.com/repos/gocardless/business#{i}"

stub_request(:get, repo_url).
to_return(status: 200,
body: fixture("github", "business_repo.json"),
headers: json_header)
stub_request(:get, "#{repo_url}/contents/").
to_return(status: 200,
body: fixture("github", "business_files.json"),
headers: json_header)
stub_request(:get, "#{repo_url}/releases?per_page=100").
to_return(status: 200,
body: fixture("github", "business_releases.json"),
headers: json_header)
stub_request(:get, "https://api.github.com/repos/gocardless/" \
"business#{i}/contents/CHANGELOG.md?ref=master").
to_return(status: 200,
body: fixture("github", "changelog_contents.json"),
headers: json_header)
stub_request(:get, "https://rubygems.org/api/v1/gems/business#{i}.json").
to_return(
status: 200,
body: fixture("ruby", "rubygems_response_statesman.json")
)

service_pack_url =
"https://github.com/gocardless/business#{i}.git/info/refs" \
"?service=git-upload-pack"

stub_request(:get, service_pack_url).
to_return(
status: 200,
body: fixture("git", "upload_packs", "no_tags"),
headers: {
"content-type" => "application/x-git-upload-pack-advertisement"
}

)
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)
}
)
end
Dependabot::Experiments.register(:unignore_commands, false)
end

it "does not include the ignore conditions section in the message" do
expect(pr_message).not_to include("Most Recent Ignore Conditions Applied to This Pull Request")
end
end

context "without ignore conditions", :vcr do
let(:dependency1) do
Dependabot::Dependency.new(
Expand Down

0 comments on commit ca4115b

Please sign in to comment.