Skip to content

Commit

Permalink
Fix more Rubocop offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo Figarola committed Apr 12, 2014
1 parent 2a36af2 commit 34b1e97
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 53 deletions.
4 changes: 2 additions & 2 deletions app/controllers/api/v1/comments_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module Api
module V1
class CommentsController < Api::V1::ApplicationController
before_filter :authenticate_user!
before_action :authenticate_user!

def index
@comments = GithubService.new(session[:user_token]).get_pull_comments(comment_params)
@comments = GithubService.new(session[:user_token]).pull_comments(comment_params)

render 'api/v1/comments/index'
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/v1/diffs_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module Api
module V1
class DiffsController < Api::V1::ApplicationController
before_filter :authenticate_user!
before_action :authenticate_user!

def show
render text: GithubService.new(session[:user_token]).get_diff(diff_params)
render text: GithubService.new(session[:user_token]).diff(diff_params)
end

private
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/api/v1/organizations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
module Api
module V1
class OrganizationsController < Api::V1::ApplicationController
before_filter :authenticate_user!
before_action :authenticate_user!

def index
@organizations = get_organizations
@organizations = organizations

render 'api/v1/organizations/index'
end

private

def get_organizations
GithubService.new(session[:user_token]).get_organizations
def organizations
GithubService.new(session[:user_token]).organizations
end

end
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/api/v1/pulls_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module Api
module V1
class PullsController < Api::V1::ApplicationController
before_filter :authenticate_user!
before_action :authenticate_user!

def index
@pull_requests, @repositories, @users = get_pull_requests
@pull_requests, @repositories, @users = pull_requests
render 'api/v1/pulls/index'
end

Expand All @@ -31,8 +31,8 @@ def pull_params
params.permit(:id, :repo)
end

def get_pull_requests
GithubService.new(session[:user_token]).get_pull_requests organization
def pull_requests
GithubService.new(session[:user_token]).pull_requests organization
end

def organization
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class DashboardController < ApplicationController
layout 'dashboard'
before_filter :authenticate_user!
before_action :authenticate_user!

def index; end

Expand Down
28 changes: 14 additions & 14 deletions app/services/github_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def initialize(token)
@github = Github.new oauth_token: token
end

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

Expand All @@ -27,7 +27,7 @@ def get_pull_requests(organization)
end
end

def get_organizations
def organizations
orgs = []
organizations = github.orgs.list

Expand All @@ -40,30 +40,30 @@ def get_organizations
orgs.sort_by { |org| org.name }
end

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

req = Net::HTTP::Get.new(uri)
req['Authorization'] = "token #{token}"
req['Accept'] = "application/vnd.github.v3.diff"
req['Accept'] = 'application/vnd.github.v3.diff'

res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') { |http|
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
http.request(req)
}
end

res.body
end
end

def create_pull_comment(params)
user, repo = get_user_repo(params)
user, repo = user_repo(params)
github.issues.comments.create user, repo, params[:pull], body: params[:text]
end

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

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

Expand All @@ -75,17 +75,17 @@ def get_pull_comments(params)
end

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

def close_pull_request(params, _)
user, repo = get_user_repo(params)
user, repo = user_repo(params)
github.pull_requests.update user, repo, params[:id], state: 'closed'
end

def pull_mergeable?(params)
user, repo = get_user_repo(params)
user, repo = user_repo(params)
pull = github.pull_requests.get user, repo, params[:id]

pull[:mergeable]
Expand All @@ -107,9 +107,9 @@ def cache_key
Digest::MD5.hexdigest("#{@token}")
end

def get_user_repo(params)
def user_repo(params)
info = params[:repo].split('/')
[ info.first, info.last ]
[info.first, info.last]
end

end
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/api/v1/comments_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

context 'when user is signed in' do
before do
GithubService.any_instance.stub(:get_pull_comments).and_return comments
GithubService.any_instance.stub(:pull_comments).and_return comments
signin_user
xhr :get, :index
end
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/api/v1/diffs_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
let(:diff) { "le diff" }

before do
GithubService.any_instance.stub(:get_diff).and_return diff
GithubService.any_instance.stub(:diff).and_return diff
signin_user
xhr :get, :show, id: 1
end
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/api/v1/organizations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
end

before do
GithubService.any_instance.stub(:get_organizations).and_return organizations
GithubService.any_instance.stub(:organizations).and_return organizations
signin_user
end

Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/api/v1/pulls_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
describe '#index' do
context 'when user is signed in' do
before do
GithubService.any_instance.stub(:get_pull_requests).and_return pulls
GithubService.any_instance.stub(:pull_requests).and_return pulls
signin_user
end

Expand Down
44 changes: 22 additions & 22 deletions spec/services/github_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
end
end

describe '#get_pull_requests' do
describe '#pull_requests' do
let(:repos) do
[
OpenStruct.new(name: 'rails3-jquery-autocomplete', issues_count: 1)
Expand All @@ -39,23 +39,23 @@
[
{
id: 13748176,
html_url: "https://github.com/crowdint/rails3-jquery-autocomplete/pull/264",
html_url: 'https://github.com/crowdint/rails3-jquery-autocomplete/pull/264',
number: 264,
title: "1.0.13 broken for Mongoid, items is not an array",
created_at: "2014-03-19T17:21:27Z",
title: '1.0.13 broken for Mongoid, items is not an array',
created_at: '2014-03-19T17:21:27Z',
user: {
login: "danielfarrell",
login: 'danielfarrell',
id: 13850,
avatar_url: "https://avatars.githubusercontent.com/u/13850?",
html_url: "https://github.com/danielfarrell"
avatar_url: 'https://avatars.githubusercontent.com/u/13850?',
html_url: 'https://github.com/danielfarrell'
},
base: {
repo: {
id: 778055,
name: "rails3-jquery-autocomplete",
full_name: "crowdint/rails3-jquery-autocomplete",
name: 'rails3-jquery-autocomplete',
full_name: 'crowdint/rails3-jquery-autocomplete',
private: false,
html_url: "https://github.com/crowdint/rails3-jquery-autocomplete",
html_url: 'https://github.com/crowdint/rails3-jquery-autocomplete',
description: "An easy and unobtrusive way to use jQuery's autocomplete with Rails 3"
}
}
Expand All @@ -69,19 +69,19 @@
end

it 'returns pulls objects as the first positon of array' do
expect(subject.get_pull_requests('crowdint')[0].first).to be_a PullRequest
expect(subject.pull_requests('crowdint')[0].first).to be_a PullRequest
end

it 'returns repositories objecs as the second position of array' do
expect(subject.get_pull_requests('crowdint')[1].first).to be_a Repository
expect(subject.pull_requests('crowdint')[1].first).to be_a Repository
end

it 'returns github users objects as the last position of array' do
expect(subject.get_pull_requests('crowdint')[2].first).to be_a GithubUser
expect(subject.pull_requests('crowdint')[2].first).to be_a GithubUser
end
end

describe '#get_organizations' do
describe '#organizations' do
let(:body) do
[
{
Expand Down Expand Up @@ -115,22 +115,22 @@
end

it 'returns an array with 2 objects' do
expect(subject.get_organizations.size).to eql 2
expect(subject.organizations.size).to eql 2
end

it 'returns Organization objects' do
expect(subject.get_organizations.first).to be_a Organization
expect(subject.organizations.first).to be_a Organization
end
end


describe '#get_diff' do
describe '#diff' do
before do
Net::HTTP.stub(:start).and_return OpenStruct.new(body: 'le diff')
end

it 'returns diff text for a given pull request' do
expect(subject.get_diff(pull_params)).to eql 'le diff'
expect(subject.diff(pull_params)).to eql 'le diff'
end
end

Expand All @@ -144,7 +144,7 @@
end
end

describe '#get_pull_comments' do
describe '#pull_comments' do
let(:comments) do
[
{
Expand All @@ -171,11 +171,11 @@
end

it 'gets an array of 2 comments from a pull request' do
expect(subject.get_pull_comments(pull_params).size).to eql 2
expect(subject.pull_comments(pull_params).size).to eql 2
end

it 'gets an array of Comments objects' do
expect(subject.get_pull_comments(pull_params).first).to be_a Comment
expect(subject.pull_comments(pull_params).first).to be_a Comment
end
end

Expand All @@ -201,7 +201,7 @@

describe '#pull_mergeable?' do
before do
Github::Client.any_instance.stub_chain(:pull_requests, :get).and_return({ mergeable: true })
Github::Client.any_instance.stub_chain(:pull_requests, :get).and_return(mergeable: true)
end

it 'returns the mergeable property of a pull request' do
Expand Down

0 comments on commit 34b1e97

Please sign in to comment.