BigW Consortium Gitlab

post_receive.rb 1.62 KB
Newer Older
1
class PostReceive
Dmitriy Zaporozhets committed
2
  include Sidekiq::Worker
3

Dmitriy Zaporozhets committed
4 5
  sidekiq_options queue: :post_receive

6
  def perform(repo_path, identifier, changes)
7 8
    if path = Gitlab.config.repositories.storages.find { |p| repo_path.start_with?(p[1].to_s) }
      repo_path.gsub!(path[1].to_s, "")
9
    else
10
      log("Check gitlab.yml config for correct repositories.storages values. No repository storage path matches \"#{repo_path}\"")
11 12
    end

13
    post_received = Gitlab::GitPostReceive.new(repo_path, identifier, changes)
14

15
    if post_received.project.nil?
16
      log("Triggered hook for non-existing project with full path \"#{repo_path} \"")
17 18
      return false
    end
19

20 21 22 23 24 25 26 27 28
    if post_received.wiki?
      # Nothing defined here yet.
    elsif post_received.regular_project?
      process_project_changes(post_received)
    else
      log("Triggered hook for unidentifiable repository type with full path \"#{repo_path} \"")
      false
    end
  end
29

30 31
  def process_project_changes(post_received)
    post_received.changes.each do |change|
32
      oldrev, newrev, ref = change.strip.split(' ')
33

34
      @user ||= post_received.identify(newrev)
35 36

      unless @user
37
        log("Triggered hook for non-existing user \"#{post_received.identifier} \"")
38 39 40
        return false
      end

41
      if Gitlab::Git.tag_ref?(ref)
42
        GitTagPushService.new(post_received.project, @user, oldrev: oldrev, newrev: newrev, ref: ref).execute
43
      elsif Gitlab::Git.branch_ref?(ref)
44
        GitPushService.new(post_received.project, @user, oldrev: oldrev, newrev: newrev, ref: ref).execute
45
      end
46
    end
47
  end
48

49
  private
50

51 52 53
  def log(message)
    Gitlab::GitLogger.error("POST-RECEIVE: #{message}")
  end
54
end