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

Fix rubocop offenses #21

Open
wants to merge 1 commit into
base: master
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: 7 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
AllCops:
Exclude:
- db/schema.rb
Documentation:
Enabled: false
LineLength:
Max: 100
3 changes: 0 additions & 3 deletions app/controllers/api/v1/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
module Api
module V1
class ApplicationController < ::ApplicationController

def authenticate_user!
if session[:user_id]
current_user
else
render json: { message: 'Invalid credentials' }
end
end

end
end
end

2 changes: 0 additions & 2 deletions app/controllers/api/v1/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ def create
def comment_params
params.permit(:repo, :pull, :text)
end

end
end
end

2 changes: 0 additions & 2 deletions app/controllers/api/v1/diffs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ def show
def diff_params
params.permit(:id, :repo)
end

end
end
end

2 changes: 0 additions & 2 deletions app/controllers/api/v1/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ def index
def organizations
GithubService.new(session[:user_token]).organizations
end

end
end
end

6 changes: 3 additions & 3 deletions app/controllers/api/v1/pulls_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ def update
end

def mergeable
render json: { mergeable: GithubService.new(session[:user_token]).pull_mergeable?(pull_params) }
render json: {
mergeable: GithubService.new(session[:user_token]).pull_mergeable?(pull_params)
}
end

private
Expand All @@ -38,8 +40,6 @@ def pull_requests
def organization
params[:organization] || 'crowdint'
end

end
end
end

2 changes: 0 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@ def authenticate_user!
redirect_to root_path
end
end

end

2 changes: 0 additions & 2 deletions app/controllers/concerns/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ def initialize(params)
@username = params[:user][:login]
@avatar = params[:user][:avatar_url]
end

end

2 changes: 0 additions & 2 deletions app/controllers/concerns/github_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ def initialize(params)
@avatar = params[:avatar_url]
@url = params[:html_url]
end

end

2 changes: 0 additions & 2 deletions app/controllers/concerns/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ def initialize(params)
@name = params[:login]
@avatar = params[:avatar_url]
end

end

5 changes: 2 additions & 3 deletions app/controllers/concerns/pull_request.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class PullRequest
attr_accessor :id, :title, :url, :user, :created_at, :repository, :comments_count, :number, :is_private, :mergeable
attr_accessor :id, :title, :url, :user, :created_at, :repository, :comments_count, :number,
:is_private, :mergeable

def initialize(params)
@id = params[:id]
Expand All @@ -13,6 +14,4 @@ def initialize(params)
@is_private = params[:base][:repo][:private]
@mergeable = true
end

end

2 changes: 0 additions & 2 deletions app/controllers/concerns/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ def initialize(params)
@description = params[:description]
@private = params[:private]
end

end

2 changes: 0 additions & 2 deletions app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@ class DashboardController < ApplicationController
before_action :authenticate_user!

def index; end

end

10 changes: 6 additions & 4 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
class SessionsController < ApplicationController

def create
auth = request.env['omniauth.auth']
user = User.find_by_provider_and_uid(auth['provider'], auth['uid']) || User.create_with_omniauth(auth)
session[:user_id] = user.id
session[:user_id] = find_user(auth).id
session[:user_token] = auth['credentials']['token']

redirect_to dashboard_url, notice: 'Signed in!'
Expand All @@ -15,5 +13,9 @@ def destroy
redirect_to root_url, notice: 'Signed out!'
end

end
protected

def find_user(auth)
User.find_by_provider_and_uid(auth['provider'], auth['uid']) || User.create_with_omniauth(auth)
end
end
2 changes: 0 additions & 2 deletions app/controllers/settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ class SettingsController < ApplicationController
def analytics_keys
render json: ANALYTICS_KEYS, status: :ok
end

end

3 changes: 0 additions & 3 deletions app/controllers/welcome_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
class WelcomeController < ApplicationController

def index
redirect_to dashboard_path if current_user
end

end

2 changes: 0 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ def self.create_with_omniauth(auth)
user.avatar = auth['info']['image']
end
end

end

56 changes: 28 additions & 28 deletions app/services/github_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,7 @@ def initialize(token)

def pull_requests(organization)
Rails.cache.fetch("#{cache_key}/#{organization}/pulls", expires_in: 5.minutes) do
pulls = []

repos_for(organization).each do |repo|
if repo.issues_count > 0
pull_requests = github.pull_requests.list(user: organization, repo: repo.name, auto_pagination: true)

pull_requests.each do |pull|
pulls << PullRequest.new(pull)
end
end
end

repositories = pulls.map(&:repository).uniq { |e| [e.id] }
users = pulls.map(&:user).uniq { |e| [e.id] }

[pulls, repositories, users]
fetch_pull_requests(organization)
end
end

Expand All @@ -41,7 +26,7 @@ def organizations
end

def diff(params)
Rails.cache.fetch("#{cache_key}/diff/#{params[:repo]}/#{params[:id]}}", expires_in: 5.minutes) do
Rails.cache.fetch(diff_cache_key(params), expires_in: 5.minutes) do
uri = URI("https://api.github.com/repos/#{params[:repo]}/pulls/#{params[:id]}.diff")

req = Net::HTTP::Get.new(uri)
Expand All @@ -62,21 +47,18 @@ def create_pull_comment(params)
end

def pull_comments(params)
comments_list = []
user, repo = user_repo(params)

comments = github.issues.comments.list(user, repo, issue_id: params[:pull], auto_pagination: true)

comments.each do |comment|
comments_list << Comment.new(comment)
end

comments_list
comments = github.issues.comments.list user,
repo,
issue_id: params[:pull],
auto_pagination: true
comments.each_with_object([]) { |comment, list| list << Comment.new(comment) }
end

def merge_pull_request(params, current_user)
user, repo = user_repo(params)
github.pull_requests.merge user, repo, params[:id], commit_message: "Merged from PR Dashboard by #{current_user.nickname}"
message = "Merged from PR Dashboard by #{current_user.nickname}"
github.pull_requests.merge user, repo, params[:id], commit_message: message
end

def close_pull_request(params, _)
Expand All @@ -93,6 +75,10 @@ def pull_mergeable?(params)

private

def diff_cache_key(params)
"#{cache_key}/diff/#{params[:repo]}/#{params[:id]}}"
end

def repos_for(organization)
repos = []

Expand All @@ -112,5 +98,19 @@ def user_repo(params)
[info.first, info.last]
end

end
def fetch_pull_requests(organization)
pulls = repos_for(organization).each_with_object([]) do |repo, array|
next unless repo.issues_count > 0

pull_requests = github.pull_requests.list user: organization,
repo: repo.name,
auto_pagination: true
pull_requests.each { |pull| array << PullRequest.new(pull) }
end

repositories = pulls.map(&:repository).uniq { |e| [e.id] }
users = pulls.map(&:user).uniq { |e| [e.id] }

[pulls, repositories, users]
end
end
4 changes: 2 additions & 2 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
module Prdashboard
class Application < Rails::Application
config.assets.precompile += %w(
ember_application.js
analytics/analytics.js
ember_application.js
analytics/analytics.js
)
end
end
2 changes: 1 addition & 1 deletion config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# Configure static asset server for tests with Cache-Control for performance.
config.serve_static_assets = true
config.static_cache_control = "public, max-age=3600"
config.static_cache_control = 'public, max-age=3600'

# Show full error reports and disable caching.
config.consider_all_requests_local = true
Expand Down
6 changes: 3 additions & 3 deletions config/initializers/analytics.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Prdashboard::Application.config.analytics_id = Rails.env.production? ? ENV['ANALYTICS_ID'] : nil
Prdashboard::Application.config.analytics_domain = Rails.env.production? ? ENV['ANALYTICS_DOMAIN'] : nil

config = Prdashboard::Application.config
config.analytics_id = Rails.env.production? ? ENV['ANALYTICS_ID'] : nil
config.analytics_domain = Rails.env.production? ? ENV['ANALYTICS_DOMAIN'] : nil
6 changes: 4 additions & 2 deletions config/initializers/backtrace_silencers.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Be sure to restart your server when you modify this file.

# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your
# backtraces.
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }

# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
# You can also remove all the silencers if you're trying to debug a problem that might stem from
# framework code.
# Rails.backtrace_cleaner.remove_silencers!
1 change: 0 additions & 1 deletion config/initializers/omniauth.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Rails.application.config.middleware.use OmniAuth::Builder do
provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET'], scope: 'user,repo,read:org'
end

1 change: 0 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@
get '/analytics', to: 'settings#analytics_keys'

end

5 changes: 3 additions & 2 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
# This file should contain all the record creation needed to seed the database with its default
# values. The data can then be loaded with the rake db:seed (or created alongside the db with
# db:setup).
#
# Examples:
#
Expand Down
1 change: 0 additions & 1 deletion spec/controllers/api/v1/comments_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,3 @@
end
end
end

3 changes: 1 addition & 2 deletions spec/controllers/api/v1/diffs_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

describe '#show' do
context 'when user is signed in' do
let(:diff) { "le diff" }
let(:diff) { 'le diff' }

before do
GithubService.any_instance.stub(:diff).and_return diff
Expand All @@ -31,4 +31,3 @@
end
end
end

1 change: 0 additions & 1 deletion spec/controllers/api/v1/organizations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,3 @@
end
end
end

1 change: 0 additions & 1 deletion spec/controllers/api/v1/pulls_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,3 @@
end

end

1 change: 0 additions & 1 deletion spec/controllers/dashboard_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@
end
end
end

3 changes: 1 addition & 2 deletions spec/controllers/sessions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe SessionsController do
describe '#create' do
before do
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:github]
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:github]
post :create
end

Expand Down Expand Up @@ -32,4 +32,3 @@
end
end
end

1 change: 0 additions & 1 deletion spec/controllers/welcome_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@
end
end
end

Loading