Module: Gitlab::Identifier

Included in:
GitPostReceive
Defined in:
lib/gitlab/identifier.rb

Instance Method Summary collapse

Instance Method Details

#identify(identifier, project, newrev) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/gitlab/identifier.rb', line 5

def identify(identifier, project, newrev)
  if identifier.blank?
    # Local push from gitlab
    email = project.commit(newrev).author_email rescue nil
    User.find_by(email: email) if email

  elsif identifier =~ /\Auser-\d+\Z/
    # git push over http
    user_id = identifier.gsub("user-", "")
    User.find_by(id: user_id)

  elsif identifier =~ /\Akey-\d+\Z/
    # git push over ssh
    key_id = identifier.gsub("key-", "")
    Key.find_by(id: key_id).try(:user)
  end
end