BigW Consortium Gitlab

post_receive.rb 682 Bytes
Newer Older
1
class PostReceive
2 3
  @queue = :post_receive

4
  def self.perform(reponame, oldrev, newrev, ref, identifier)
5 6 7
    project = Project.find_by_path(reponame)
    return false if project.nil?

8
    # Ignore push from non-gitlab users
9
    user = if identifier.eql? Gitlab.config.gitolite_admin_key 
10 11
      email = project.commit(newrev).author.email rescue nil
      User.find_by_email(email) if email
12 13
    elsif /^[A-Z0-9._%a-z\-]+@(?:[A-Z0-9a-z\-]+\.)+[A-Za-z]{2,4}$/.match(identifier)
      User.find_by_email(identifier)
14
    else
15
      Key.find_by_identifier(identifier).try(:user)
16
    end
17
    return false unless user
18

19
    project.trigger_post_receive(oldrev, newrev, ref, user)
20 21
  end
end