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 809bcca..24072dc 100644 --- a/Gemfile +++ b/Gemfile @@ -47,6 +47,9 @@ 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 gem "debug", platforms: %i[ mri windows ] @@ -67,4 +70,8 @@ group :test do # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing] gem "capybara" gem "selenium-webdriver" + gem "database_cleaner-active_record" + gem "webmock", "~> 3.23" end + +gem "octokit", "~> 9.1" diff --git a/Gemfile.lock b/Gemfile.lock index a256ccf..3082af9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -94,15 +94,29 @@ 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) + database_cleaner-core (~> 2.0.0) + database_cleaner-core (2.0.1) date (3.3.4) debug (1.9.2) irb (~> 1.10) 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) @@ -116,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) @@ -130,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 @@ -142,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) @@ -194,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) @@ -224,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) @@ -244,9 +273,12 @@ PLATFORMS DEPENDENCIES bootsnap capybara + database_cleaner-active_record debug + gems importmap-rails jbuilder + octokit (~> 9.1) puma (>= 5.0) rails (~> 7.1.3, >= 7.1.3.4) selenium-webdriver @@ -256,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 new file mode 100644 index 0000000..cb18035 --- /dev/null +++ b/app/models/ruby_gem.rb @@ -0,0 +1,6 @@ +class RubyGem < ApplicationRecord + def self.fetch_from_ruby_gems_dot_org(gem_name) + 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/db/migrate/20240624204429_create_ruby_gems.rb b/db/migrate/20240624204429_create_ruby_gems.rb new file mode 100644 index 0000000..3c51784 --- /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, index: { unique: true } + 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..19f0cf0 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,44 @@ +# 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 + t.index ["name"], name: "index_ruby_gems_on_name", unique: true + end + +end 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..e27c135 --- /dev/null +++ b/foo_hack.rb @@ -0,0 +1,29 @@ +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 + +# 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? +# +# if gem.archived? && gem.usage_score > some_cutoff +# add_gem_to_our_fostering_portfolio +# end diff --git a/lib/query_gems.rb b/lib/query_gems.rb new file mode 100644 index 0000000..df6d787 --- /dev/null +++ b/lib/query_gems.rb @@ -0,0 +1,18 @@ +class QueryGems + def initialize(username:) + @username = username + 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/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) diff --git a/test/fixtures/ruby_gems.yml b/test/fixtures/ruby_gems.yml new file mode 100644 index 0000000..1f0df1d --- /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 new file mode 100644 index 0000000..a7c6566 --- /dev/null +++ b/test/lib/query_gems_test.rb @@ -0,0 +1,111 @@ +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 + +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: Extract Transform and Load +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 +# + + # 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") + + # 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..d647b85 --- /dev/null +++ b/test/models/ruby_gem_test.rb @@ -0,0 +1,19 @@ +require "test_helper" + +class RubyGemTest < ActiveSupport::TestCase + test "create a RubyGem record" do + bar = RubyGem.create!(name: "bar") + + assert_equal "bar", bar.name + end + + 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 0c22470..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 @@ -11,5 +12,19 @@ class TestCase fixtures :all # Add more helper methods to be used by all tests here... + + 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 + DatabaseCleaner.clean + end end end 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