diff --git a/.gitignore b/.gitignore index 5fb66c9..d3840a5 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,5 @@ # Ignore master key for decrypting credentials and more. /config/master.key + +*.swp diff --git a/Gemfile b/Gemfile index cc79b8b..24072dc 100644 --- a/Gemfile +++ b/Gemfile @@ -47,9 +47,8 @@ gem "bootsnap", require: false # Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] # gem "image_processing", "~> 1.2" - gem "gems" - +gem "vcr", "~> 6.2" group :development, :test do # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem @@ -72,6 +71,7 @@ group :test do gem "capybara" gem "selenium-webdriver" gem "database_cleaner-active_record" + gem "webmock", "~> 3.23" end -# TODO: add a linter or rubocop or something like that +gem "octokit", "~> 9.1" diff --git a/Gemfile.lock b/Gemfile.lock index 4ca2ebe..3082af9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -94,6 +94,9 @@ GEM xpath (~> 3.2) concurrent-ruby (1.3.3) connection_pool (2.4.1) + crack (1.0.0) + bigdecimal + rexml crass (1.0.6) database_cleaner-active_record (2.1.0) activerecord (>= 5.a) @@ -105,9 +108,15 @@ GEM reline (>= 0.3.8) drb (2.2.1) erubi (1.13.0) + faraday (2.10.0) + faraday-net_http (>= 2.0, < 3.2) + logger + faraday-net_http (3.1.0) + net-http gems (1.2.0) globalid (1.2.1) activesupport (>= 6.1) + hashdiff (1.1.0) i18n (1.14.5) concurrent-ruby (~> 1.0) importmap-rails (2.0.1) @@ -121,6 +130,7 @@ GEM jbuilder (2.12.0) actionview (>= 5.0.0) activesupport (>= 5.0.0) + logger (1.6.0) loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -135,6 +145,8 @@ GEM minitest (5.23.1) msgpack (1.7.2) mutex_m (0.2.0) + net-http (0.4.1) + uri net-imap (0.4.13) date net-protocol @@ -147,6 +159,9 @@ GEM nio4r (2.7.3) nokogiri (1.16.6-x86_64-linux) racc (~> 1.4) + octokit (9.1.0) + faraday (>= 1, < 3) + sawyer (~> 0.9) psych (5.1.2) stringio public_suffix (5.1.1) @@ -199,6 +214,9 @@ GEM rexml (3.3.0) strscan rubyzip (2.3.2) + sawyer (0.9.2) + addressable (>= 2.3.5) + faraday (>= 0.17.3, < 3) selenium-webdriver (4.21.1) base64 (~> 0.2) rexml (~> 3.2, >= 3.2.5) @@ -229,11 +247,17 @@ GEM railties (>= 6.0.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) + uri (0.13.0) + vcr (6.2.0) web-console (4.2.1) actionview (>= 6.0.0) activemodel (>= 6.0.0) bindex (>= 0.4.0) railties (>= 6.0.0) + webmock (3.23.1) + addressable (>= 2.8.0) + crack (>= 0.3.2) + hashdiff (>= 0.4.0, < 2.0.0) webrick (1.8.1) websocket (1.2.10) websocket-driver (0.7.6) @@ -254,6 +278,7 @@ DEPENDENCIES gems importmap-rails jbuilder + octokit (~> 9.1) puma (>= 5.0) rails (~> 7.1.3, >= 7.1.3.4) selenium-webdriver @@ -263,7 +288,9 @@ DEPENDENCIES stimulus-rails turbo-rails tzinfo-data + vcr (~> 6.2) web-console + webmock (~> 3.23) RUBY VERSION ruby 3.2.4p170 diff --git a/app/models/ruby_gem.rb b/app/models/ruby_gem.rb index 4c1480e..cb18035 100644 --- a/app/models/ruby_gem.rb +++ b/app/models/ruby_gem.rb @@ -1,12 +1,6 @@ class RubyGem < ApplicationRecord def self.fetch_from_ruby_gems_dot_org(gem_name) - # gem_info = Gems.info(gem_name).symbolize_keys - # puts gem_info - # new(gem_info).save - # create(name: "maid") - i = new - i.name = "maid" # FIXME: Y U NO WORK - i.save - i + gem_info = Gems.info(gem_name).symbolize_keys + create(gem_info) end end diff --git a/b-coauthor.txt b/b-coauthor.txt new file mode 100644 index 0000000..999793a --- /dev/null +++ b/b-coauthor.txt @@ -0,0 +1 @@ +Co-authored-by: Benjamin Oakes diff --git a/fixtures/vcr_cassettes/fetch_from_ruby_gems_dot_org.yml b/fixtures/vcr_cassettes/fetch_from_ruby_gems_dot_org.yml new file mode 100644 index 0000000..7646887 --- /dev/null +++ b/fixtures/vcr_cassettes/fetch_from_ruby_gems_dot_org.yml @@ -0,0 +1,207 @@ +--- +http_interactions: +- request: + method: get + uri: https://rubygems.org/api/v1/gems/maid.json + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Gems 1.2.0 + - Ruby + Connection: + - keep-alive + Keep-Alive: + - '30' + Content-Type: + - application/x-www-form-urlencoded + response: + status: + code: 200 + message: OK + headers: + Connection: + - keep-alive + Content-Length: + - '2999' + Content-Type: + - application/json; charset=utf-8 + X-Frame-Options: + - SAMEORIGIN + X-Xss-Protection: + - '0' + X-Content-Type-Options: + - nosniff + X-Permitted-Cross-Domain-Policies: + - none + Referrer-Policy: + - strict-origin-when-cross-origin + Access-Control-Allow-Origin: + - "*" + Access-Control-Allow-Methods: + - GET + Access-Control-Max-Age: + - '1728000' + Cache-Control: + - max-age=60, public + Content-Security-Policy: + - default-src 'self'; font-src 'self' https://fonts.gstatic.com; img-src 'self' + https://secure.gaug.es https://gravatar.com https://www.gravatar.com https://secure.gravatar.com + https://*.fastly-insights.com https://avatars.githubusercontent.com; object-src + 'none'; script-src 'self' 'sha256-d8BfrKFC6GOH8sHkHPe0WRYrAiIvDn8UIwURqFEBqNQ=' + https://secure.gaug.es https://www.fastly-insights.com 'nonce-29e1406ca483578b03f1130e8b8571c8'; + style-src 'self' https://fonts.googleapis.com 'nonce-29e1406ca483578b03f1130e8b8571c8'; + connect-src 'self' https://s3-us-west-2.amazonaws.com/rubygems-dumps/ https://*.fastly-insights.com + https://fastly-insights.com https://api.github.com http://localhost:*; form-action + 'self' https://github.com/login/oauth/authorize; frame-ancestors 'self'; base-uri + 'self'; report-uri https://csp-report.browser-intake-datadoghq.com/api/v2/logs?dd-api-key=pub852fa3e2312391fafa5640b60784e660&dd-evp-origin=content-security-policy&ddsource=csp-report&ddtags=service%3Arubygems.org%2Cversion%3A51a79ceba9c67c2df3a21a1d0ff1618fa510a26f%2Cenv%3Aproduction%2Ctrace_id%3A1936704404488720913 + X-Request-Id: + - 5d2e14eb-a061-4c2b-a767-c616efa151f3 + X-Runtime: + - '0.018728' + Strict-Transport-Security: + - max-age=31536000 + X-Backend: + - F_Rails 54.189.148.120:443 + Accept-Ranges: + - bytes + Age: + - '574' + Date: + - Fri, 12 Jul 2024 21:10:28 GMT + Via: + - 1.1 varnish + X-Served-By: + - cache-iad-kiad7000072-IAD + X-Cache: + - HIT + X-Cache-Hits: + - '0' + X-Timer: + - S1720818628.256799,VS0,VE1 + Vary: + - Accept-Encoding + Server: + - RubyGems.org + body: + encoding: ASCII-8BIT + string: '{"name":"maid","downloads":147869,"version":"0.10.0","version_created_at":"2023-05-01T12:56:03.070Z","version_downloads":1206,"platform":"ruby","authors":"Benjamin + Oakes, Coaxial","info":"Be lazy. Let Maid clean up after you, based on rules + you define. Think of it as \"Hazel for hackers\".","licenses":["GPL-2.0"],"metadata":{"wiki_uri":"https://github.com/maid/maid/wiki","changelog_uri":"https://github.com/maid/maid/blob/master/CHANGELOG.md","bug_tracker_uri":"https://github.com/maid/maid/issues","source_code_uri":"https://github.com/maid/maid","documentation_uri":"https://github.com/maid/maid/blob/master/README.md","rubygems_mfa_required":"true"},"yanked":false,"sha":"a935ed74013f19867aa6f74020d690a94f0d671c031a6e63062152df1f87346c","spec_sha":"25890519587dc934e2c78f9bcd495c8a92ed5409fe914e2a0a4ddf82697b2bea","project_uri":"https://rubygems.org/gems/maid","gem_uri":"https://rubygems.org/gems/maid-0.10.0.gem","homepage_uri":"http://github.com/maid/maid","wiki_uri":"https://github.com/maid/maid/wiki","documentation_uri":"https://github.com/maid/maid/blob/master/README.md","mailing_list_uri":null,"source_code_uri":"https://github.com/maid/maid","bug_tracker_uri":"https://github.com/maid/maid/issues","changelog_uri":"https://github.com/maid/maid/blob/master/CHANGELOG.md","funding_uri":null,"dependencies":{"development":[{"name":"fakefs","requirements":"~\u003e + 2.4.0"},{"name":"fuubar","requirements":"\u003e= 0"},{"name":"guard","requirements":"~\u003e + 2.18.0"},{"name":"guard-bundler","requirements":"~\u003e 3.0.1"},{"name":"guard-rspec","requirements":"~\u003e + 4.7.3"},{"name":"guard-rubocop","requirements":"\u003e= 0"},{"name":"pry-byebug","requirements":"\u003e= + 0"},{"name":"rake","requirements":"~\u003e 13.0.6"},{"name":"rake-notes","requirements":"\u003e= + 0"},{"name":"rb-fsevent","requirements":"~\u003e 0.11.2"},{"name":"rb-inotify","requirements":"~\u003e + 0.10.1"},{"name":"redcarpet","requirements":"~\u003e 3.6.0"},{"name":"rspec","requirements":"~\u003e + 3.12.0"},{"name":"rubocop","requirements":"\u003e= 0"},{"name":"rubocop-rake","requirements":"\u003e= + 0"},{"name":"rubocop-rspec","requirements":"\u003e= 0"},{"name":"simplecov","requirements":"\u003e= + 0"},{"name":"timecop","requirements":"~\u003e 0.9.6"},{"name":"vcr","requirements":"~\u003e + 6.1.0"},{"name":"webmock","requirements":"~\u003e 3.18.1"},{"name":"yard","requirements":"\u003e= + 0.9.11"}],"runtime":[{"name":"deprecated","requirements":"~\u003e 3.0.0"},{"name":"dimensions","requirements":"\u003e= + 1.0.0, \u003c 2.0"},{"name":"escape","requirements":"\u003e= 0.0.1, \u003c + 0.1.0"},{"name":"exifr","requirements":"~\u003e 1.3.10"},{"name":"geocoder","requirements":"~\u003e + 1.8.1"},{"name":"listen","requirements":"~\u003e 3.8.0"},{"name":"mime-types","requirements":"~\u003e + 3.0, \u003c 4.0"},{"name":"rubyzip","requirements":"~\u003e 2.3.2"},{"name":"rufus-scheduler","requirements":"~\u003e + 3.8.2"},{"name":"thor","requirements":"~\u003e 1.2.1"},{"name":"xdg","requirements":"~\u003e + 2.2.3"}]}}' + recorded_at: Fri, 12 Jul 2024 21:10:28 GMT +- request: + method: get + uri: https://rubygems.org/api/v1/gems/gems.json + body: + encoding: US-ASCII + string: '' + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Gems 1.2.0 + - Ruby + Connection: + - keep-alive + Keep-Alive: + - '30' + Content-Type: + - application/x-www-form-urlencoded + response: + status: + code: 200 + message: OK + headers: + Connection: + - keep-alive + Content-Length: + - '812' + Content-Type: + - application/json; charset=utf-8 + X-Frame-Options: + - SAMEORIGIN + X-Xss-Protection: + - '0' + X-Content-Type-Options: + - nosniff + X-Permitted-Cross-Domain-Policies: + - none + Referrer-Policy: + - strict-origin-when-cross-origin + Access-Control-Allow-Origin: + - "*" + Access-Control-Allow-Methods: + - GET + Access-Control-Max-Age: + - '1728000' + Cache-Control: + - max-age=60, public + Content-Security-Policy: + - default-src 'self'; font-src 'self' https://fonts.gstatic.com; img-src 'self' + https://secure.gaug.es https://gravatar.com https://www.gravatar.com https://secure.gravatar.com + https://*.fastly-insights.com https://avatars.githubusercontent.com; object-src + 'none'; script-src 'self' 'sha256-d8BfrKFC6GOH8sHkHPe0WRYrAiIvDn8UIwURqFEBqNQ=' + https://secure.gaug.es https://www.fastly-insights.com 'nonce-576ad232245c838f43ac564bf6b8acc3'; + style-src 'self' https://fonts.googleapis.com 'nonce-576ad232245c838f43ac564bf6b8acc3'; + connect-src 'self' https://s3-us-west-2.amazonaws.com/rubygems-dumps/ https://*.fastly-insights.com + https://fastly-insights.com https://api.github.com http://localhost:*; form-action + 'self' https://github.com/login/oauth/authorize; frame-ancestors 'self'; base-uri + 'self'; report-uri https://csp-report.browser-intake-datadoghq.com/api/v2/logs?dd-api-key=pub852fa3e2312391fafa5640b60784e660&dd-evp-origin=content-security-policy&ddsource=csp-report&ddtags=service%3Arubygems.org%2Cversion%3A51a79ceba9c67c2df3a21a1d0ff1618fa510a26f%2Cenv%3Aproduction%2Ctrace_id%3A3719806649199205047 + X-Request-Id: + - 40e14fc2-65c7-42d8-949a-14946344ab71 + X-Runtime: + - '0.079492' + Strict-Transport-Security: + - max-age=31536000 + X-Backend: + - F_Rails 52.25.82.247:443 + Accept-Ranges: + - bytes + Age: + - '523' + Date: + - Fri, 12 Jul 2024 21:10:28 GMT + Via: + - 1.1 varnish + X-Served-By: + - cache-iad-kiad7000068-IAD + X-Cache: + - HIT + X-Cache-Hits: + - '0' + X-Timer: + - S1720818628.268739,VS0,VE1 + Vary: + - Accept-Encoding + Server: + - RubyGems.org + body: + encoding: ASCII-8BIT + string: '{"name":"gems","downloads":32337664,"version":"1.2.0","version_created_at":"2019-09-26T07:12:34.431Z","version_downloads":24477917,"platform":"ruby","authors":"Erik + Michaels-Ober","info":"Ruby wrapper for the RubyGems.org API","licenses":["MIT"],"metadata":{},"yanked":false,"sha":"343d74bd54d906f38193f3ccd983f9d08c4b54cd01ee7e5fe8467ab41a9946f0","spec_sha":"fbe30645252fd72a57f747c7387d2baf8007634e27b5a30ea165cb2c25a6f617","project_uri":"https://rubygems.org/gems/gems","gem_uri":"https://rubygems.org/gems/gems-1.2.0.gem","homepage_uri":"https://github.com/rubygems/gems","wiki_uri":null,"documentation_uri":"https://www.rubydoc.info/gems/gems/1.2.0","mailing_list_uri":null,"source_code_uri":null,"bug_tracker_uri":null,"changelog_uri":null,"funding_uri":null,"dependencies":{"development":[],"runtime":[]}}' + recorded_at: Fri, 12 Jul 2024 21:10:28 GMT +recorded_with: VCR 6.2.0 diff --git a/foo_hack.rb b/foo_hack.rb new file mode 100644 index 0000000..787fa80 --- /dev/null +++ b/foo_hack.rb @@ -0,0 +1,28 @@ +# gem = RubyGem.find_by_name("maid") +# +# # This is gonna be a lot messier than just this, but for now that's ok +# gem.github_url +# # homepage? +# +# # GitHubCacheFooModel.new +# github_repo_object = query_github_from_project_url(project_url) +# +# github_repoo_object.archived? +# +# if gem.archived? && gem.usage_score > some_cutoff +# add_gem_to_our_fostering_portfolio +# end + +# github_repo_object = query_github_from_project_url(project_url) + +require "octokit" + +def query_github_from_project_url(project_url) + puts "querying " + project_url + client = Octokit::Client.new(:access_token => 'personal_access_token') + + p client + p client.user +end + +query_github_from_project_url("maid") diff --git a/test/lib/query_gems_test.rb b/test/lib/query_gems_test.rb index 0c749b9..a7c6566 100644 --- a/test/lib/query_gems_test.rb +++ b/test/lib/query_gems_test.rb @@ -1,6 +1,10 @@ require "test_helper" class QueryGemsTest < ActiveSupport::TestCase + + def test_foo + fail "check out the foo_hack.rb file next" + end # TODO: close instance before we wrap for the day =begin diff --git a/test/models/ruby_gem_test.rb b/test/models/ruby_gem_test.rb index 7dbb2c4..d647b85 100644 --- a/test/models/ruby_gem_test.rb +++ b/test/models/ruby_gem_test.rb @@ -1,22 +1,19 @@ require "test_helper" class RubyGemTest < ActiveSupport::TestCase - test "the truth" do - # assert_equal RubyGem.count, 0 - puts "RubyGem.count = ", RubyGem.count + test "create a RubyGem record" do + bar = RubyGem.create!(name: "bar") - foo = RubyGem.new - foo.name = "bar" - foo.save! - - bar = RubyGem.first assert_equal "bar", bar.name end - # Issues we ran into: - # * bar and baz creation didn't work as expected - # * our tests weren't saving before - test "create multiple records and sanity check our test env db" do - skip "TODO" + test "can fetch from rubygems.org" do + VCR.use_cassette("fetch_from_ruby_gems_dot_org") do + maid = RubyGem.fetch_from_ruby_gems_dot_org("maid") + gems = RubyGem.fetch_from_ruby_gems_dot_org("gems") + + assert_equal "maid", maid.name + assert_equal "gems", gems.name + end end end diff --git a/test/test_helper.rb b/test/test_helper.rb index b828d11..2d3d9c0 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,6 +1,7 @@ ENV["RAILS_ENV"] ||= "test" require_relative "../config/environment" require "rails/test_help" +require 'vcr' module ActiveSupport class TestCase @@ -12,16 +13,18 @@ class TestCase # Add more helper methods to be used by all tests here... - setup do - puts "DatabaseCleaner.start" - DatabaseCleaner.start - puts "DatabaseCleaner.clean" - DatabaseCleaner.clean - end + setup do + DatabaseCleaner.start + DatabaseCleaner.clean - teardown do - puts "DatabaseCleaner.clean" - DatabaseCleaner.clean - end + VCR.configure do |config| + config.cassette_library_dir = "fixtures/vcr_cassettes" + config.hook_into :webmock + end + end + + teardown do + DatabaseCleaner.clean + end end end