Update: encoding to UTF8 from database. Be less restrictive in checking (reactivate code from first initial version)
------------------------------- file pre-receive ------------------------------- #!/opt/gitlab/embedded/bin/ruby # @backup # Fix the PATH so that gitlab-shell can find git-upload-pack and friends. ENV['PATH'] = '/opt/gitlab/bin:/opt/gitlab/embedded/bin:' + ENV['PATH'] #!/usr/bin/env ruby # This file was placed here by GitLab. It makes sure that your pushed commits # will be processed properly. # You can add your own hooks to this file, but be careful when updating gitlab-shell! refs = ARGF.read key_id = ENV['GL_ID'] repo_path = Dir.pwd # get sha references temp = refs.split(" ") shaold = temp[0] shanew = temp[1] require '/opt/gitlab/embedded/service/gitlab-shell/lib/gitlab_access' # read the remote user which is pushing # distinguish between key-id (ssh access) and user-id (http access) user = {} if key_id =~ /\Akey\-\d+\Z/ # discover the user though its ssh key using GitLab shell function require '/opt/gitlab/embedded/service/gitlab-shell/lib/gitlab_net' api = GitlabNet.new user = api.discover(key_id) elsif key_id =~ /\Auser\-\d+\Z/ # read user data directly from database table dbid = key_id.gsub("user-", "") temp = `psql -h localhost -At -d gitlab -c "select name from users where id=#{dbid};"` temp = temp.encode('UTF-8', :invalid => :replace).strip user["name"] = temp temp = `psql -h localhost -At -d gitlab -c "select username from users where id=#{dbid};"` temp = temp.encode('UTF-8', :invalid => :replace).strip user["username"] = temp else puts "Unknown GL_ID response: " + key_id exit 1 end ## cn = committers name from SHA reference cn = `git log #{shanew} --pretty=format:%cn --max-count=1` ## glu = GitLab usernames glu = `psql -h localhost -At -d gitlab -c "select username from users;"` glu = glu.encode('UTF-8', :invalid => :replace).strip glu = glu.split("\n") ## gln = GitLab names gln = `psql -h localhost -At -d gitlab -c "select name from users;"` gln = gln.encode('UTF-8', :invalid => :replace).strip gln = gln.split("\n") puts "Remote account is " + user['name'] + " (" + user['username'] + ")" ## reject if pushers name does not match the last comitters name ## (maybe too restrictive) #if (user["username"] != cn) && (user["name"] != cn) # puts "Rejected push because the committers name '#{cn}' does not match the remote account" # puts "Use 'git config user.name <your-account-name>' to set things right" # exit 1 #end ## loop all GitLab usernames and compare with committers name found = 0 for username in glu if username == cn found = 1 end end ## loop all GitLab names ... for name in gln if name == cn found = 1 end end ## reject push if found == 0 puts "Rejected push because of unknown committer '#{cn}'" exit 1 end if GitlabAccess.new(repo_path, key_id, refs).exec exit 0 else exit 1 end -- You received this message because you are subscribed to the Google Groups "GitLab" group. To unsubscribe from this group and stop receiving emails from it, send an email to gitlabhq+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/gitlabhq/586e32d9-7cc8-47b6-84e5-8a82e07b78eb%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.