post_receive.rb 1.2 KB
Newer Older
1
class PostReceive
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
2
  include Sidekiq::Worker
3
  include Gitlab::Identifier
4

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
5 6 7
  sidekiq_options queue: :post_receive

  def perform(repo_path, oldrev, newrev, ref, identifier)
8

9 10
    if repo_path.start_with?(Gitlab.config.gitlab_shell.repos_path.to_s)
      repo_path.gsub!(Gitlab.config.gitlab_shell.repos_path.to_s, "")
11
    else
12
      log("Check gitlab.yml config for correct gitlab_shell.repos_path variable. \"#{Gitlab.config.gitlab_shell.repos_path}\" does not match \"#{repo_path}\"")
13 14
    end

15 16
    repo_path.gsub!(/.git$/, "")
    repo_path.gsub!(/^\//, "")
17 18

    project = Project.find_with_namespace(repo_path)
19 20

    if project.nil?
21
      log("Triggered hook for non-existing project with full path \"#{repo_path} \"")
22 23
      return false
    end
24

25
    user = identify(identifier, project, newrev)
26

27
    unless user
28
      log("Triggered hook for non-existing user \"#{identifier} \"")
29 30
      return false
    end
31

32 33 34 35 36
    if tag?(ref)
      GitTagPushService.new.execute(project, user, ref)
    else
      GitPushService.new.execute(project, user, oldrev, newrev, ref)
    end
37
  end
38 39 40 41

  def log(message)
    Gitlab::GitLogger.error("POST-RECEIVE: #{message}")
  end
42 43 44 45 46 47

  private

  def tag?(ref)
    !!(/refs\/tags\/(.*)/.match(ref))
  end
48
end