Skip to content

Commit

Permalink
Simplify the "version already exists" check by using RubyGems v2 API (#…
Browse files Browse the repository at this point in the history
…11712)

The v2 API has endpoints specific to each version: https://guides.rubygems.org/rubygems-org-api-v2/

Benefits:

1. Less data gets returned over the wire
    Compare:
       * https://rubygems.org/api/v1/versions/dependabot-omnibus.json
        * https://rubygems.org/api/v2/rubygems/dependabot-omnibus/versions/0.299.1.json
2. Less brittle since we no longer parse the `response.body`
3. Faster since we only check `response.code`

I verified that sending a non-existent version returns a `404`:
https://rubygems.org/api/v2/rubygems/dependabot-omnibus/versions/0.7.1.json
  • Loading branch information
jeffwidman authored Mar 3, 2025
1 parent 9c44da9 commit d0b3517
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,8 @@ def guard_tag_match
end

def rubygems_release_exists?(name, version)
uri = URI.parse("https://rubygems.org/api/v1/versions/#{name}.json")
uri = URI.parse("https://rubygems.org/api/v2/rubygems/#{name}/versions/#{version}.json")
response = Net::HTTP.get_response(uri)
return false if response.code != "200"

body = JSON.parse(response.body)
existing_versions = body.map { |b| b["number"] }
existing_versions.include?(version)
response.code == "200"
end
# rubocop:enable Metrics/BlockLength

0 comments on commit d0b3517

Please sign in to comment.