Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kjr/updates #38

Open
wants to merge 2 commits into
base: release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ source 'https://rubygems.org'

git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.5.3'
ruby '2.7.2'

gem 'bootsnap', '>= 1.4.2', require: false
gem 'dotenv'
gem 'graphql-client'
gem 'jbuilder', '~> 2.7'
gem 'pg'
gem 'puma', '~> 4.3'
gem 'puma'
gem 'rack-attack'
gem 'rails', '~> 6.0.2', '>= 6.0.2.1'
gem 'sidekiq'
Expand All @@ -22,6 +22,9 @@ gem 'webpacker', '~> 4.0'
# but today is not that day.
gem 'coffee-rails'

# Transactional email service
gem 'postmark-rails'

group :development, :test do
gem 'dotenv-rails'
gem 'pry'
Expand Down
13 changes: 10 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ GEM
concurrent-ruby (~> 1.0)
jbuilder (2.9.1)
activesupport (>= 4.2.0)
json (2.5.1)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
Expand All @@ -110,10 +111,15 @@ GEM
nokogiri (1.10.8)
mini_portile2 (~> 2.4.0)
pg (1.2.2)
postmark (1.21.3)
json
postmark-rails (0.20.0)
actionmailer (>= 3.0.0)
postmark (~> 1.15)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
puma (4.3.5)
puma (5.1.1)
nio4r (~> 2.0)
rack (2.2.3)
rack-attack (6.2.2)
Expand Down Expand Up @@ -229,8 +235,9 @@ DEPENDENCIES
jbuilder (~> 2.7)
listen (>= 3.0.5, < 3.2)
pg
postmark-rails
pry
puma (~> 4.3)
puma
rack-attack
rails (~> 6.0.2, >= 6.0.2.1)
rspec-rails
Expand All @@ -241,7 +248,7 @@ DEPENDENCIES
webpacker (~> 4.0)

RUBY VERSION
ruby 2.5.3p105
ruby 2.7.2p137

BUNDLED WITH
2.1.4
24 changes: 19 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,25 @@ Challenge OSS maintainers to re-license with an ethical license so that Palantir

# Local dev

To create junk data, run `bin/rake defaults:sample_data`
## Setup

`bundle`

`bundle exec rails db:create`

`bundle exec rails db:schema:load`

`cp .env.example .env`

## Seed data

To create junk data, run `bin/rake defaults:junk_data`

## Real Data

To set up your local environment with real data:

* Copy `.env.example` to `.env`
* Set the `GITHUB_TOKEN` in `.env` to any GitHub token with org and repo read permissions
* Set defaults: `bin/rake defaults:init`
* Fetch projects and their dependencies using the background job queue: `bin/rake scheduled_tasks:update
- Copy `.env.example` to `.env`
- Set the `GITHUB_TOKEN` in `.env` to any GitHub token with org and repo read permissions
- Set defaults: `bin/rake defaults:init`
- Fetch projects and their dependencies using the background job queue: `bin/rake scheduled_tasks:update
2 changes: 1 addition & 1 deletion app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: '[email protected]'
default from: '[email protected]'
layout 'mailer'
end
10 changes: 10 additions & 0 deletions app/mailers/hippocratic_alert_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class HippocraticAlertMailer < ApplicationMailer
def alert(dependency_name)
@dependency_name = dependency_name
mail(
subject: 'Hippocratic License Alert',
to: ENV['ALERT_EMAIL_ADDRESSES'],
html_body: "'#{dependency_name}' is using the Hippocratic License!",
message_stream: 'notifications')
end
end
8 changes: 5 additions & 3 deletions app/models/dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ class Dependency < ApplicationRecord

def update_with_details
details = DependencyDetailsFetcher.new(self).fetch
license_name = details[:license] || "Unknown"
license = License.find_or_create_by(name: license_name)
self.source_repo_url = details[:url]
self.license = license
license_name = details[:license] || "Unknown"
self.license = License.find_or_create_by(name: license_name)
if license_name == "MIT-Hippocratic-1.2"
HippocraticAlertMailer.alert(name)
end
end
end
2 changes: 1 addition & 1 deletion app/models/package_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ class PackageManager < ApplicationRecord

private
def set_language
self.language = Language.find_or_create_by(name: MANAGERS[self.name])
self.language = Language.find_or_create_by(name: MANAGERS[name])
end
end
2 changes: 1 addition & 1 deletion app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Project < ApplicationRecord
validates :name, uniqueness: true, presence: true

def github_identifier
"#{self.org_name}/#{self.name}"
"#{org_name}/#{name}"
end

end
1 change: 1 addition & 0 deletions app/views/hippocratic_alert_mailer/alert.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'<%= @dependency_name %>' is using the Hippocratic License!
6 changes: 6 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,11 @@ class Application < Rails::Application
config.load_defaults 6.0
config.autoload_paths << "#{Rails.root}/app/services/*"
config.active_job.queue_adapter = :sidekiq

config.action_mailer.delivery_method = :postmark

config.action_mailer.postmark_settings = {
api_token: Rails.application.credentials.postmark_api_token
}
end
end
1 change: 1 addition & 0 deletions config/credentials.yml.enc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mSk7HEcfdczw+naGIebobwZB1n1pPPettZOtBpSHJ/qvbkXYNn+BjVH9ZJLzXD7q3AlKLptOsuNTU8K+4piwflBsVmBFFzus28DP+vc0XFRXaLBeL3OVFUb2rpBqDvYBoNdQaA/11XJz4fZ+TroNgGXAdG7oD3YerE7qBdIx9PpVef/19l6S9eAX5W3Ljt5AlazDvc4jXd6fdjZPaL8qVyvSnoO9yuYOjAdeauR2Ow5TcwRd1t5qWf2Z5W3+Mt8tV2znhL/5rs0QwUXfjCpVRyKjh4SCwlSKGJ+WSf/FURQ30yqoqcI3C544af5W3GjJRorstds0XDZMan5zZfh/DDeK+Mr3KkUxZo3arCcepZ9jeiGQYbNjdm9SR0fC/K6ppdUNE0fE3lcelczkHbrhn0OCdNSvjCRYc8wPzmEfMSOeE0gpsVZbQzDV3L0Vsy8j5E6+q1r97yHOoCi1cmosfTxUuWMhQeKXuimoU2b+sM7Y--bqaAhpt+XCcZP/cM--qErv/AUFYTF21+QGe7Fbdw==
1 change: 0 additions & 1 deletion config/initializers/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
# - Use digests to stop length information leaking (see also ActiveSupport::SecurityUtils.variable_size_secure_compare)
ActiveSupport::SecurityUtils.secure_compare(::Digest::SHA256.hexdigest(username), ::Digest::SHA256.hexdigest(ENV["SIDEKIQ_USERNAME"])) &
ActiveSupport::SecurityUtils.secure_compare(::Digest::SHA256.hexdigest(password), ::Digest::SHA256.hexdigest(ENV["SIDEKIQ_PASSWORD"]))

end
Sidekiq::Web.set :sessions, false
1 change: 0 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
Rails.application.routes.draw do
mount Sidekiq::Web => '/sidekiq'


resources :projects, only: [:index, :show]

root "home#show"
Expand Down