Commit bed04fae authored by Thong Kuah's avatar Thong Kuah

Merge branch...

Merge branch '217605-make-group-namespace-name-in-email-a-link-to-group-overview-page' into 'master'

Make group/namespace name in email a link to group

Closes #217605

See merge request gitlab-org/gitlab!32461
parents deb6db5e 31839909
......@@ -5,23 +5,23 @@ class CiMinutesUsageMailer < ApplicationMailer
layout 'mailer'
def notify(namespace_name, recipients)
@namespace_name = namespace_name
def notify(namespace, recipients)
@namespace = namespace
mail(
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
def notify_limit(namespace_name, recipients, percentage_of_available_mins)
@namespace_name = namespace_name
def notify_limit(namespace, recipients, percentage_of_available_mins)
@namespace = namespace
@percentage_of_available_mins = percentage_of_available_mins
mail(
bcc: recipients,
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
......@@ -2,10 +2,10 @@
class CiMinutesUsageMailerPreview < ActionMailer::Preview
def out_of_minutes
::CiMinutesUsageMailer.notify('GROUP_NAME', %w(bob@example.com))
::CiMinutesUsageMailer.notify(Group.last, %w(bob@example.com))
end
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
......@@ -22,7 +22,7 @@ module Ci
namespace.update_columns(last_ci_minutes_notification_at: Time.current)
CiMinutesUsageMailer.notify(namespace.name, recipients).deliver_later
CiMinutesUsageMailer.notify(namespace, recipients).deliver_later
end
def notify_on_partial_usage
......@@ -32,7 +32,7 @@ module Ci
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
def namespace
......
%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
= _('We recommend that you buy more Pipeline minutes to resume normal service.')
%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.') %>
......
%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
= _('We recommend that you buy more Pipeline minutes to avoid any interruption of service.')
%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.') %>
......
---
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'
describe CiMinutesUsageMailer do
include EmailSpec::Matchers
let(:namespace_name) { 'GROUP_NAME' }
let(:namespace) { create(:group) }
let(:recipients) { %w(bob@example.com john@example.com) }
shared_examples 'mail format' do
it { is_expected.to have_subject subject_text }
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 }
end
describe '#notify' do
it_behaves_like 'mail format' 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
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
......@@ -30,12 +31,12 @@ describe CiMinutesUsageMailer do
it_behaves_like 'mail format' do
let(:percent) { 30 }
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
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
......@@ -16,7 +16,7 @@ describe Ci::Minutes::EmailNotificationService do
shared_examples 'namespace with all CI minutes used' do
context 'when usage is over the quote' 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
end
......@@ -117,7 +117,7 @@ describe Ci::Minutes::EmailNotificationService do
it 'sends the email to all the owners' do
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)
subject
......@@ -161,7 +161,7 @@ describe Ci::Minutes::EmailNotificationService do
it 'notifies the the owners about it' do
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
notify_owners
......
......@@ -38,7 +38,7 @@ describe BuildFinishedWorker do
namespace.update_attribute(:shared_runners_minutes_limit, 2000)
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
end
......
......@@ -394,6 +394,12 @@ msgstr ""
msgid "%{mrText}, this issue will be closed automatically."
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}"
msgstr ""
......@@ -403,16 +409,16 @@ msgstr ""
msgid "%{name} found %{resultsString}"
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 ""
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 ""
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 ""
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 ""
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