Commit 31839909 authored by Doug Stull's avatar Doug Stull Committed by Thong Kuah

Make ci notification mail have link to group

- clearer for user when email received on what
  is being alerted upon.
parent 591ccc71
...@@ -5,23 +5,23 @@ class CiMinutesUsageMailer < ApplicationMailer ...@@ -5,23 +5,23 @@ class CiMinutesUsageMailer < ApplicationMailer
layout 'mailer' layout 'mailer'
def notify(namespace_name, recipients) def notify(namespace, recipients)
@namespace_name = namespace_name @namespace = namespace
mail( mail(
bcc: recipients, bcc: recipients,
subject: "Action required: There are no remaining Pipeline minutes for #{namespace_name}" subject: "Action required: There are no remaining Pipeline minutes for #{@namespace.name}"
) )
end end
def notify_limit(namespace_name, recipients, percentage_of_available_mins) def notify_limit(namespace, recipients, percentage_of_available_mins)
@namespace_name = namespace_name @namespace = namespace
@percentage_of_available_mins = percentage_of_available_mins @percentage_of_available_mins = percentage_of_available_mins
mail( mail(
bcc: recipients, bcc: recipients,
subject: "Action required: Less than #{percentage_of_available_mins}% " \ subject: "Action required: Less than #{percentage_of_available_mins}% " \
"of Pipeline minutes remain for #{namespace_name}" "of Pipeline minutes remain for #{@namespace.name}"
) )
end end
end end
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
class CiMinutesUsageMailerPreview < ActionMailer::Preview class CiMinutesUsageMailerPreview < ActionMailer::Preview
def out_of_minutes def out_of_minutes
::CiMinutesUsageMailer.notify('GROUP_NAME', %w(bob@example.com)) ::CiMinutesUsageMailer.notify(Group.last, %w(bob@example.com))
end end
def limit_warning def limit_warning
::CiMinutesUsageMailer.notify_limit('GROUP_NAME', %w(bob@example.com), 30) ::CiMinutesUsageMailer.notify_limit(Group.last, %w(bob@example.com), 30)
end end
end end
...@@ -22,7 +22,7 @@ module Ci ...@@ -22,7 +22,7 @@ module Ci
namespace.update_columns(last_ci_minutes_notification_at: Time.current) namespace.update_columns(last_ci_minutes_notification_at: Time.current)
CiMinutesUsageMailer.notify(namespace.name, recipients).deliver_later CiMinutesUsageMailer.notify(namespace, recipients).deliver_later
end end
def notify_on_partial_usage def notify_on_partial_usage
...@@ -32,7 +32,7 @@ module Ci ...@@ -32,7 +32,7 @@ module Ci
namespace.update_columns(last_ci_minutes_usage_notification_level: current_alert_level) namespace.update_columns(last_ci_minutes_usage_notification_level: current_alert_level)
CiMinutesUsageMailer.notify_limit(namespace.name, recipients, current_alert_level).deliver_later CiMinutesUsageMailer.notify_limit(namespace, recipients, current_alert_level).deliver_later
end end
def namespace def namespace
......
%p %p
= _('%{name} has run out of Shared Runner Pipeline minutes so no new jobs or pipelines in its projects will run.') % { name: @namespace_name } - name_link = link_to @namespace.name, @namespace
= html_escape(_('%{name_with_link} has run out of Shared Runner Pipeline minutes so no new jobs or pipelines in its projects will run.')) % { name_with_link: name_link.html_safe }
%p %p
= _('We recommend that you buy more Pipeline minutes to resume normal service.') = _('We recommend that you buy more Pipeline minutes to resume normal service.')
%p %p
......
<%= _('%{name} has run out of Shared Runner Pipeline minutes so no new jobs or pipelines in its projects will run.') % { name: @namespace_name } %> <%= _('%{name}(%{url}) has run out of Shared Runner Pipeline minutes so no new jobs or pipelines in its projects will run.') % { name: @namespace.name, url: group_url(@namespace) }%>
<%= _('We recommend that you buy more Pipeline minutes to resume normal service.') %> <%= _('We recommend that you buy more Pipeline minutes to resume normal service.') %>
......
%p %p
= _('%{name} has %{percent} or less Shared Runner Pipeline minutes remaining. Once it runs out, no new jobs or pipelines in its projects will run.') % { name: @namespace_name, percent: "#{@percentage_of_available_mins}%" } - name_link = link_to @namespace.name, @namespace
= html_escape(_('%{name_with_link} has %{percent} or less Shared Runner Pipeline minutes remaining. Once it runs out, no new jobs or pipelines in its projects will run.')) % { name_with_link: name_link.html_safe, percent: "#{@percentage_of_available_mins}%" }
%p %p
= _('We recommend that you buy more Pipeline minutes to avoid any interruption of service.') = _('We recommend that you buy more Pipeline minutes to avoid any interruption of service.')
%p %p
......
<%= _('%{name} has %{percent} or less Shared Runner Pipeline minutes remaining. Once it runs out, no new jobs or pipelines in its projects will run.') % { name: @namespace_name, percent: "#{@percentage_of_available_mins}%" } %> <%= _('%{name}(%{url}) has %{percent} or less Shared Runner Pipeline minutes remaining. Once it runs out, no new jobs or pipelines in its projects will run.') % { name: @namespace.name, url: group_url(@namespace), percent: "#{@percentage_of_available_mins}%" } %>
<%= _('We recommend that you buy more Pipeline minutes to avoid any interruption of service.') %> <%= _('We recommend that you buy more Pipeline minutes to avoid any interruption of service.') %>
......
---
title: Make group/namespace name in email a link to group overview page
merge_request: 32461
author:
type: added
...@@ -5,24 +5,25 @@ require 'spec_helper' ...@@ -5,24 +5,25 @@ require 'spec_helper'
describe CiMinutesUsageMailer do describe CiMinutesUsageMailer do
include EmailSpec::Matchers include EmailSpec::Matchers
let(:namespace_name) { 'GROUP_NAME' } let(:namespace) { create(:group) }
let(:recipients) { %w(bob@example.com john@example.com) } let(:recipients) { %w(bob@example.com john@example.com) }
shared_examples 'mail format' do shared_examples 'mail format' do
it { is_expected.to have_subject subject_text } it { is_expected.to have_subject subject_text }
it { is_expected.to bcc_to recipients } it { is_expected.to bcc_to recipients }
it { is_expected.to have_body_text "#{group_path namespace}" }
it { is_expected.to have_body_text body_text } it { is_expected.to have_body_text body_text }
end end
describe '#notify' do describe '#notify' do
it_behaves_like 'mail format' do it_behaves_like 'mail format' do
let(:subject_text) do let(:subject_text) do
"Action required: There are no remaining Pipeline minutes for #{namespace_name}" "Action required: There are no remaining Pipeline minutes for #{namespace.name}"
end end
let(:body_text) { "#{namespace_name} has run out of Shared Runner Pipeline minutes" } let(:body_text) { "has run out of Shared Runner Pipeline minutes" }
subject { described_class.notify(namespace_name, recipients) } subject { described_class.notify(namespace, recipients) }
end end
end end
...@@ -30,12 +31,12 @@ describe CiMinutesUsageMailer do ...@@ -30,12 +31,12 @@ describe CiMinutesUsageMailer do
it_behaves_like 'mail format' do it_behaves_like 'mail format' do
let(:percent) { 30 } let(:percent) { 30 }
let(:subject_text) do let(:subject_text) do
"Action required: Less than #{percent}% of Pipeline minutes remain for #{namespace_name}" "Action required: Less than #{percent}% of Pipeline minutes remain for #{namespace.name}"
end end
let(:body_text) { "#{namespace_name} has #{percent}% or less Shared Runner Pipeline minutes" } let(:body_text) { "has #{percent}% or less Shared Runner Pipeline minutes" }
subject { described_class.notify_limit(namespace_name, recipients, percent) } subject { described_class.notify_limit(namespace, recipients, percent) }
end end
end end
end end
...@@ -16,7 +16,7 @@ describe Ci::Minutes::EmailNotificationService do ...@@ -16,7 +16,7 @@ describe Ci::Minutes::EmailNotificationService do
shared_examples 'namespace with all CI minutes used' do shared_examples 'namespace with all CI minutes used' do
context 'when usage is over the quote' do context 'when usage is over the quote' do
it 'sends the email to the owner' do it 'sends the email to the owner' do
expect(CiMinutesUsageMailer).to receive(:notify).once.with(namespace.name, [user.email]).and_return(spy) expect(CiMinutesUsageMailer).to receive(:notify).once.with(namespace, [user.email]).and_return(spy)
subject subject
end end
...@@ -117,7 +117,7 @@ describe Ci::Minutes::EmailNotificationService do ...@@ -117,7 +117,7 @@ describe Ci::Minutes::EmailNotificationService do
it 'sends the email to all the owners' do it 'sends the email to all the owners' do
expect(CiMinutesUsageMailer).to receive(:notify) expect(CiMinutesUsageMailer).to receive(:notify)
.with(namespace.name, match_array([user_2.email, user.email])) .with(namespace, match_array([user_2.email, user.email]))
.and_return(spy) .and_return(spy)
subject subject
...@@ -161,7 +161,7 @@ describe Ci::Minutes::EmailNotificationService do ...@@ -161,7 +161,7 @@ describe Ci::Minutes::EmailNotificationService do
it 'notifies the the owners about it' do it 'notifies the the owners about it' do
expect(CiMinutesUsageMailer).to receive(:notify_limit) expect(CiMinutesUsageMailer).to receive(:notify_limit)
.with(namespace.name, array_including(user_2.email, user.email), expected_level) .with(namespace, array_including(user_2.email, user.email), expected_level)
.and_call_original .and_call_original
notify_owners notify_owners
......
...@@ -38,7 +38,7 @@ describe BuildFinishedWorker do ...@@ -38,7 +38,7 @@ describe BuildFinishedWorker do
namespace.update_attribute(:shared_runners_minutes_limit, 2000) namespace.update_attribute(:shared_runners_minutes_limit, 2000)
namespace_stats.update_attribute(:shared_runners_seconds, 2100 * 60) namespace_stats.update_attribute(:shared_runners_seconds, 2100 * 60)
expect(CiMinutesUsageMailer).to receive(:notify).once.with(namespace.name, [namespace.owner.email]).and_return(spy) expect(CiMinutesUsageMailer).to receive(:notify).once.with(namespace, [namespace.owner.email]).and_return(spy)
subject subject
end end
......
...@@ -394,6 +394,12 @@ msgstr "" ...@@ -394,6 +394,12 @@ msgstr ""
msgid "%{mrText}, this issue will be closed automatically." msgid "%{mrText}, this issue will be closed automatically."
msgstr "" msgstr ""
msgid "%{name_with_link} has %{percent} or less Shared Runner Pipeline minutes remaining. Once it runs out, no new jobs or pipelines in its projects will run."
msgstr ""
msgid "%{name_with_link} has run out of Shared Runner Pipeline minutes so no new jobs or pipelines in its projects will run."
msgstr ""
msgid "%{namespace_name} is now read-only. You cannot: %{base_message}" msgid "%{namespace_name} is now read-only. You cannot: %{base_message}"
msgstr "" msgstr ""
...@@ -403,16 +409,16 @@ msgstr "" ...@@ -403,16 +409,16 @@ msgstr ""
msgid "%{name} found %{resultsString}" msgid "%{name} found %{resultsString}"
msgstr "" msgstr ""
msgid "%{name} has %{percent} or less Shared Runner Pipeline minutes remaining. Once it runs out, no new jobs or pipelines in its projects will run." msgid "%{name} is scheduled for %{action}"
msgstr "" msgstr ""
msgid "%{name} has run out of Shared Runner Pipeline minutes so no new jobs or pipelines in its projects will run." msgid "%{name}'s avatar"
msgstr "" msgstr ""
msgid "%{name} is scheduled for %{action}" msgid "%{name}(%{url}) has %{percent} or less Shared Runner Pipeline minutes remaining. Once it runs out, no new jobs or pipelines in its projects will run."
msgstr "" msgstr ""
msgid "%{name}'s avatar" msgid "%{name}(%{url}) has run out of Shared Runner Pipeline minutes so no new jobs or pipelines in its projects will run."
msgstr "" msgstr ""
msgid "%{no_of_days} day" msgid "%{no_of_days} day"
......
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