Commit 6c6e4ca4 authored by Stan Hu's avatar Stan Hu

Fix remote mirrors not updating after tag push

Remote mirrors were only being updated after pushes to branches, not
tags. This change consolidates the functionality into
Git::BaseHooksService so that both tags and branches will now update
remote mirrors.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/51240
parent 04794fb4
...@@ -17,6 +17,8 @@ module Git ...@@ -17,6 +17,8 @@ module Git
# Not a hook, but it needs access to the list of changed commits # Not a hook, but it needs access to the list of changed commits
enqueue_invalidate_cache enqueue_invalidate_cache
update_remote_mirrors
push_data push_data
end end
...@@ -92,5 +94,12 @@ module Git ...@@ -92,5 +94,12 @@ module Git
def pipeline_options def pipeline_options
{} {}
end end
def update_remote_mirrors
return unless project.has_remote_mirror?
project.mark_stuck_remote_mirrors_as_failed!
project.update_remote_mirrors
end
end end
end end
...@@ -27,7 +27,6 @@ module Git ...@@ -27,7 +27,6 @@ module Git
execute_related_hooks execute_related_hooks
perform_housekeeping perform_housekeeping
update_remote_mirrors
stop_environments stop_environments
true true
......
---
title: Fix remote mirrors not updating after tag push
merge_request:
author:
type: fixed
# frozen_string_literal: true
require 'spec_helper'
describe Git::BaseHooksService do
include RepoHelpers
include GitHelpers
let(:user) { create(:user) }
let(:project) { create(:project, :repository) }
let(:service) { described_class.new(project, user, oldrev: oldrev, newrev: newrev, ref: ref) }
let(:oldrev) { Gitlab::Git::BLANK_SHA }
let(:newrev) { "8a2a6eb295bb170b34c24c76c49ed0e9b2eaf34b" } # gitlab-test: git rev-parse refs/tags/v1.1.0
let(:ref) { 'refs/tags/v1.1.0' }
describe 'with remote mirrors' do
class TestService < described_class
def commits
[]
end
end
let(:project) { create(:project, :repository, :remote_mirror) }
subject { TestService.new(project, user, oldrev: oldrev, newrev: newrev, ref: ref) }
before do
expect(subject).to receive(:execute_project_hooks)
end
context 'when remote mirror feature is enabled' do
it 'fails stuck remote mirrors' do
allow(project).to receive(:update_remote_mirrors).and_return(project.remote_mirrors)
expect(project).to receive(:mark_stuck_remote_mirrors_as_failed!)
subject.execute
end
it 'updates remote mirrors' do
expect(project).to receive(:update_remote_mirrors)
subject.execute
end
end
context 'when remote mirror feature is disabled' do
before do
stub_application_setting(mirror_available: false)
end
context 'with remote mirrors global setting overridden' do
before do
project.remote_mirror_available_overridden = true
end
it 'fails stuck remote mirrors' do
allow(project).to receive(:update_remote_mirrors).and_return(project.remote_mirrors)
expect(project).to receive(:mark_stuck_remote_mirrors_as_failed!)
subject.execute
end
it 'updates remote mirrors' do
expect(project).to receive(:update_remote_mirrors)
subject.execute
end
end
context 'without remote mirrors global setting overridden' do
before do
project.remote_mirror_available_overridden = false
end
it 'does not fails stuck remote mirrors' do
expect(project).not_to receive(:mark_stuck_remote_mirrors_as_failed!)
subject.execute
end
it 'does not updates remote mirrors' do
expect(project).not_to receive(:update_remote_mirrors)
subject.execute
end
end
end
end
end
...@@ -18,6 +18,12 @@ describe Git::BranchHooksService do ...@@ -18,6 +18,12 @@ describe Git::BranchHooksService do
described_class.new(project, user, oldrev: oldrev, newrev: newrev, ref: ref) described_class.new(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
end end
it 'update remote mirrors' do
expect(service).to receive(:update_remote_mirrors).and_call_original
service.execute
end
describe "Git Push Data" do describe "Git Push Data" do
subject(:push_data) { service.execute } subject(:push_data) { service.execute }
......
...@@ -17,72 +17,6 @@ describe Git::BranchPushService, services: true do ...@@ -17,72 +17,6 @@ describe Git::BranchPushService, services: true do
project.add_maintainer(user) project.add_maintainer(user)
end end
describe 'with remote mirrors' do
let(:project) { create(:project, :repository, :remote_mirror) }
subject do
described_class.new(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
end
context 'when remote mirror feature is enabled' do
it 'fails stuck remote mirrors' do
allow(project).to receive(:update_remote_mirrors).and_return(project.remote_mirrors)
expect(project).to receive(:mark_stuck_remote_mirrors_as_failed!)
subject.execute
end
it 'updates remote mirrors' do
expect(project).to receive(:update_remote_mirrors)
subject.execute
end
end
context 'when remote mirror feature is disabled' do
before do
stub_application_setting(mirror_available: false)
end
context 'with remote mirrors global setting overridden' do
before do
project.remote_mirror_available_overridden = true
end
it 'fails stuck remote mirrors' do
allow(project).to receive(:update_remote_mirrors).and_return(project.remote_mirrors)
expect(project).to receive(:mark_stuck_remote_mirrors_as_failed!)
subject.execute
end
it 'updates remote mirrors' do
expect(project).to receive(:update_remote_mirrors)
subject.execute
end
end
context 'without remote mirrors global setting overridden' do
before do
project.remote_mirror_available_overridden = false
end
it 'does not fails stuck remote mirrors' do
expect(project).not_to receive(:mark_stuck_remote_mirrors_as_failed!)
subject.execute
end
it 'does not updates remote mirrors' do
expect(project).not_to receive(:update_remote_mirrors)
subject.execute
end
end
end
end
describe 'Push branches' do describe 'Push branches' do
subject do subject do
execute_service(project, user, oldrev, newrev, ref) execute_service(project, user, oldrev, newrev, ref)
......
...@@ -18,6 +18,12 @@ describe Git::TagHooksService, :service do ...@@ -18,6 +18,12 @@ describe Git::TagHooksService, :service do
described_class.new(project, user, oldrev: oldrev, newrev: newrev, ref: ref) described_class.new(project, user, oldrev: oldrev, newrev: newrev, ref: ref)
end end
it 'update remote mirrors' do
expect(service).to receive(:update_remote_mirrors).and_call_original
service.execute
end
describe 'System hooks' do describe 'System hooks' do
it 'Executes system hooks' do it 'Executes system hooks' do
push_data = service.execute push_data = service.execute
......
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