2014-09-02 18:07:02 +05:30
|
|
|
class PostReceive
|
|
|
|
include Sidekiq::Worker
|
2016-11-03 12:29:30 +05:30
|
|
|
include DedicatedSidekiqQueue
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def perform(repo_path, identifier, changes)
|
2016-08-24 12:49:21 +05:30
|
|
|
if path = Gitlab.config.repositories.storages.find { |p| repo_path.start_with?(p[1].to_s) }
|
|
|
|
repo_path.gsub!(path[1].to_s, "")
|
2014-09-02 18:07:02 +05:30
|
|
|
else
|
2016-08-24 12:49:21 +05:30
|
|
|
log("Check gitlab.yml config for correct repositories.storages values. No repository storage path matches \"#{repo_path}\"")
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
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']
|
2016-06-02 11:05:42 +05:30
|
|
|
post_received = Gitlab::GitPostReceive.new(repo_path, identifier, changes)
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
if post_received.project.nil?
|
2014-09-02 18:07:02 +05:30
|
|
|
log("Triggered hook for non-existing project with full path \"#{repo_path} \"")
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
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
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
def process_project_changes(post_received)
|
|
|
|
post_received.changes.each do |change|
|
2015-04-26 12:48:37 +05:30
|
|
|
oldrev, newrev, ref = change.strip.split(' ')
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
@user ||= post_received.identify(newrev)
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
unless @user
|
2016-06-02 11:05:42 +05:30
|
|
|
log("Triggered hook for non-existing user \"#{post_received.identifier} \"")
|
2015-04-26 12:48:37 +05:30
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
if Gitlab::Git.tag_ref?(ref)
|
2016-06-02 11:05:42 +05:30
|
|
|
GitTagPushService.new(post_received.project, @user, oldrev: oldrev, newrev: newrev, ref: ref).execute
|
|
|
|
elsif Gitlab::Git.branch_ref?(ref)
|
|
|
|
GitPushService.new(post_received.project, @user, oldrev: oldrev, newrev: newrev, ref: ref).execute
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
private
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def log(message)
|
|
|
|
Gitlab::GitLogger.error("POST-RECEIVE: #{message}")
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|