class EndOfLife::Repository
Attributes
full_name[RW]
Public Class Methods
fetch(options)
click to toggle source
# File lib/end_of_life/repository.rb, line 6 def fetch(options) github_client.bind do |github| github.auto_paginate = true options[:user] ||= github.user.login query = search_query_for(options) items = github.search_repositories(query).items Success( items.map do |repo| Repository.new( full_name: repo.full_name, url: repo.html_url, github_client: github ) end ) rescue => e Failure("Unexpected error: #{e}") end end
github_client()
click to toggle source
# File lib/end_of_life/repository.rb, line 28 def github_client Maybe(ENV["GITHUB_TOKEN"]) .fmap { |token| Octokit::Client.new(access_token: token) } .or { Failure("Please set GITHUB_TOKEN environment variable") } end
new(full_name:, url:, github_client:)
click to toggle source
# File lib/end_of_life/repository.rb, line 61 def initialize(full_name:, url:, github_client:) @full_name = full_name @url = url @github_client = github_client end
search_query_for(options)
click to toggle source
# File lib/end_of_life/repository.rb, line 34 def search_query_for(options) query = "language:ruby" query += if options[:repository] " repo:#{options[:repository]}" elsif options[:organizations] options[:organizations].map { |org| " org:#{org}" }.join else " user:#{options[:user]}" end if options[:visibility] query += " is:#{options[:visibility]}" end if options[:excludes] words_to_exclude = options[:excludes].map { |word| "NOT #{word} " }.join query += " #{words_to_exclude} in:name" end query end
Public Instance Methods
eol_ruby?(at: Date.today)
click to toggle source
# File lib/end_of_life/repository.rb, line 67 def eol_ruby?(at: Date.today) ruby_version&.eol?(at: at) end
ruby_version()
click to toggle source
# File lib/end_of_life/repository.rb, line 71 def ruby_version return @ruby_version if defined?(@ruby_version) @ruby_version = ruby_versions.min end
Private Instance Methods
decode_file(file)
click to toggle source
# File lib/end_of_life/repository.rb, line 104 def decode_file(file) return file.content if file.encoding.nil? return Base64.decode64(file.content) if file.encoding == "base64" raise ArgumentError, "Unsupported encoding: #{file.encoding.inspect}" end
fetch_file(file_path)
click to toggle source
# File lib/end_of_life/repository.rb, line 94 def fetch_file(file_path) @github_client.contents(full_name, path: file_path) rescue Octokit::NotFound nil end
parse_version_file(file)
click to toggle source
# File lib/end_of_life/repository.rb, line 100 def parse_version_file(file) RubyVersion.from_file(file_name: file.name, content: decode_file(file)) end
ruby_versions()
click to toggle source
# File lib/end_of_life/repository.rb, line 79 def ruby_versions return @ruby_versions if defined?(@ruby_versions) @ruby_versions = begin ruby_version_files = [ fetch_file(".ruby-version"), fetch_file("Gemfile"), fetch_file("Gemfile.lock"), fetch_file(".tool-versions") ].compact ruby_version_files.filter_map { |file| parse_version_file(file) } end end