Skip to content
9 changes: 9 additions & 0 deletions config.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,12 @@ repos_path: "/home/git/repositories"

# File used as authorized_keys for gitlab user
auth_file: "/home/git/.ssh/authorized_keys"

# Redis settings used for pushing commit notices to gitlab
redis:
bin: /usr/bin/redis-cli
host: 127.0.0.1
port: 6379
# socket: /tmp/redis.socket # Only define this if you want to use sockets
namespace: resque:gitlab

4 changes: 4 additions & 0 deletions lib/gitlab_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ def gitlab_url
def http_settings
@config['http_settings'] ||= {}
end

def redis
@config['redis'] ||= {}
end
end
13 changes: 12 additions & 1 deletion lib/gitlab_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def initialize(repo_path, key_id, refname)

@oldrev = ARGV[1]
@newrev = ARGV[2]

@redis = GitlabConfig.new.redis
end

def exec
Expand Down Expand Up @@ -49,7 +51,16 @@ def ssh?
end

def update_redis
command = "env -i redis-cli rpush 'resque:gitlab:queue:post_receive' '{\"class\":\"PostReceive\",\"args\":[\"#{@repo_path}\",\"#{@oldrev}\",\"#{@newrev}\",\"#{@refname}\",\"#{@key_id}\"]}' > /dev/null 2>&1"
if !@redis.empty? && !@redis.has_key?("socket")
redis_command = "#{@redis['bin']} -h #{@redis['host']} -p #{@redis['port']} rpush '#{@redis['namespace']}:queue:post_receive'"
elsif !@redis.empty? && @redis.has_key?("socket")
redis_command = "#{@redis['bin']} -s #{@redis['socket']} rpush '#{@redis['namespace']}:queue:post_receive'"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a small bug in this version: "rpush '#{@redis['namespace']}:queue:post_receive'" should go into command instead of redis_command. Besides the code duplication, this also causes default configuration (redis.empty? == true) not to take in that command.

else
# Default to old method of connecting to redis for users that haven't updated their configuration
redis_commend = "env -i redis-cli"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misspelling: s/redis_commend/redis_command

end

command = "#{redis_command} '{\"class\":\"PostReceive\",\"args\":[\"#{@repo_path}\",\"#{@oldrev}\",\"#{@newrev}\",\"#{@refname}\",\"#{@key_id}\"]}' > /dev/null 2>&1"
system(command)
end
end