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 ...@@ -67,7 +67,7 @@ class Groups::Analytics::CycleAnalytics::ValueStreamsController < Groups::Analyt
end end
def value_streams 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 end
def in_memory_default_value_stream def in_memory_default_value_stream
......
...@@ -10,6 +10,8 @@ class Analytics::CycleAnalytics::GroupValueStream < ApplicationRecord ...@@ -10,6 +10,8 @@ class Analytics::CycleAnalytics::GroupValueStream < ApplicationRecord
accepts_nested_attributes_for :stages, allow_destroy: true accepts_nested_attributes_for :stages, allow_destroy: true
scope :preload_associated_models, -> { includes(:group, stages: [:group, :end_event_label, :start_event_label]) }
def custom? def custom?
name != Analytics::CycleAnalytics::Stages::BaseService::DEFAULT_VALUE_STREAM_NAME name != Analytics::CycleAnalytics::Stages::BaseService::DEFAULT_VALUE_STREAM_NAME
end end
......
...@@ -13,10 +13,26 @@ module Analytics ...@@ -13,10 +13,26 @@ module Analytics
expose :end_event_identifier, if: -> (s) { s.custom? } expose :end_event_identifier, if: -> (s) { s.custom? }
expose :start_event_label, using: LabelEntity, if: -> (s) { s.start_event_label_based? } 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 :end_event_label, using: LabelEntity, if: -> (s) { s.end_event_label_based? }
expose :start_event_html_description
expose :end_event_html_description
def id def id
object.id || object.name object.id || object.name
end 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 end
end end
...@@ -13,6 +13,10 @@ module Gitlab ...@@ -13,6 +13,10 @@ module Gitlab
:issue_label_added :issue_label_added
end end
def markdown_description
s_("CycleAnalyticsEvent|%{label_reference} label was added to the issue") % { label_reference: label.to_reference }
end
def object_type def object_type
Issue Issue
end end
......
...@@ -13,6 +13,10 @@ module Gitlab ...@@ -13,6 +13,10 @@ module Gitlab
:issue_label_removed :issue_label_removed
end end
def markdown_description
s_("CycleAnalyticsEvent|%{label_reference} label was removed from the issue") % { label_reference: label.to_reference }
end
def object_type def object_type
Issue Issue
end end
......
...@@ -13,6 +13,10 @@ module Gitlab ...@@ -13,6 +13,10 @@ module Gitlab
:merge_request_label_added :merge_request_label_added
end end
def markdown_description
s_("CycleAnalyticsEvent|%{label_reference} label was added to the merge request") % { label_reference: label.to_reference }
end
def object_type def object_type
MergeRequest MergeRequest
end end
......
...@@ -13,6 +13,10 @@ module Gitlab ...@@ -13,6 +13,10 @@ module Gitlab
:merge_request_label_removed :merge_request_label_removed
end end
def markdown_description
s_("CycleAnalyticsEvent|%{label_reference} label was removed from the merge request") % { label_reference: label.to_reference }
end
def object_type def object_type
MergeRequest MergeRequest
end end
......
...@@ -5,11 +5,13 @@ Array [ ...@@ -5,11 +5,13 @@ Array [
Object { Object {
"custom": false, "custom": false,
"description": "Time before an issue gets scheduled", "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, "hidden": false,
"id": 1, "id": 1,
"legend": "", "legend": "",
"name": "Issue", "name": "Issue",
"slug": 1, "slug": 1,
"startEventHtmlDescription": "<p data-sourcepos=\\"1:1-1:13\\" dir=\\"auto\\">Issue created</p>",
"title": "Issue", "title": "Issue",
}, },
Object { 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 ...@@ -19,6 +19,10 @@ module Gitlab
raise NotImplementedError raise NotImplementedError
end end
def markdown_description
self.class.name
end
def self.identifier def self.identifier
raise NotImplementedError raise NotImplementedError
end end
......
...@@ -9052,6 +9052,18 @@ msgstr "" ...@@ -9052,6 +9052,18 @@ msgstr ""
msgid "Cycle Time" msgid "Cycle Time"
msgstr "" 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" msgid "CycleAnalyticsEvent|Issue closed"
msgstr "" msgstr ""
......
...@@ -8,6 +8,7 @@ RSpec.shared_examples_for 'value stream analytics event' do ...@@ -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(described_class.identifier).to be_a_kind_of(Symbol) }
it { expect(instance.object_type.ancestors).to include(ApplicationRecord) } it { expect(instance.object_type.ancestors).to include(ApplicationRecord) }
it { expect(instance).to respond_to(:timestamp_projection) } 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) } it { expect(instance.column_list).to be_a_kind_of(Array) }
describe '#apply_query_customization' do 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