BigW Consortium Gitlab

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

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

12 13 14 15
    changes = Base64.decode64(changes) unless changes.include?(' ')
    # Use Sidekiq.logger so arguments can be correlated with execution
    # time and thread ID's.
    Sidekiq.logger.info "changes: #{changes.inspect}" if ENV['SIDEKIQ_LOG_ARGUMENTS']
16
    post_received = Gitlab::GitPostReceive.new(repo_path, identifier, changes)
17

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

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

33 34
  def process_project_changes(post_received)
    post_received.changes.each do |change|
35
      oldrev, newrev, ref = change.strip.split(' ')
36

37
      @user ||= post_received.identify(newrev)
38 39

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

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

52
  private
53

54 55 56
  def log(message)
    Gitlab::GitLogger.error("POST-RECEIVE: #{message}")
  end
57
end