11module 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
145144end
0 commit comments