From db11c8d8b7fc8e1f19c5c47efc79a38549a27835 Mon Sep 17 00:00:00 2001 From: Ben Oakes Date: Mon, 24 Jun 2024 19:32:27 +0000 Subject: [PATCH 01/18] Add spike code for QueryGems Co-authored-by: Zach Morek --- Gemfile | 4 ++++ Gemfile.lock | 2 ++ lib/query_gems.rb | 12 ++++++++++++ test/lib/query_gems_test.rb | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 lib/query_gems.rb create mode 100644 test/lib/query_gems_test.rb diff --git a/Gemfile b/Gemfile index 809bcca..4580165 100644 --- a/Gemfile +++ b/Gemfile @@ -47,6 +47,10 @@ 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" + + group :development, :test do # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem gem "debug", platforms: %i[ mri windows ] diff --git a/Gemfile.lock b/Gemfile.lock index a256ccf..c470bed 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -101,6 +101,7 @@ GEM reline (>= 0.3.8) drb (2.2.1) erubi (1.13.0) + gems (1.2.0) globalid (1.2.1) activesupport (>= 6.1) i18n (1.14.5) @@ -245,6 +246,7 @@ DEPENDENCIES bootsnap capybara debug + gems importmap-rails jbuilder puma (>= 5.0) diff --git a/lib/query_gems.rb b/lib/query_gems.rb new file mode 100644 index 0000000..4203eb0 --- /dev/null +++ b/lib/query_gems.rb @@ -0,0 +1,12 @@ +class QueryGems + def initialize(username:) + @username = username + end + + def results + Gems. + gems(@username). + map { |gem| Gems.info(gem["name"])["homepage_uri"] }. + sort + end +end diff --git a/test/lib/query_gems_test.rb b/test/lib/query_gems_test.rb new file mode 100644 index 0000000..36a8753 --- /dev/null +++ b/test/lib/query_gems_test.rb @@ -0,0 +1,33 @@ +require "test_helper" + +class QueryGemsTest < ActiveSupport::TestCase + test "#gems" do + query = QueryGems.new(username: "fgrehm") + + results = query.results + + assert_equal results, [ + "", + "http://github.com/fgrehm/autotestforphp", + "http://github.com/fgrehm/tiny-rails", + "https://github.com/Helabs/jumpup-deis", + "https://github.com/Helabs/jumpup-hipchat", + "https://github.com/PetroFeed/actionpusher", + "https://github.com/doximity/rsg", + "https://github.com/fgrehm/bindler", + "https://github.com/fgrehm/docker-provider", + "https://github.com/fgrehm/letter_opener_web", + "https://github.com/fgrehm/middleman-draft-articles", + "https://github.com/fgrehm/rake-notes", + "https://github.com/fgrehm/vagrant-boxen", + "https://github.com/fgrehm/vagrant-cachier", + "https://github.com/fgrehm/vagrant-global-status", + "https://github.com/fgrehm/vagrant-lxc", + "https://github.com/fgrehm/vagrant-notify", + "https://github.com/fgrehm/vagrant-pristine", + "https://github.com/fgrehm/ventriloquist", + "https://github.com/fgrehm/vocker", + "https://github.com/fgrehm/vundler", + ] + end +end From 96e39ddb73e6f227a40b33235e26fe2a48a081f5 Mon Sep 17 00:00:00 2001 From: Ben Oakes Date: Mon, 24 Jun 2024 19:40:41 +0000 Subject: [PATCH 02/18] add a helper Co-authored-by: Zach Morek --- z-coauthor.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 z-coauthor.txt diff --git a/z-coauthor.txt b/z-coauthor.txt new file mode 100644 index 0000000..23249a3 --- /dev/null +++ b/z-coauthor.txt @@ -0,0 +1 @@ +Co-authored-by: Zach Morek From 9092dd264788dcefc82b977216ba303478a1249b Mon Sep 17 00:00:00 2001 From: Ben Oakes Date: Mon, 24 Jun 2024 20:58:44 +0000 Subject: [PATCH 03/18] WIP: Using ActiveRecord to model external data for cross referencing Co-authored-by: Zach Morek --- app/models/ruby_gem.rb | 12 ++ db/migrate/20240624204429_create_ruby_gems.rb | 31 +++++ db/schema.rb | 43 ++++++ lib/query_gems.rb | 18 ++- test/fixtures/ruby_gems.yml | 11 ++ test/lib/query_gems_test.rb | 129 ++++++++++++++---- test/models/ruby_gem_test.rb | 7 + 7 files changed, 217 insertions(+), 34 deletions(-) create mode 100644 app/models/ruby_gem.rb create mode 100644 db/migrate/20240624204429_create_ruby_gems.rb create mode 100644 db/schema.rb create mode 100644 test/fixtures/ruby_gems.yml create mode 100644 test/models/ruby_gem_test.rb diff --git a/app/models/ruby_gem.rb b/app/models/ruby_gem.rb new file mode 100644 index 0000000..4c1480e --- /dev/null +++ b/app/models/ruby_gem.rb @@ -0,0 +1,12 @@ +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 + end +end diff --git a/db/migrate/20240624204429_create_ruby_gems.rb b/db/migrate/20240624204429_create_ruby_gems.rb new file mode 100644 index 0000000..e740079 --- /dev/null +++ b/db/migrate/20240624204429_create_ruby_gems.rb @@ -0,0 +1,31 @@ +class CreateRubyGems < ActiveRecord::Migration[7.1] + def change + create_table :ruby_gems do |t| + t.string :name + t.integer :downloads + t.string :version + t.datetime :version_created_at + t.integer :version_downloads + t.string :platform + t.string :authors + t.string :info + t.json :licenses + t.json :metadata + t.string :yanked + t.string :sha + t.string :spec_sha + t.string :project_uri + t.string :gem_uri + t.string :homepage_uri + t.string :wiki_uri + t.string :documentation_uri + t.string :mailing_list_uri + t.string :source_code_uri + t.string :bug_tracker_uri + t.string :changelog_uri + t.string :funding_uri + t.json :dependencies + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..24a02d5 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,43 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema[7.1].define(version: 2024_06_24_204429) do + create_table "ruby_gems", force: :cascade do |t| + t.string "name" + t.integer "downloads" + t.string "version" + t.datetime "version_created_at" + t.integer "version_downloads" + t.string "platform" + t.string "authors" + t.string "info" + t.json "licenses" + t.json "metadata" + t.string "yanked" + t.string "sha" + t.string "spec_sha" + t.string "project_uri" + t.string "gem_uri" + t.string "homepage_uri" + t.string "wiki_uri" + t.string "documentation_uri" + t.string "mailing_list_uri" + t.string "source_code_uri" + t.string "bug_tracker_uri" + t.string "changelog_uri" + t.string "funding_uri" + t.json "dependencies" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end diff --git a/lib/query_gems.rb b/lib/query_gems.rb index 4203eb0..df6d787 100644 --- a/lib/query_gems.rb +++ b/lib/query_gems.rb @@ -3,10 +3,16 @@ def initialize(username:) @username = username end - def results - Gems. - gems(@username). - map { |gem| Gems.info(gem["name"])["homepage_uri"] }. - sort - end + # def self.gimme_some_schema + # # @username = "fgrehm" + # # Gems.gems(@username).first.keys + # Gems.info("maid").keys + # end + + # def results + # Gems. + # gems(@username). + # map { |gem| Gems.info(gem["name"])["homepage_uri"] }. + # sort + # end end diff --git a/test/fixtures/ruby_gems.yml b/test/fixtures/ruby_gems.yml new file mode 100644 index 0000000..d7a3329 --- /dev/null +++ b/test/fixtures/ruby_gems.yml @@ -0,0 +1,11 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +# This model initially had no columns defined. If you add columns to the +# model remove the "{}" from the fixture names and add the columns immediately +# below each fixture, per the syntax in the comments below +# +one: {} +# column: value +# +two: {} +# column: value diff --git a/test/lib/query_gems_test.rb b/test/lib/query_gems_test.rb index 36a8753..2a3be6e 100644 --- a/test/lib/query_gems_test.rb +++ b/test/lib/query_gems_test.rb @@ -1,33 +1,106 @@ require "test_helper" class QueryGemsTest < ActiveSupport::TestCase - test "#gems" do - query = QueryGems.new(username: "fgrehm") - - results = query.results - - assert_equal results, [ - "", - "http://github.com/fgrehm/autotestforphp", - "http://github.com/fgrehm/tiny-rails", - "https://github.com/Helabs/jumpup-deis", - "https://github.com/Helabs/jumpup-hipchat", - "https://github.com/PetroFeed/actionpusher", - "https://github.com/doximity/rsg", - "https://github.com/fgrehm/bindler", - "https://github.com/fgrehm/docker-provider", - "https://github.com/fgrehm/letter_opener_web", - "https://github.com/fgrehm/middleman-draft-articles", - "https://github.com/fgrehm/rake-notes", - "https://github.com/fgrehm/vagrant-boxen", - "https://github.com/fgrehm/vagrant-cachier", - "https://github.com/fgrehm/vagrant-global-status", - "https://github.com/fgrehm/vagrant-lxc", - "https://github.com/fgrehm/vagrant-notify", - "https://github.com/fgrehm/vagrant-pristine", - "https://github.com/fgrehm/ventriloquist", - "https://github.com/fgrehm/vocker", - "https://github.com/fgrehm/vundler", - ] +# TODO: close instance before we wrap for the day +=begin + +Goal: +Have a means to add gems to be maintained by RSC + + +tell us what gems are high value and unmainted (archived) +this query could be cached? don't want to + +Manual solution now: +* Look thru contacts, linkedin, github, rolodex +* Check ruby gems for that author +* Look at high download count (what's the trehshold for high, sort?) +* Pluck out some n number of gems +* check out their github projects for archived + + + + +ETL +grab a set of gems +query from a local copy + +* [ ] this test is actually hitting the web, do we care about VCR type solutions? + maybe we split the difference? how do our test suite protect us if the real api changes under us +=end + + +# test "find archived" do +# foo = RubyGems.give_me_gems +# bar = Github.give_me_repos +# foo & bar +# +# select * +# from github +# inner join ruby_gems +# on github.url = ruby_gems.homepage +# where github.archived = true +# and ruby_gems.downloads > lower_threshold_foo +# FooGemCache +# +# +# QueryGems.give_me_top_n_gems_that_need_attention +# RubyGems +# Github +# # use some score to determine priority - archived and high download +# +# +# +# +# +# QueryGems.new(author: "foo") +# QueryGems.new(author: ["foo", "bar"]) +# query_gems.results +# +# QueryGems.new(archived: true).results +# +# QueryGems.archived +# QueryGems.where(archived: true) +# QueryGems.give_me_hella_gems.select { |el| el.archived } +# end +# + + test "arel this stuff" do + # assert_equal "fail", QueryGems.gimme_some_schema + RubyGem.fetch_from_ruby_gems_dot_org("maid") + # assert_equal 1, RubyGem.count # TODO database_cleaner + maid_gem = RubyGem.first + puts maid_gem.inspect + assert_equal maid_gem.name, "maid" end + + # test "#results" do + # query = QueryGems.new(username: "fgrehm") + + # results = query.results + + # assert_equal results, [ + # "", + # "http://github.com/fgrehm/autotestforphp", + # "http://github.com/fgrehm/tiny-rails", + # "https://github.com/Helabs/jumpup-deis", + # "https://github.com/Helabs/jumpup-hipchat", + # "https://github.com/PetroFeed/actionpusher", + # "https://github.com/doximity/rsg", + # "https://github.com/fgrehm/bindler", + # "https://github.com/fgrehm/docker-provider", + # "https://github.com/fgrehm/letter_opener_web", + # "https://github.com/fgrehm/middleman-draft-articles", + # "https://github.com/fgrehm/rake-notes", + # "https://github.com/fgrehm/vagrant-boxen", + # "https://github.com/fgrehm/vagrant-cachier", + # "https://github.com/fgrehm/vagrant-global-status", + # "https://github.com/fgrehm/vagrant-lxc", + # "https://github.com/fgrehm/vagrant-notify", + # "https://github.com/fgrehm/vagrant-pristine", + # "https://github.com/fgrehm/ventriloquist", + # "https://github.com/fgrehm/vocker", + # "https://github.com/fgrehm/vundler", + # ] + # end end diff --git a/test/models/ruby_gem_test.rb b/test/models/ruby_gem_test.rb new file mode 100644 index 0000000..f42c6a4 --- /dev/null +++ b/test/models/ruby_gem_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class RubyGemTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end From fee037829a45f7343cbe0b6d2e3fb22d0062b6c2 Mon Sep 17 00:00:00 2001 From: Ben Oakes Date: Mon, 1 Jul 2024 20:10:28 +0000 Subject: [PATCH 04/18] Unique index on ruby_gems.name --- db/migrate/20240624204429_create_ruby_gems.rb | 2 +- db/schema.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/db/migrate/20240624204429_create_ruby_gems.rb b/db/migrate/20240624204429_create_ruby_gems.rb index e740079..3c51784 100644 --- a/db/migrate/20240624204429_create_ruby_gems.rb +++ b/db/migrate/20240624204429_create_ruby_gems.rb @@ -1,7 +1,7 @@ class CreateRubyGems < ActiveRecord::Migration[7.1] def change create_table :ruby_gems do |t| - t.string :name + t.string :name, index: { unique: true } t.integer :downloads t.string :version t.datetime :version_created_at diff --git a/db/schema.rb b/db/schema.rb index 24a02d5..19f0cf0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -38,6 +38,7 @@ t.json "dependencies" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.index ["name"], name: "index_ruby_gems_on_name", unique: true end end From ed8702bdd9dece6c4a91c056bcc1acffcd7bc6ad Mon Sep 17 00:00:00 2001 From: Ben Oakes Date: Mon, 1 Jul 2024 20:10:38 +0000 Subject: [PATCH 05/18] Define ETL --- test/lib/query_gems_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib/query_gems_test.rb b/test/lib/query_gems_test.rb index 2a3be6e..4b2d49a 100644 --- a/test/lib/query_gems_test.rb +++ b/test/lib/query_gems_test.rb @@ -21,7 +21,7 @@ class QueryGemsTest < ActiveSupport::TestCase -ETL +ETL: Extract Transform and Load grab a set of gems query from a local copy From 12d252aaab8b8cc69b668c7f999a445e387e8b59 Mon Sep 17 00:00:00 2001 From: Ben Oakes Date: Mon, 1 Jul 2024 20:47:39 +0000 Subject: [PATCH 06/18] starting to test RubyGem class and confirm testing infra Co-authored-by: Zach Morek --- test/lib/query_gems_test.rb | 49 ++++++++++++++++++------------------ test/models/ruby_gem_test.rb | 30 +++++++++++++++++++--- test/test_helper.rb | 3 +++ 3 files changed, 55 insertions(+), 27 deletions(-) diff --git a/test/lib/query_gems_test.rb b/test/lib/query_gems_test.rb index 4b2d49a..0c749b9 100644 --- a/test/lib/query_gems_test.rb +++ b/test/lib/query_gems_test.rb @@ -28,51 +28,52 @@ class QueryGemsTest < ActiveSupport::TestCase * [ ] this test is actually hitting the web, do we care about VCR type solutions? maybe we split the difference? how do our test suite protect us if the real api changes under us =end - + # test "find archived" do # foo = RubyGems.give_me_gems # bar = Github.give_me_repos # foo & bar -# -# select * -# from github -# inner join ruby_gems +# +# select * +# from github +# inner join ruby_gems # on github.url = ruby_gems.homepage # where github.archived = true # and ruby_gems.downloads > lower_threshold_foo # FooGemCache -# -# +# +# # QueryGems.give_me_top_n_gems_that_need_attention # RubyGems # Github # # use some score to determine priority - archived and high download -# -# -# -# -# +# +# +# +# +# # QueryGems.new(author: "foo") # QueryGems.new(author: ["foo", "bar"]) # query_gems.results -# +# # QueryGems.new(archived: true).results -# +# # QueryGems.archived # QueryGems.where(archived: true) # QueryGems.give_me_hella_gems.select { |el| el.archived } # end -# - - test "arel this stuff" do - # assert_equal "fail", QueryGems.gimme_some_schema - RubyGem.fetch_from_ruby_gems_dot_org("maid") - # assert_equal 1, RubyGem.count # TODO database_cleaner - maid_gem = RubyGem.first - puts maid_gem.inspect - assert_equal maid_gem.name, "maid" - end +# + + # FIXME + # test "arel this stuff" do + # # assert_equal "fail", QueryGems.gimme_some_schema + # RubyGem.fetch_from_ruby_gems_dot_org("maid") + # # assert_equal 1, RubyGem.count # TODO database_cleaner + # maid_gem = RubyGem.first + # puts maid_gem.inspect + # assert_equal maid_gem.name, "maid" + # end # test "#results" do # query = QueryGems.new(username: "fgrehm") diff --git a/test/models/ruby_gem_test.rb b/test/models/ruby_gem_test.rb index f42c6a4..310a747 100644 --- a/test/models/ruby_gem_test.rb +++ b/test/models/ruby_gem_test.rb @@ -1,7 +1,31 @@ require "test_helper" class RubyGemTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + setup do + puts "got in - ruby gem test" + RubyGem.delete_all + end + + teardown do + puts "got in - teardown ruby gem test" + RubyGem.delete_all + end + + test "the truth" do + assert_equal RubyGem.count, 0 + + 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" + end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 0c22470..1fa2e60 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -11,5 +11,8 @@ class TestCase fixtures :all # Add more helper methods to be used by all tests here... + setup do + puts "got in suite" + end end end From f9e0929dd4a90fc7ca14a7b85108ae84131e580a Mon Sep 17 00:00:00 2001 From: Ben Oakes Date: Mon, 1 Jul 2024 20:59:43 +0000 Subject: [PATCH 07/18] Use DatabaseCleaner Co-authored-by: Zach Morek --- Gemfile | 3 +++ Gemfile.lock | 5 +++++ test/fixtures/ruby_gems.yml | 4 ++-- test/models/ruby_gem_test.rb | 13 ++----------- test/test_helper.rb | 15 ++++++++++++--- 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/Gemfile b/Gemfile index 4580165..cc79b8b 100644 --- a/Gemfile +++ b/Gemfile @@ -71,4 +71,7 @@ group :test do # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing] gem "capybara" gem "selenium-webdriver" + gem "database_cleaner-active_record" end + +# TODO: add a linter or rubocop or something like that diff --git a/Gemfile.lock b/Gemfile.lock index c470bed..4ca2ebe 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -95,6 +95,10 @@ GEM concurrent-ruby (1.3.3) connection_pool (2.4.1) crass (1.0.6) + database_cleaner-active_record (2.1.0) + activerecord (>= 5.a) + database_cleaner-core (~> 2.0.0) + database_cleaner-core (2.0.1) date (3.3.4) debug (1.9.2) irb (~> 1.10) @@ -245,6 +249,7 @@ PLATFORMS DEPENDENCIES bootsnap capybara + database_cleaner-active_record debug gems importmap-rails diff --git a/test/fixtures/ruby_gems.yml b/test/fixtures/ruby_gems.yml index d7a3329..1f0df1d 100644 --- a/test/fixtures/ruby_gems.yml +++ b/test/fixtures/ruby_gems.yml @@ -4,8 +4,8 @@ # model remove the "{}" from the fixture names and add the columns immediately # below each fixture, per the syntax in the comments below # -one: {} +# one: {} # column: value # -two: {} +# two: {} # column: value diff --git a/test/models/ruby_gem_test.rb b/test/models/ruby_gem_test.rb index 310a747..7dbb2c4 100644 --- a/test/models/ruby_gem_test.rb +++ b/test/models/ruby_gem_test.rb @@ -1,18 +1,9 @@ require "test_helper" class RubyGemTest < ActiveSupport::TestCase - setup do - puts "got in - ruby gem test" - RubyGem.delete_all - end - - teardown do - puts "got in - teardown ruby gem test" - RubyGem.delete_all - end - test "the truth" do - assert_equal RubyGem.count, 0 + # assert_equal RubyGem.count, 0 + puts "RubyGem.count = ", RubyGem.count foo = RubyGem.new foo.name = "bar" diff --git a/test/test_helper.rb b/test/test_helper.rb index 1fa2e60..b828d11 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -11,8 +11,17 @@ class TestCase fixtures :all # Add more helper methods to be used by all tests here... - setup do - puts "got in suite" - end + + setup do + puts "DatabaseCleaner.start" + DatabaseCleaner.start + puts "DatabaseCleaner.clean" + DatabaseCleaner.clean + end + + teardown do + puts "DatabaseCleaner.clean" + DatabaseCleaner.clean + end end end From 482cfd7b02f36a96d25dd10311f889d5e7df89f1 Mon Sep 17 00:00:00 2001 From: Zach Morek Date: Fri, 12 Jul 2024 20:29:37 +0000 Subject: [PATCH 08/18] (m) clean up whitespace and move TODO into a new ticket Co-authored-by: Benjamin Oakes --- Gemfile | 2 -- test/models/ruby_gem_test.rb | 2 +- test/test_helper.rb | 20 ++++++++++---------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Gemfile b/Gemfile index cc79b8b..6761a93 100644 --- a/Gemfile +++ b/Gemfile @@ -73,5 +73,3 @@ group :test do gem "selenium-webdriver" gem "database_cleaner-active_record" end - -# TODO: add a linter or rubocop or something like that diff --git a/test/models/ruby_gem_test.rb b/test/models/ruby_gem_test.rb index 7dbb2c4..64e724e 100644 --- a/test/models/ruby_gem_test.rb +++ b/test/models/ruby_gem_test.rb @@ -3,7 +3,7 @@ class RubyGemTest < ActiveSupport::TestCase test "the truth" do # assert_equal RubyGem.count, 0 - puts "RubyGem.count = ", RubyGem.count + puts "RubyGem.count = ", RubyGem.count foo = RubyGem.new foo.name = "bar" diff --git a/test/test_helper.rb b/test/test_helper.rb index b828d11..9edc250 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -12,16 +12,16 @@ 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 + puts "DatabaseCleaner.start" + DatabaseCleaner.start + puts "DatabaseCleaner.clean" + DatabaseCleaner.clean + end - teardown do - puts "DatabaseCleaner.clean" - DatabaseCleaner.clean - end + teardown do + puts "DatabaseCleaner.clean" + DatabaseCleaner.clean + end end end From 23fa7233689c698dd4632c95acbc576e8b321e9e Mon Sep 17 00:00:00 2001 From: Zach Morek Date: Fri, 12 Jul 2024 20:36:25 +0000 Subject: [PATCH 09/18] remove puts statements and stale assertions Co-authored-by: Benjamin Oakes --- test/models/ruby_gem_test.rb | 3 --- test/test_helper.rb | 3 --- 2 files changed, 6 deletions(-) diff --git a/test/models/ruby_gem_test.rb b/test/models/ruby_gem_test.rb index 64e724e..d8fd786 100644 --- a/test/models/ruby_gem_test.rb +++ b/test/models/ruby_gem_test.rb @@ -2,9 +2,6 @@ class RubyGemTest < ActiveSupport::TestCase test "the truth" do - # assert_equal RubyGem.count, 0 - puts "RubyGem.count = ", RubyGem.count - foo = RubyGem.new foo.name = "bar" foo.save! diff --git a/test/test_helper.rb b/test/test_helper.rb index 9edc250..20d3dfe 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -13,14 +13,11 @@ 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 teardown do - puts "DatabaseCleaner.clean" DatabaseCleaner.clean end end From c67fc18375b94eeaaeee11c036d8f8c022edd0f9 Mon Sep 17 00:00:00 2001 From: Zach Morek Date: Fri, 12 Jul 2024 20:39:55 +0000 Subject: [PATCH 10/18] tidy the trivial first test Co-authored-by: Benjamin Oakes --- test/models/ruby_gem_test.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/test/models/ruby_gem_test.rb b/test/models/ruby_gem_test.rb index d8fd786..3820baf 100644 --- a/test/models/ruby_gem_test.rb +++ b/test/models/ruby_gem_test.rb @@ -1,12 +1,9 @@ require "test_helper" class RubyGemTest < ActiveSupport::TestCase - test "the truth" do - foo = RubyGem.new - foo.name = "bar" - foo.save! + test "create a RubyGem record" do + bar = RubyGem.create!(name: "bar") - bar = RubyGem.first assert_equal "bar", bar.name end From d06c7f6aa4c185c3dfb5976d8714831b8f7c0276 Mon Sep 17 00:00:00 2001 From: Zach Morek Date: Fri, 12 Jul 2024 21:03:25 +0000 Subject: [PATCH 11/18] Working RubyGem.fetch_from_ruby_gems_dot_org Co-authored-by: Benjamin Oakes --- app/models/ruby_gem.rb | 10 ++-------- test/models/ruby_gem_test.rb | 11 ++++++----- 2 files changed, 8 insertions(+), 13 deletions(-) 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/test/models/ruby_gem_test.rb b/test/models/ruby_gem_test.rb index 3820baf..a76f161 100644 --- a/test/models/ruby_gem_test.rb +++ b/test/models/ruby_gem_test.rb @@ -7,10 +7,11 @@ class RubyGemTest < ActiveSupport::TestCase 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 + 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 From 4a37497fcdcdfa0823245aaa5d528a83317332b8 Mon Sep 17 00:00:00 2001 From: Zach Morek Date: Fri, 12 Jul 2024 21:04:52 +0000 Subject: [PATCH 12/18] Add b-coauthor helper Co-authored-by: Benjamin Oakes --- b-coauthor.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 b-coauthor.txt 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 From 691dad96b2f0fbcecacd9b2be9c96e82b6cd5e02 Mon Sep 17 00:00:00 2001 From: Zach Morek Date: Fri, 12 Jul 2024 21:07:24 +0000 Subject: [PATCH 13/18] Add VCR gem Co-authored-by: Benjamin Oakes --- Gemfile | 3 +-- Gemfile.lock | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 6761a93..5a7cb84 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 diff --git a/Gemfile.lock b/Gemfile.lock index 4ca2ebe..e23e36f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -229,6 +229,7 @@ GEM railties (>= 6.0.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) + vcr (6.2.0) web-console (4.2.1) actionview (>= 6.0.0) activemodel (>= 6.0.0) @@ -263,6 +264,7 @@ DEPENDENCIES stimulus-rails turbo-rails tzinfo-data + vcr (~> 6.2) web-console RUBY VERSION From c1e28abee4f7fb5cc122f573580ab49636ead05c Mon Sep 17 00:00:00 2001 From: Zach Morek Date: Fri, 12 Jul 2024 21:13:38 +0000 Subject: [PATCH 14/18] Use VCR for fetch_from_ruby_gems_dot_org Co-authored-by: Benjamin Oakes --- Gemfile | 1 + Gemfile.lock | 9 + .../fetch_from_ruby_gems_dot_org.yml | 207 ++++++++++++++++++ test/models/ruby_gem_test.rb | 10 +- test/test_helper.rb | 6 + 5 files changed, 229 insertions(+), 4 deletions(-) create mode 100644 fixtures/vcr_cassettes/fetch_from_ruby_gems_dot_org.yml diff --git a/Gemfile b/Gemfile index 5a7cb84..b0032c1 100644 --- a/Gemfile +++ b/Gemfile @@ -71,4 +71,5 @@ group :test do gem "capybara" gem "selenium-webdriver" gem "database_cleaner-active_record" + gem "webmock", "~> 3.23" end diff --git a/Gemfile.lock b/Gemfile.lock index e23e36f..36837e1 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) @@ -108,6 +111,7 @@ GEM 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) @@ -235,6 +239,10 @@ GEM 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) @@ -266,6 +274,7 @@ DEPENDENCIES tzinfo-data vcr (~> 6.2) web-console + webmock (~> 3.23) RUBY VERSION ruby 3.2.4p170 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/test/models/ruby_gem_test.rb b/test/models/ruby_gem_test.rb index a76f161..d647b85 100644 --- a/test/models/ruby_gem_test.rb +++ b/test/models/ruby_gem_test.rb @@ -8,10 +8,12 @@ class RubyGemTest < ActiveSupport::TestCase end test "can fetch from rubygems.org" do - maid = RubyGem.fetch_from_ruby_gems_dot_org("maid") - gems = RubyGem.fetch_from_ruby_gems_dot_org("gems") + 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 + 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 20d3dfe..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 @@ -15,6 +16,11 @@ class TestCase setup do DatabaseCleaner.start DatabaseCleaner.clean + + VCR.configure do |config| + config.cassette_library_dir = "fixtures/vcr_cassettes" + config.hook_into :webmock + end end teardown do From e1f74e3c897d0654b382d3ddf7f7b57c4012a605 Mon Sep 17 00:00:00 2001 From: Zach Morek Date: Fri, 12 Jul 2024 21:42:24 +0000 Subject: [PATCH 15/18] gitignore swap files Co-authored-by: Benjamin Oakes --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) 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 From a85c4fcc7e91f797cc8e8215c0d5facb86a42546 Mon Sep 17 00:00:00 2001 From: Zach Morek Date: Fri, 12 Jul 2024 22:07:40 +0000 Subject: [PATCH 16/18] spike on querying github Co-authored-by: Benjamin Oakes --- Gemfile | 2 ++ Gemfile.lock | 16 ++++++++++++++++ foo_hack.rb | 28 ++++++++++++++++++++++++++++ test/lib/query_gems_test.rb | 4 ++++ 4 files changed, 50 insertions(+) create mode 100644 foo_hack.rb diff --git a/Gemfile b/Gemfile index b0032c1..24072dc 100644 --- a/Gemfile +++ b/Gemfile @@ -73,3 +73,5 @@ group :test do gem "database_cleaner-active_record" gem "webmock", "~> 3.23" end + +gem "octokit", "~> 9.1" diff --git a/Gemfile.lock b/Gemfile.lock index 36837e1..3082af9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -108,6 +108,11 @@ 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) @@ -125,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) @@ -139,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 @@ -151,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) @@ -203,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) @@ -233,6 +247,7 @@ 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) @@ -263,6 +278,7 @@ DEPENDENCIES gems importmap-rails jbuilder + octokit (~> 9.1) puma (>= 5.0) rails (~> 7.1.3, >= 7.1.3.4) selenium-webdriver 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 From d8e4f55e422e047c1a8ba1a45587cf73782b34c6 Mon Sep 17 00:00:00 2001 From: Ben Oakes Date: Mon, 15 Jul 2024 21:11:42 +0000 Subject: [PATCH 17/18] Working query_github_from_project_url Co-authored-by: Zach Morek --- foo_hack.rb | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/foo_hack.rb b/foo_hack.rb index 787fa80..286918a 100644 --- a/foo_hack.rb +++ b/foo_hack.rb @@ -1,28 +1,23 @@ +require 'open-uri' + +def query_github_from_project_url(project_url) + url = 'https://github.com/benjaminoakes/maid/' + uri = URI.parse(url) + uri.host = 'api.github.com' + uri.path = '/repos' + uri.path + io = URI.open('https://api.github.com/repos/benjaminoakes/maid') + body = io.read + JSON.parse(body) +end + # 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) -# +# ruby_gem.homepage_url # => "https://github.com/maid/maid" +json = query_github_from_project_url("https://github.com/maid/maid") +# GitHubRepo.create(json) # 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") From 496367e879068f5530e60136a08c0abf4a997f5e Mon Sep 17 00:00:00 2001 From: Ben Oakes Date: Mon, 15 Jul 2024 21:44:07 +0000 Subject: [PATCH 18/18] Write up plan for GitHubRepo model creation Co-authored-by: Zach Morek --- foo_hack.rb | 6 ++ repo.json | 133 +++++++++++++++++++++++++++++++++++++++++++++ repo_generation.sh | 18 ++++++ 3 files changed, 157 insertions(+) create mode 100644 repo.json create mode 100644 repo_generation.sh diff --git a/foo_hack.rb b/foo_hack.rb index 286918a..e27c135 100644 --- a/foo_hack.rb +++ b/foo_hack.rb @@ -10,11 +10,17 @@ def query_github_from_project_url(project_url) JSON.parse(body) end +# TODO: +# Repo Last Updated At +# Create a GitHubRepo object + # 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 # ruby_gem.homepage_url # => "https://github.com/maid/maid" json = query_github_from_project_url("https://github.com/maid/maid") +pp json +@json = json # GitHubRepo.create(json) # github_repoo_object.archived? # diff --git a/repo.json b/repo.json new file mode 100644 index 0000000..f063188 --- /dev/null +++ b/repo.json @@ -0,0 +1,133 @@ +{ + "id": 1780853, + "node_id": "MDEwOlJlcG9zaXRvcnkxNzgwODUz", + "name": "maid", + "full_name": "maid/maid", + "private": false, + "owner": { + "login": "maid", + "id": 3083817, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjMwODM4MTc=", + "avatar_url": "https://avatars.githubusercontent.com/u/3083817?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/maid", + "html_url": "https://github.com/maid", + "followers_url": "https://api.github.com/users/maid/followers", + "following_url": "https://api.github.com/users/maid/following{/other_user}", + "gists_url": "https://api.github.com/users/maid/gists{/gist_id}", + "starred_url": "https://api.github.com/users/maid/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/maid/subscriptions", + "organizations_url": "https://api.github.com/users/maid/orgs", + "repos_url": "https://api.github.com/users/maid/repos", + "events_url": "https://api.github.com/users/maid/events{/privacy}", + "received_events_url": "https://api.github.com/users/maid/received_events", + "type": "Organization", + "site_admin": false + }, + "html_url": "https://github.com/maid/maid", + "description": "Be lazy. Let Maid clean up after you, based on rules you define. Think of it as \"Hazel for hackers\".", + "fork": false, + "url": "https://api.github.com/repos/maid/maid", + "forks_url": "https://api.github.com/repos/maid/maid/forks", + "keys_url": "https://api.github.com/repos/maid/maid/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/maid/maid/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/maid/maid/teams", + "hooks_url": "https://api.github.com/repos/maid/maid/hooks", + "issue_events_url": "https://api.github.com/repos/maid/maid/issues/events{/number}", + "events_url": "https://api.github.com/repos/maid/maid/events", + "assignees_url": "https://api.github.com/repos/maid/maid/assignees{/user}", + "branches_url": "https://api.github.com/repos/maid/maid/branches{/branch}", + "tags_url": "https://api.github.com/repos/maid/maid/tags", + "blobs_url": "https://api.github.com/repos/maid/maid/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/maid/maid/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/maid/maid/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/maid/maid/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/maid/maid/statuses/{sha}", + "languages_url": "https://api.github.com/repos/maid/maid/languages", + "stargazers_url": "https://api.github.com/repos/maid/maid/stargazers", + "contributors_url": "https://api.github.com/repos/maid/maid/contributors", + "subscribers_url": "https://api.github.com/repos/maid/maid/subscribers", + "subscription_url": "https://api.github.com/repos/maid/maid/subscription", + "commits_url": "https://api.github.com/repos/maid/maid/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/maid/maid/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/maid/maid/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/maid/maid/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/maid/maid/contents/{+path}", + "compare_url": "https://api.github.com/repos/maid/maid/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/maid/maid/merges", + "archive_url": "https://api.github.com/repos/maid/maid/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/maid/maid/downloads", + "issues_url": "https://api.github.com/repos/maid/maid/issues{/number}", + "pulls_url": "https://api.github.com/repos/maid/maid/pulls{/number}", + "milestones_url": "https://api.github.com/repos/maid/maid/milestones{/number}", + "notifications_url": "https://api.github.com/repos/maid/maid/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/maid/maid/labels{/name}", + "releases_url": "https://api.github.com/repos/maid/maid/releases{/id}", + "deployments_url": "https://api.github.com/repos/maid/maid/deployments", + "created_at": "2011-05-21T15:35:43Z", + "updated_at": "2024-07-13T05:05:54Z", + "pushed_at": "2024-06-21T21:05:34Z", + "git_url": "git://github.com/maid/maid.git", + "ssh_url": "git@github.com:maid/maid.git", + "clone_url": "https://github.com/maid/maid.git", + "svn_url": "https://github.com/maid/maid", + "homepage": "http://rubygems.org/gems/maid", + "size": 819, + "stargazers_count": 1796, + "watchers_count": 1796, + "language": "Ruby", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "has_discussions": true, + "forks_count": 84, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 46, + "license": { + "key": "gpl-2.0", + "name": "GNU General Public License v2.0", + "spdx_id": "GPL-2.0", + "url": "https://api.github.com/licenses/gpl-2.0", + "node_id": "MDc6TGljZW5zZTg=" + }, + "allow_forking": true, + "is_template": false, + "web_commit_signoff_required": false, + "topics": [ + + ], + "visibility": "public", + "forks": 84, + "open_issues": 46, + "watchers": 1796, + "default_branch": "master", + "temp_clone_token": null, + "custom_properties": { + }, + "organization": { + "login": "maid", + "id": 3083817, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjMwODM4MTc=", + "avatar_url": "https://avatars.githubusercontent.com/u/3083817?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/maid", + "html_url": "https://github.com/maid", + "followers_url": "https://api.github.com/users/maid/followers", + "following_url": "https://api.github.com/users/maid/following{/other_user}", + "gists_url": "https://api.github.com/users/maid/gists{/gist_id}", + "starred_url": "https://api.github.com/users/maid/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/maid/subscriptions", + "organizations_url": "https://api.github.com/users/maid/orgs", + "repos_url": "https://api.github.com/users/maid/repos", + "events_url": "https://api.github.com/users/maid/events{/privacy}", + "received_events_url": "https://api.github.com/users/maid/received_events", + "type": "Organization", + "site_admin": false + }, + "network_count": 84, + "subscribers_count": 38 +} \ No newline at end of file diff --git a/repo_generation.sh b/repo_generation.sh new file mode 100644 index 0000000..3353c64 --- /dev/null +++ b/repo_generation.sh @@ -0,0 +1,18 @@ +rails g model \ + # no fixture please + + # https://stackoverflow.com/questions/6210572/how-can-i-replace-a-hash-key-with-another-key + # + # repo_id + # repo_updated_at + # repo_created_at + + name: string \ + private: boolean \ + # ... + + # TODO + # + # Consider using ChatGPT or Copilot to take repo.json and turn it into a Rails generate command or schema + + # How do we want to handle "organization" and similar? Probably as a JSON column for now and possibly as a related model in the future (as needed)