BigW Consortium Gitlab

post_receive.rb 1.68 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
    repo_relative_path = Gitlab::RepoPath.strip_storage_path(repo_path)
7

8 9 10 11
    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']
12
    post_received = Gitlab::GitPostReceive.new(repo_relative_path, identifier, changes)
13

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

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

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

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

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

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

48
  private
49

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