Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions updater/lib/dependabot/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,13 @@ def create_pull_request_data(dependencies, updated_dependency_files, base_commit
dependencies: dependencies.map do |dep|
{
name: dep.name,
version: dep.version,
"previous-version": dep.previous_version,
requirements: dep.requirements,
"previous-requirements": dep.previous_requirements
}
}.merge({
version: dep.version,
removed: dep.removed? ? true : nil
}.compact)
end,
"updated-dependency-files": updated_dependency_files,
"base-commit-sha": base_commit_sha
Expand Down
28 changes: 28 additions & 0 deletions updater/spec/dependabot/api_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,34 @@
end)
end
end

context "with a removed dependency" do
Copy link
Copy Markdown
Member

@Nishnha Nishnha Sep 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if somehow we pass in removed: false instead of nil?

Copy link
Copy Markdown
Contributor Author

@mctofu mctofu Sep 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It defaults to false so should be the same:

def initialize(name:, requirements:, package_manager:, version: nil,
previous_version: nil, previous_requirements: nil,
subdependency_metadata: [], removed: false)

let(:removed_dependency) do
Dependabot::Dependency.new(
name: "removed",
package_manager: "bundler",
previous_version: "1.7.0",
requirements: [],
previous_requirements: [],
removed: true
)
end

it "encodes fields" do
client.create_pull_request(1, [removed_dependency, dependency], dependency_files, base_commit, message)
expect(WebMock).
to(have_requested(:post, create_pull_request_url).
with(headers: { "Authorization" => "token" }).
with do |req|
data = JSON.parse(req.body)["data"]
expect(data["dependencies"].first["removed"]).to eq(true)
expect(data["dependencies"].first.key?("version")).to eq(false)
expect(data["dependencies"].last.key?("removed")).to eq(false)
expect(data["dependencies"].last["version"]).to eq("1.8.0")
true
end)
end
end
end

describe "update_pull_request" do
Expand Down