utils/pypi: return nil for non-pypi-packages from url

This commit is contained in:
Rylan Polster 2020-12-03 15:00:30 -05:00
parent 9298e4959b
commit 22a3025f6e
2 changed files with 12 additions and 0 deletions

View File

@ -172,5 +172,13 @@ describe PyPI do
it "updates url to new version" do
expect(described_class.update_pypi_url(old_package_url, "5.29.0")).to eq package_url
end
it "returns nil for invalid versions" do
expect(described_class.update_pypi_url(old_package_url, "0.0.0")).to eq nil
end
it "returns nil for non-pypi urls" do
expect(described_class.update_pypi_url("https://brew.sh/foo-1.0.tgz", "1.1")).to eq nil
end
end
end

View File

@ -110,8 +110,12 @@ module PyPI
def update_pypi_url(url, version)
package = Package.new url, is_url: true
return unless package.valid_pypi_package?
_, url = package.pypi_info(version: version)
url
rescue ArgumentError
nil
end
# Return true if resources were checked (even if no change).