Commit 5e0243b5 authored by Peter Leitzen's avatar Peter Leitzen

Trigger publish only for eligible notes

Trigger publish for notes
* on issues
* which are user-generated (non-system)
* which were changed or destroyed
* had emoji `microphone` on it
parent 1d05a0db
# frozen_string_literal: true
#
require_dependency 'status_page'
# Retrieves Notes specifically for the Status Page
# which are rendered as comments.
#
......@@ -15,11 +17,7 @@
#
module StatusPage
class IncidentCommentsFinder
# Only comments with this emoji are visible.
# This filter will change once we have confidential notes.
# See https://gitlab.com/gitlab-org/gitlab/issues/207468
AWARD_EMOJI = 'microphone'
AWARD_EMOJI = StatusPage::AWARD_EMOJI
MAX_LIMIT = StatusPage::Storage::MAX_COMMENTS
def initialize(issue:)
......
......@@ -50,20 +50,44 @@ module StatusPage
def eligable_issue_id
case triggered_by
when Issue then eligable_issue_id_from_issue
when Note then eligable_issue_id_from_note
else
raise ArgumentError, "unsupported trigger type #{triggered_by.class}"
end
end
# Trigger publish for public (non-confidential) issues
# - which were changed
# - just become confidential to unpublish
def eligable_issue_id_from_issue
changes = triggered_by.previous_changes.keys & PUBLISH_WHEN_ISSUE_CHANGED
issue = triggered_by
changes = issue.previous_changes.keys & PUBLISH_WHEN_ISSUE_CHANGED
return if changes.none?
# Ignore updates for already confidential issues
# Note: Issues becoming confidential _will_ be unpublished.
return if triggered_by.confidential? && changes.exclude?('confidential')
return if issue.confidential? && changes.exclude?('confidential')
issue.id
end
# Trigger publish for notes
# - on issues
# - which are user-generated (non-system)
# - which were changed or destroyed
# - had emoji `microphone` on it
def eligable_issue_id_from_note
note = triggered_by
return unless note.for_issue?
return if note.system?
# We can't know the emoji if the note was destroyed, so
# publish every time to make sure we remove the comment if needed
return note.noteable_id if note.destroyed?
return if note.previous_changes.none?
return if note.award_emoji.named(StatusPage::AWARD_EMOJI).none?
triggered_by.id
note.noteable_id
end
end
end
# frozen_string_literal: true
module StatusPage
# Only comments with this emoji are visible.
# This filter will change once we have confidential notes.
# See https://gitlab.com/gitlab-org/gitlab/issues/207468
AWARD_EMOJI = 'microphone'
# Convenient method to trigger a status page update.
def self.trigger_publish(project, user, triggered_by)
TriggerPublishService.new(project, user, triggered_by).execute
......
......@@ -11,7 +11,6 @@ describe StatusPage::TriggerPublishService do
describe '#execute' do
# Variables used by shared examples
let(:execute) { subject }
let(:issue_id) { triggered_by.id }
let_it_be(:status_page_setting, reload: true) do
create(:status_page_setting, :enabled, project: project)
......@@ -21,6 +20,7 @@ describe StatusPage::TriggerPublishService do
describe 'triggered by issue' do
let_it_be(:triggered_by, reload: true) { create(:issue, project: project) }
let(:issue_id) { triggered_by.id }
using RSpec::Parameterized::TableSyntax
......@@ -74,6 +74,90 @@ describe StatusPage::TriggerPublishService do
end
end
describe 'triggered by note' do
let(:issue_id) { triggered_by.noteable_id }
let(:emoji_name) { StatusPage::AWARD_EMOJI }
before do
create(:award_emoji, user: user, name: emoji_name,
awardable: triggered_by)
end
context 'for issues' do
let_it_be(:triggered_by, refind: true) do
create(:note_on_issue, project: project)
end
context 'without changes' do
include_examples 'no trigger status page publish'
end
context 'when changed' do
include_examples 'trigger status page publish' do
before do
triggered_by.update!(note: 'changed')
end
end
end
context 'when destroyed' do
include_examples 'trigger status page publish' do
before do
triggered_by.destroy
end
end
end
context 'as system note' do
let_it_be(:triggered_by, reload: true) do
create(:note_on_issue, :system, project: project)
end
include_examples 'no trigger status page publish' do
before do
triggered_by.update!(note: 'changed')
end
end
end
context 'without recognized emoji' do
let(:emoji_name) { 'thumbsup' }
context 'when changed' do
include_examples 'no trigger status page publish' do
before do
triggered_by.update!(note: 'changed')
end
end
end
context 'when destroyed' do
include_examples 'trigger status page publish' do
before do
triggered_by.destroy
end
end
end
end
end
context 'for merge requests' do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:triggered_by) do
create(:note_on_merge_request, project: project)
end
context 'when changed' do
include_examples 'no trigger status page publish' do
before do
triggered_by.update!(note: 'changed')
end
end
end
end
end
describe 'triggered by unsupported type' do
context 'for some abitary type' do
let(:triggered_by) { Object.new }
......@@ -89,6 +173,7 @@ describe StatusPage::TriggerPublishService do
context 'with eligable triggered_by' do
let_it_be(:triggered_by) { create(:issue, project: project) }
let(:issue_id) { triggered_by.id }
context 'when eligable' do
include_examples 'trigger status page publish'
......
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