Commit ff0508b5 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Simulate cache specific concern for git_push_service in Geo

parent e02f4eef
......@@ -5,10 +5,12 @@ module Geo
def initialize(params)
@id = params[:project_id]
@clone_url = params[:project][:git_ssh_url]
@push_data = { 'type': params[:object_kind], 'before': params[:before],
'after': params[:newref], 'ref': params[:ref] }
end
def execute
GeoRepositoryUpdateWorker.perform_async(@id, @clone_url)
GeoRepositoryUpdateWorker.perform_async(@id, @clone_url, @push_data)
end
end
end
......@@ -5,11 +5,12 @@ class GeoRepositoryUpdateWorker
attr_accessor :project
def perform(project_id, clone_url)
def perform(project_id, clone_url, push_data)
@project = Project.find(project_id)
@push_data = push_data
fetch_repository(clone_url)
ProjectCacheWorker.perform_async(@project.id)
process_hooks
end
private
......@@ -17,8 +18,33 @@ class GeoRepositoryUpdateWorker
def fetch_repository(remote_url)
@project.create_repository unless @project.repository_exists?
@project.repository.after_create if @project.empty_repo?
@project.repository.fetch_geo_mirror(remote_url)
@project.repository.after_import
end
def process_hooks
if @push_data['type'] == 'push'
branch = Gitlab::Git.branch_ref?(@push_data['ref'])
process_push(branch, @push_data['after'])
end
end
def process_push(branch, revision)
@project.repository.after_push_commit(branch, revision)
if push_remove_branch?
@project.repository.after_remove_branch
elsif push_to_new_branch?
@project.repository.after_create_branch
end
ProjectCacheWorker.perform_async(@project.id)
end
def push_remove_branch?
Gitlab::Git.branch_ref?(@push_data['ref']) && Gitlab::Git.blank_ref?(@push_data['after'])
end
def push_to_new_branch?
Gitlab::Git.branch_ref?(@push_data['ref']) && Gitlab::Git.blank_ref?(@push_data['before'])
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment