-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add logic for parsing Gemfile.lock & comparating it to Rubygems
- Loading branch information
Showing
29 changed files
with
516 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
defaults |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
//= link_tree ../images | ||
//= link_directory ../stylesheets .css | ||
//= link application.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'csv' | ||
|
||
class ProjectsController < ApplicationController | ||
def show | ||
project_file_name = Chart::FileStorage.find(params[:id]) | ||
|
||
@project = Project.new( | ||
project_file_name: project_file_name, | ||
data: CSV.read(project_file_name, col_sep: ';').to_h | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
module Chart | ||
def self.generate(**args) | ||
generator = Chart::Generator.new(**args).create | ||
|
||
Chart::FileStorage.create(name: generator.project_name, days: generator.days) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module Chart | ||
class Day | ||
attr_reader :date | ||
attr_reader :outdated_gem_count | ||
|
||
def initialize(date:, outdated_gem_count:) | ||
@date = date | ||
@outdated_gem_count = outdated_gem_count | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
module Chart | ||
class FileStorage | ||
class << self | ||
def create(**args) | ||
new(**args).create | ||
end | ||
|
||
def find(name) | ||
file = new(name: name) | ||
raise ActiveRecord::RecordNotFound, 'file not found' unless File.exist?(file.file_path) | ||
|
||
file.file_path | ||
end | ||
end | ||
|
||
attr_reader :name | ||
|
||
def initialize(name:, days: []) | ||
@name = name | ||
@days = days | ||
@file = nil | ||
end | ||
|
||
def create | ||
self.file = File.open(file_path, 'w') do |file| | ||
days.each do |day| | ||
file.puts "#{day.date};#{day.outdated_gem_count}" | ||
end | ||
end | ||
|
||
self | ||
end | ||
|
||
def file_path | ||
"#{Rails.root}/public/data/#{name}.csv" | ||
end | ||
|
||
private | ||
|
||
attr_reader :days | ||
attr_writer :file | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# frozen_string_literal: true | ||
|
||
module Chart | ||
class Generator | ||
attr_reader :days | ||
|
||
def initialize(start_date:, end_date:, repo:) | ||
@start_date = start_date | ||
@end_date = end_date | ||
@repo = repo | ||
@days = [] | ||
@progress = ProgressBar.new((end_date - start_date).to_i + 1) | ||
end | ||
|
||
def create | ||
self.days = map_days | ||
|
||
self | ||
end | ||
|
||
def project_name | ||
repo.split('/').last | ||
end | ||
|
||
private | ||
|
||
attr_reader :start_date | ||
attr_reader :end_date | ||
attr_reader :progress | ||
attr_reader :repo | ||
attr_writer :days | ||
|
||
def map_days | ||
previous_sha = nil | ||
|
||
(start_date..end_date).map do |date| | ||
sha = `cd #{repo} && git rev-list -1 --before="#{date}" master`.strip | ||
|
||
`cd #{repo} && OVERCOMMIT_DISABLE=1 git checkout #{sha} Gemfile.lock > /dev/null 2>&1` if previous_sha != sha | ||
|
||
count = outdated_gem_count(date) | ||
previous_sha = sha | ||
progress.increment! | ||
|
||
Day.new(date:, outdated_gem_count: count) | ||
end | ||
end | ||
|
||
def outdated_gem_count(time) | ||
count = 0 | ||
parser.specs.each do |gem_specification| | ||
gem = Rubygem.find_by(name: gem_specification.name) | ||
current_version = gem.versions.release.find_by(number: gem_specification.version.to_s) | ||
next if current_version.nil? || gem.versions.release.empty? | ||
|
||
count += 1 if gem.versions.release.where(position: ...current_version.position, created_at: ...time).any? | ||
end | ||
|
||
count | ||
end | ||
|
||
def parser | ||
Bundler::LockfileParser.new(gemfile_lock) | ||
end | ||
|
||
def gemfile_lock | ||
Bundler.read_file("#{repo}/Gemfile.lock") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails | ||
|
||
import "echarts" | ||
import "echarts/theme/dark" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class Project | ||
include ActiveModel::Model | ||
|
||
attr_accessor :project_file_name, :data | ||
|
||
def name | ||
project_file_name.split('/').last.split('.csv').first | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
# == Schema Information | ||
# | ||
# Table name: rubygems | ||
# | ||
# id :integer not null, primary key | ||
# name :string | ||
# token :string | ||
# created_at :datetime | ||
# updated_at :datetime | ||
# user_id :integer | ||
# | ||
class Rubygem < ApplicationRecord | ||
has_many :versions, dependent: :destroy | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
# == Schema Information | ||
# | ||
# Table name: versions | ||
# | ||
# id :integer not null, primary key | ||
# authors :string | ||
# description :text | ||
# downloads :integer default(0) | ||
# number :string | ||
# position :integer | ||
# created_at :datetime | ||
# updated_at :datetime | ||
# rubygem_id :integer | ||
# | ||
# Indexes | ||
# | ||
# index_versions_on_position (position) | ||
# | ||
class Version < ApplicationRecord | ||
belongs_to :rubygem | ||
|
||
scope :release, -> { where(prerelease: false) } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
h1 = @project.name | ||
= bar_chart @project.data, class: 'box', theme: 'sakura', options: { series: { barWidth: '50%' } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require_relative "../config/application" | ||
require "importmap/commands" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Pin npm packages by running ./bin/importmap | ||
|
||
pin "application", to: "application.js" | ||
pin "echarts", to: "echarts.min.js" | ||
pin "echarts/theme/dark", to: "echarts/theme/dark.js" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,3 @@ | ||
Rails.application.routes.draw do | ||
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html | ||
|
||
# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500. | ||
# Can be used by load balancers and uptime monitors to verify that the app is live. | ||
get "up" => "rails/health#show", as: :rails_health_check | ||
|
||
# Defines the root path route ("/") | ||
# root "posts#index" | ||
resources :projects, only: [:show] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class CreateRubygems < ActiveRecord::Migration[4.2] | ||
def self.up | ||
create_table :rubygems do |table| | ||
table.string :name | ||
table.string :token | ||
table.integer :user_id | ||
table.timestamps | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :rubygems | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class CreateVersions < ActiveRecord::Migration[4.2] | ||
def change | ||
create_table :versions do |table| | ||
table.string :authors | ||
table.text :description | ||
table.integer :downloads, default: 0 | ||
table.string :number | ||
table.integer :rubygem_id | ||
table.integer :position, index: true | ||
table.timestamps | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.