Skip to content

Commit 995c32e

Browse files
committed
Rubocop automated fixes
1 parent 122ad0e commit 995c32e

File tree

11 files changed

+61
-61
lines changed

11 files changed

+61
-61
lines changed

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
source 'https://rubygems.org'
1+
source "https://rubygems.org"
22

33
# Use the gems defined in the plugins gemspec
44
gemspec(:path => File.dirname(__FILE__))

Rakefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
require "bundler/gem_tasks"
2-
require 'rake/testtask'
2+
require "rake/testtask"
33

44
Rake::TestTask.new do |t|
55
t.libs << "test"
6-
files = FileList['test/**/*test.rb']
6+
files = FileList["test/**/*test.rb"]
77
t.test_files = files
88
t.verbose = true
99
end

app/controllers/github_hook_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'json'
1+
require "json"
22

33
class GithubHookController < ApplicationController
44
skip_before_filter :verify_authenticity_token, :check_if_login_required
+3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
module GithubHook
22
class NullLogger
33
def debug(*_); end
4+
45
def info(*_); end
6+
57
def warn(*_); end
8+
69
def error(*_); end
710
end
811
end

app/services/github_hook/updater.rb

+16-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module GithubHook
22
class Updater
3-
GIT_BIN = Redmine::Configuration['scm_git_command'] || "git"
3+
GIT_BIN = Redmine::Configuration["scm_git_command"] || "git"
44

55
attr_writer :logger
66

@@ -23,7 +23,7 @@ def call
2323
repository.fetch_changesets
2424
tr2 = Time.now
2525

26-
logger.info { " GithubHook: Redmine repository updated: #{repository.identifier} (Git: #{time_diff_milli(tg1,tg2)}ms, Redmine: #{time_diff_milli(tr1,tr2)}ms)" }
26+
logger.info { " GithubHook: Redmine repository updated: #{repository.identifier} (Git: #{time_diff_milli(tg1, tg2)}ms, Redmine: #{time_diff_milli(tr1, tr2)}ms)" }
2727
end
2828
end
2929

@@ -40,7 +40,7 @@ def exec(command, directory)
4040
logger.debug { " GithubHook: Executing command: '#{command}'" }
4141

4242
# Get a path to a temp file
43-
logfile = Tempfile.new('github_hook_exec')
43+
logfile = Tempfile.new("github_hook_exec")
4444
logfile.close
4545

4646
full_command = "#{command} > #{logfile.path} 2>&1"
@@ -54,9 +54,9 @@ def exec(command, directory)
5454

5555
output_from_command = File.readlines(logfile.path)
5656
if success
57-
logger.debug { " GithubHook: Command output: #{output_from_command.inspect}"}
57+
logger.debug { " GithubHook: Command output: #{output_from_command.inspect}" }
5858
else
59-
logger.error { " GithubHook: Command '#{command}' didn't exit properly. Full output: #{output_from_command.inspect}"}
59+
logger.error { " GithubHook: Command '#{command}' didn't exit properly. Full output: #{output_from_command.inspect}" }
6060
end
6161

6262
return success
@@ -68,8 +68,8 @@ def exec(command, directory)
6868
def find_project
6969
identifier = get_identifier
7070
project = Project.find_by_identifier(identifier.downcase)
71-
raise ActiveRecord::RecordNotFound, "No project found with identifier '#{identifier}'" if project.nil?
72-
return project
71+
fail ActiveRecord::RecordNotFound, "No project found with identifier '#{identifier}'" if project.nil?
72+
project
7373
end
7474

7575
# Returns the Redmine Repository object we are trying to update
@@ -79,41 +79,41 @@ def find_repositories
7979
repo.is_a?(Repository::Git)
8080
end
8181

82-
if repositories.nil? or repositories.length == 0
83-
raise TypeError, "Project '#{project.to_s}' ('#{project.identifier}') has no repository"
82+
if repositories.nil? || repositories.length == 0
83+
fail TypeError, "Project '#{project}' ('#{project.identifier}') has no repository"
8484
end
8585

8686
# if a specific repository id is passed in url parameter "repository_id", then try to find it in
8787
# the list of current project repositories and use only this and not all to pull changes from
8888
# (issue #54)
89-
if params.has_key?(:repository_id)
89+
if params.key?(:repository_id)
9090
param_repo = repositories.select do |repo|
9191
repo.identifier == params[:repository_id]
9292
end
9393

94-
if param_repo.nil? or param_repo.length == 0
94+
if param_repo.nil? || param_repo.length == 0
9595
logger.info { " GithubHook: The repository '#{params[:repository_id]}' isn't in the list of projects repos. Updating all repos instead." }
9696

9797
else
9898
repositories = param_repo
9999
end
100100
end
101101

102-
return repositories
102+
repositories
103103
end
104104

105105
# Gets the project identifier from the querystring parameters and if that's not supplied, assume
106106
# the Github repository name is the same as the project identifier.
107107
def get_identifier
108108
identifier = get_project_name
109-
raise ActiveRecord::RecordNotFound, "Project identifier not specified" if identifier.nil?
110-
return identifier
109+
fail ActiveRecord::RecordNotFound, "Project identifier not specified" if identifier.nil?
110+
identifier
111111
end
112112

113113
# Attempts to find the project name. It first looks in the params, then in the
114114
# payload if params[:project_id] isn't given.
115115
def get_project_name
116-
params[:project_id] || (payload['repository'] ? payload['repository']['name'] : nil)
116+
params[:project_id] || (payload["repository"] ? payload["repository"]["name"] : nil)
117117
end
118118

119119
def git_command(command)
@@ -134,12 +134,11 @@ def time_diff_milli(start, finish)
134134

135135
# Fetches updates from the remote repository
136136
def update_repository(repository)
137-
command = git_command('fetch origin')
137+
command = git_command("fetch origin")
138138
if exec(command, repository.url)
139139
command = git_command("fetch --prune origin \"+refs/heads/*:refs/heads/*\"")
140140
exec(command, repository.url)
141141
end
142142
end
143-
144143
end
145144
end

config/routes.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
RedmineApp::Application.routes.draw do
2-
match 'github_hook' => 'github_hook#index', :via => [:post]
3-
match 'github_hook' => 'github_hook#welcome', :via => [:get]
2+
match "github_hook" => 'github_hook#index', :via => [:post]
3+
match "github_hook" => 'github_hook#welcome', :via => [:get]
44
end

init.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
require 'redmine'
1+
require "redmine"
22

33
Redmine::Plugin.register :redmine_github_hook do
4-
name 'Redmine Github Hook plugin'
5-
author 'Jakob Skjerning'
6-
description 'This plugin allows your Redmine installation to receive Github post-receive notifications'
7-
url 'https://github.com/koppen/redmine_github_hook'
8-
author_url 'http://mentalized.net'
4+
name "Redmine Github Hook plugin"
5+
author "Jakob Skjerning"
6+
description "This plugin allows your Redmine installation to receive Github post-receive notifications"
7+
url "https://github.com/koppen/redmine_github_hook"
8+
author_url "http://mentalized.net"
99
version RedmineGithubHook::VERSION
1010
end

redmine_github_hook.gemspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# coding: utf-8
2-
lib = File.expand_path('../lib', __FILE__)
2+
lib = File.expand_path("../lib", __FILE__)
33
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4-
require 'redmine_github_hook/version'
4+
require "redmine_github_hook/version"
55

66
Gem::Specification.new do |spec|
77
spec.name = "redmine_github_hook"

test/functional/github_hook_controller_test.rb

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
require 'test_helper'
1+
require "test_helper"
22

3-
require 'test/unit'
4-
require 'mocha'
3+
require "test/unit"
4+
require "mocha"
55

66
class GithubHookControllerTest < ActionController::TestCase
77
def json
@@ -65,7 +65,7 @@ def project
6565
end
6666

6767
def setup
68-
Project.stubs(:find_by_identifier).with('github').returns(project)
68+
Project.stubs(:find_by_identifier).with("github").returns(project)
6969

7070
# Make sure we don't run actual commands in test
7171
GithubHook::Updater.any_instance.expects(:system).never
@@ -88,9 +88,9 @@ def test_should_render_error_message
8888
do_post
8989
assert_response :not_found
9090
assert_equal({
91-
"title" => "ActiveRecord::RecordNotFound",
92-
"message" => "Repository not found"
93-
}, JSON.parse(@response.body))
91+
"title" => "ActiveRecord::RecordNotFound",
92+
"message" => "Repository not found"
93+
}, JSON.parse(@response.body))
9494
end
9595

9696
def test_should_not_require_login
@@ -115,5 +115,4 @@ def test_should_respond_to_get
115115
get :index
116116
assert_response :success
117117
end
118-
119118
end

test/test_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Load the normal Rails helper from the Redmine host app
2-
require File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper')
2+
require File.expand_path(File.dirname(__FILE__) + "/../../../test/test_helper")

test/unit/github_hook/updater_test.rb

+20-21
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
require 'test_helper'
1+
require "test_helper"
22

3-
require 'test/unit'
4-
require 'mocha'
3+
require "test/unit"
4+
require "mocha"
55

66
class GithubHookUpdaterTest < Test::Unit::TestCase
7-
87
def project
98
return @project if @project
109

@@ -23,7 +22,7 @@ def repository
2322

2423
def payload
2524
# Ruby hash with the parsed data from the JSON payload
26-
{"before" => "5aef35982fb2d34e9d9d4502f6ede1072793222d", "repository"=>{"url" => "http://github.com/defunkt/github", "name" => "github", "description" => "You're lookin' at it.", "watchers"=>5, "forks"=>2, "private"=>1, "owner"=>{"email" => "[email protected]", "name" => "defunkt"}}, "commits"=>[{"id" => "41a212ee83ca127e3c8cf465891ab7216a705f59", "url" => "http://github.com/defunkt/github/commit/41a212ee83ca127e3c8cf465891ab7216a705f59", "author"=>{"email" => "[email protected]", "name" => "Chris Wanstrath"}, "message" => "okay i give in", "timestamp" => "2008-02-15T14:57:17-08:00", "added"=>["filepath.rb"]}, {"id" => "de8251ff97ee194a289832576287d6f8ad74e3d0", "url" => "http://github.com/defunkt/github/commit/de8251ff97ee194a289832576287d6f8ad74e3d0", "author"=>{"email" => "[email protected]", "name" => "Chris Wanstrath"}, "message" => "update pricing a tad", "timestamp" => "2008-02-15T14:36:34-08:00"}], "after" => "de8251ff97ee194a289832576287d6f8ad74e3d0", "ref" => "refs/heads/master"}
25+
{"before" => "5aef35982fb2d34e9d9d4502f6ede1072793222d", "repository" => {"url" => "http://github.com/defunkt/github", "name" => "github", "description" => "You're lookin' at it.", "watchers" => 5, "forks" => 2, "private" => 1, "owner" => {"email" => "[email protected]", "name" => "defunkt"}}, "commits" => [{"id" => "41a212ee83ca127e3c8cf465891ab7216a705f59", "url" => "http://github.com/defunkt/github/commit/41a212ee83ca127e3c8cf465891ab7216a705f59", "author" => {"email" => "[email protected]", "name" => "Chris Wanstrath"}, "message" => "okay i give in", "timestamp" => "2008-02-15T14:57:17-08:00", "added" => ["filepath.rb"]}, {"id" => "de8251ff97ee194a289832576287d6f8ad74e3d0", "url" => "http://github.com/defunkt/github/commit/de8251ff97ee194a289832576287d6f8ad74e3d0", "author" => {"email" => "[email protected]", "name" => "Chris Wanstrath"}, "message" => "update pricing a tad", "timestamp" => "2008-02-15T14:36:34-08:00"}], "after" => "de8251ff97ee194a289832576287d6f8ad74e3d0", "ref" => "refs/heads/master"}
2726
end
2827

2928
def build_updater(payload, options = {})
@@ -38,7 +37,7 @@ def updater
3837
end
3938

4039
def setup
41-
Project.stubs(:find_by_identifier).with('github').returns(project)
40+
Project.stubs(:find_by_identifier).with("github").returns(project)
4241

4342
# Make sure we don't run actual commands in test
4443
GithubHook::Updater.any_instance.expects(:system).never
@@ -50,7 +49,7 @@ def teardown
5049
end
5150

5251
def test_uses_repository_name_as_project_identifier
53-
Project.expects(:find_by_identifier).with('github').returns(project)
52+
Project.expects(:find_by_identifier).with("github").returns(project)
5453
updater.call
5554
end
5655

@@ -72,8 +71,8 @@ def test_resets_repository_when_fetch_origin_fails
7271
end
7372

7473
def test_uses_project_identifier_from_request
75-
Project.expects(:find_by_identifier).with('redmine').returns(project)
76-
updater = build_updater(payload, {:project_id => 'redmine'})
74+
Project.expects(:find_by_identifier).with("redmine").returns(project)
75+
updater = build_updater(payload, :project_id => "redmine")
7776
updater.call
7877
end
7978

@@ -92,7 +91,7 @@ def test_updates_only_the_specified_repository
9291
another_repository.expects(:fetch_changesets).never
9392
project.repositories << another_repository
9493

95-
updater = build_updater(payload, {:repository_id => 'redmine'})
94+
updater = build_updater(payload, {:repository_id => "redmine"})
9695
updater.expects(:exec).with("git fetch origin", repository.url)
9796
updater.call
9897
end
@@ -102,7 +101,7 @@ def test_updates_all_repositories_if_specific_repository_is_not_found
102101
another_repository.expects(:fetch_changesets).returns(true)
103102
project.repositories << another_repository
104103

105-
updater = build_updater(payload, {:repository_id => 'redmine or something'})
104+
updater = build_updater(payload, :repository_id => "redmine or something")
106105
updater.expects(:exec).with("git fetch origin", repository.url)
107106
updater.call
108107
end
@@ -116,23 +115,23 @@ def test_raises_record_not_found_if_project_identifier_not_found
116115

117116
def test_raises_record_not_found_if_project_identifier_not_given
118117
assert_raises ActiveRecord::RecordNotFound do
119-
updater = build_updater(payload.merge({"repository" => {}}))
118+
updater = build_updater(payload.merge("repository" => {}))
120119
updater.call
121120
end
122121
end
123122

124123
def test_raises_record_not_found_if_project_not_found
125124
assert_raises ActiveRecord::RecordNotFound do
126-
Project.expects(:find_by_identifier).with('foobar').returns(nil)
127-
updater = build_updater(payload, {:project_id => "foobar"})
125+
Project.expects(:find_by_identifier).with("foobar").returns(nil)
126+
updater = build_updater(payload, :project_id => "foobar")
128127
updater.call
129128
end
130129
end
131130

132131
def test_downcases_identifier
133132
# Redmine project identifiers are always downcase
134-
Project.expects(:find_by_identifier).with('redmine').returns(project)
135-
updater = build_updater(payload, {:project_id => 'ReDmInE'})
133+
Project.expects(:find_by_identifier).with("redmine").returns(project)
134+
updater = build_updater(payload, :project_id => "ReDmInE")
136135
updater.call
137136
end
138137

@@ -144,19 +143,19 @@ def test_fetches_changesets_into_the_repository
144143

145144
def test_raises_type_error_if_project_has_no_repository
146145
assert_raises TypeError do
147-
project = mock('project', :to_s => 'My Project', :identifier => 'github')
146+
project = mock("project", :to_s => "My Project", :identifier => "github")
148147
project.expects(:repositories).returns([])
149-
Project.expects(:find_by_identifier).with('github').returns(project)
148+
Project.expects(:find_by_identifier).with("github").returns(project)
150149
updater.call
151150
end
152151
end
153152

154153
def test_raises_type_error_if_repository_is_not_git
155154
assert_raises TypeError do
156-
project = mock('project', :to_s => 'My Project', :identifier => 'github')
155+
project = mock("project", :to_s => "My Project", :identifier => "github")
157156
repository = Repository::Subversion.new
158157
project.expects(:repositories).at_least(1).returns([repository])
159-
Project.expects(:find_by_identifier).with('github').returns(project)
158+
Project.expects(:find_by_identifier).with("github").returns(project)
160159
updater.call
161160
end
162161
end
@@ -165,7 +164,7 @@ def test_logs_if_a_logger_is_given
165164
updater = GithubHook::Updater.new(payload)
166165
updater.stubs(:exec).returns(true)
167166

168-
logger = stub('Logger')
167+
logger = stub("Logger")
169168
logger.expects(:info).at_least_once
170169
updater.logger = logger
171170

0 commit comments

Comments
 (0)