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
17 changes: 15 additions & 2 deletions lib/gitlab_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

class GitlabUpdate
def initialize(repo_path, key_id, refname)
config = GitlabConfig.new

@repo_path = repo_path.strip
@repo_name = repo_path
@repo_name.gsub!(GitlabConfig.new.repos_path.to_s, "")
@repo_name.gsub!(config.repos_path.to_s, "")
@repo_name.gsub!(/\.git$/, "")
@repo_name.gsub!(/^\//, "")

Expand All @@ -15,6 +17,8 @@ def initialize(repo_path, key_id, refname)

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

@redis = config.redis
end

def exec
Expand Down Expand Up @@ -49,7 +53,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']}"
elsif !@redis.empty? && @redis.has_key?("socket")
redis_command = "#{@redis['bin']} -s #{@redis['socket']}"
else
# Default to old method of connecting to redis for users that haven't updated their configuration
redis_command = "env -i redis-cli"
end

command = "#{redis_command} rpush '#{@redis['namespace']}:queue:post_receive' '{\"class\":\"PostReceive\",\"args\":[\"#{@repo_path}\",\"#{@oldrev}\",\"#{@newrev}\",\"#{@refname}\",\"#{@key_id}\"]}' > /dev/null 2>&1"
Copy link
Contributor

Choose a reason for hiding this comment

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

If @redis.empty? and we fallback to old connecting we got wrong behaviour here because @redis['namespace'] is nil

Copy link
Author

Choose a reason for hiding this comment

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

Good point. I'll submit a new pull request later this evening that will switch out the command used based on @redis existing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed by c110d11

system(command)
end
end