Commit 9e862e37 authored by Adam Hegyi's avatar Adam Hegyi

Expose VSA stage event descriptions

This change exposes stage start and end event description via the value
streams private API.
parent bc7dd70e
......@@ -67,7 +67,7 @@ class Groups::Analytics::CycleAnalytics::ValueStreamsController < Groups::Analyt
end
def value_streams
@group.value_streams.presence || [in_memory_default_value_stream]
@group.value_streams.preload_associated_models.presence || [in_memory_default_value_stream]
end
def in_memory_default_value_stream
......
......@@ -10,6 +10,8 @@ class Analytics::CycleAnalytics::GroupValueStream < ApplicationRecord
accepts_nested_attributes_for :stages, allow_destroy: true
scope :preload_associated_models, -> { includes(:group, stages: [:group, :end_event_label, :start_event_label]) }
def custom?
name != Analytics::CycleAnalytics::Stages::BaseService::DEFAULT_VALUE_STREAM_NAME
end
......
......@@ -13,10 +13,26 @@ module Analytics
expose :end_event_identifier, if: -> (s) { s.custom? }
expose :start_event_label, using: LabelEntity, if: -> (s) { s.start_event_label_based? }
expose :end_event_label, using: LabelEntity, if: -> (s) { s.end_event_label_based? }
expose :start_event_html_description
expose :end_event_html_description
def id
object.id || object.name
end
def start_event_html_description
html_description(object.start_event)
end
def end_event_html_description
html_description(object.end_event)
end
private
def html_description(event)
Banzai::Renderer.render(event.markdown_description, { group: object.group, project: nil })
end
end
end
end
......@@ -13,6 +13,10 @@ module Gitlab
:issue_label_added
end
def markdown_description
s_("CycleAnalyticsEvent|%{label_reference} label was added to the issue") % { label_reference: label.to_reference }
end
def object_type
Issue
end
......
......@@ -13,6 +13,10 @@ module Gitlab
:issue_label_removed
end
def markdown_description
s_("CycleAnalyticsEvent|%{label_reference} label was removed from the issue") % { label_reference: label.to_reference }
end
def object_type
Issue
end
......
......@@ -13,6 +13,10 @@ module Gitlab
:merge_request_label_added
end
def markdown_description
s_("CycleAnalyticsEvent|%{label_reference} label was added to the merge request") % { label_reference: label.to_reference }
end
def object_type
MergeRequest
end
......
......@@ -13,6 +13,10 @@ module Gitlab
:merge_request_label_removed
end
def markdown_description
s_("CycleAnalyticsEvent|%{label_reference} label was removed from the merge request") % { label_reference: label.to_reference }
end
def object_type
MergeRequest
end
......
......@@ -5,11 +5,13 @@ Array [
Object {
"custom": false,
"description": "Time before an issue gets scheduled",
"endEventHtmlDescription": "<p data-sourcepos=\\"1:1-1:71\\" dir=\\"auto\\">Issue first associated with a milestone or issue first added to a board</p>",
"hidden": false,
"id": 1,
"legend": "",
"name": "Issue",
"slug": 1,
"startEventHtmlDescription": "<p data-sourcepos=\\"1:1-1:13\\" dir=\\"auto\\">Issue created</p>",
"title": "Issue",
},
Object {
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Analytics::CycleAnalytics::StageEntity do
let(:stage) { build(:cycle_analytics_group_stage, start_event_identifier: :merge_request_created, end_event_identifier: :merge_request_merged) }
subject(:entity_json) { described_class.new(Analytics::CycleAnalytics::StagePresenter.new(stage)).as_json }
it 'exposes start and end event descriptions' do
expect(entity_json).to have_key(:start_event_html_description)
expect(entity_json).to have_key(:end_event_html_description)
end
context 'when label based event is given' do
let(:label) { create(:group_label, title: 'test label') }
let(:stage) { build(:cycle_analytics_group_stage, group: label.group, start_event_label: label, start_event_identifier: :merge_request_label_added, end_event_identifier: :merge_request_merged) }
it 'includes the label reference in the description' do
expect(entity_json[:start_event_html_description]).to include(label.title)
end
end
end
......@@ -19,6 +19,10 @@ module Gitlab
raise NotImplementedError
end
def markdown_description
self.class.name
end
def self.identifier
raise NotImplementedError
end
......
......@@ -9052,6 +9052,18 @@ msgstr ""
msgid "Cycle Time"
msgstr ""
msgid "CycleAnalyticsEvent|%{label_reference} label was added to the issue"
msgstr ""
msgid "CycleAnalyticsEvent|%{label_reference} label was added to the merge request"
msgstr ""
msgid "CycleAnalyticsEvent|%{label_reference} label was removed from the issue"
msgstr ""
msgid "CycleAnalyticsEvent|%{label_reference} label was removed from the merge request"
msgstr ""
msgid "CycleAnalyticsEvent|Issue closed"
msgstr ""
......
......@@ -8,6 +8,7 @@ RSpec.shared_examples_for 'value stream analytics event' do
it { expect(described_class.identifier).to be_a_kind_of(Symbol) }
it { expect(instance.object_type.ancestors).to include(ApplicationRecord) }
it { expect(instance).to respond_to(:timestamp_projection) }
it { expect(instance).to respond_to(:markdown_description) }
it { expect(instance.column_list).to be_a_kind_of(Array) }
describe '#apply_query_customization' do
......
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