Commit 6bcd8805 authored by Tiago Botelho's avatar Tiago Botelho

Adds email templates for when mirror was hard failed

parent eeeb2d38
......@@ -39,12 +39,12 @@ module Emails
subject: @message.subject)
end
def mirror_hard_failed(project_id, user_id)
@current_user = @user = User.find user_id
@project = Project.find project_id
def mirror_was_hard_failed_email(project_id, user_id)
@user = User.find(user_id)
@project = Project.find(project_id)
mail(to: @user.notification_email,
subject: subject('Mirror hard failed'))
subject: subject('Pull mirroring paused'))
end
end
end
%p
Mirroring from #{@project.import_url} to #{@project.full_path} failed with the following error:
%p
= @project.import_error.try(:strip)
Repository mirroring has been paused due to too many failed attempts, and can be resumed by a project admin.
Mirroring from <%= @project.import_url %> to <%= @project.full_path %> failed with the following error:
<%= @project.import_error.try(:strip) %>
Repository mirroring has been paused due to too many failed attempts, and can be resumed by a project admin.
......@@ -20,11 +20,12 @@ module EE
end
end
after_transition [:scheduled, :started] => [:finished, :failed] do |project, _|
if project.mirror?
::Gitlab::Mirror.decrement_capacity(project.id)
::NotificationService.new.mirror_was_hard_failed(project)
after_transition started: :failed do |project, _|
::NotificationService.new.mirror_was_hard_failed(project) if project.mirror?
end
after_transition [:scheduled, :started] => [:finished, :failed] do |project, _|
::Gitlab::Mirror.decrement_capacity(project.id) if project.mirror?
end
before_transition started: :failed do |project, _|
......
......@@ -20,13 +20,15 @@ module EE
return if note.author == support_bot
return unless issue.subscribed?(support_bot, issue.project)
Notify.service_desk_new_note_email(issue.id, note.id).deliver_later
mailer.service_desk_new_note_email(issue.id, note.id).deliver_later
end
def mirror_was_hard_failed(project)
return unless project.mirror_hard_failed?
recepient = project.mirror_user
mailer.mirror_hard_failed(project.id, recepient.id).deliver_later
mailer.mirror_was_hard_failed_email(project.id, recepient.id).deliver_later
end
end
end
---
title: Repository mirroring notifies when hard failed
merge_request: 4699
author:
type: added
......@@ -119,4 +119,24 @@ describe EE::NotificationService, :mailer do
end
end
end
describe 'mirror hard failed' do
let(:user) { create(:user) }
it 'does not send email when mirror is not hard failed' do
project = create(:project, :mirror)
expect(Notify).not_to receive(:mirror_was_hard_failed_email)
subject.mirror_was_hard_failed(project)
end
it 'sends email to mirror user when mirror hard failed' do
project = create(:project, :mirror, :import_hard_failed, mirror_user: user)
expect(Notify).to receive(:mirror_was_hard_failed_email).with(project.id, user.id).and_call_original
subject.mirror_was_hard_failed(project)
end
end
end
......@@ -1419,6 +1419,22 @@ describe Notify do
end
end
describe 'mirror was hard failed' do
let(:project) { create(:project, :mirror, :import_hard_failed) }
subject { described_class.mirror_was_hard_failed_email(project.id, user.id) }
it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links'
it_behaves_like "a user cannot unsubscribe through footer link"
it 'has the correct subject and body' do
is_expected.to have_subject("#{project.name} | Pull mirroring paused")
is_expected.to have_html_escaped_body_text(project.import_url)
is_expected.to have_html_escaped_body_text(project.full_path)
end
end
describe 'admin notification' do
let(:example_site_path) { root_path }
let(:user) { create(:user) }
......
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