Commit a9982762 authored by James Lopez's avatar James Lopez

added analytics stage serializer and moved some info to the stage classes from the controller

parent 3268e377
class AnalyticsStageEntity < Grape::Entity
include EntityDateHelper
expose :stage, as: :title do |object|
object[:stage].to_s.capitalize
end
expose :description
expose :median, as: :value do |stage|
stage[:median] && !stage[:median].zero? ? distance_of_time_in_words(stage[:median]) : nil
end
end
class AnalyticsStageSerializer < BaseSerializer
entity AnalyticsStageEntity
end
module Gitlab module Gitlab
module CycleAnalytics module CycleAnalytics
class BaseStage class BaseStage
attr_reader :stage, :description
def initialize(project:, options:, stage: stage) def initialize(project:, options:, stage: stage)
@project = project @project = project
@options = options @options = options
......
module Gitlab module Gitlab
module CycleAnalytics module CycleAnalytics
class CodeStage < BaseStage class CodeStage < BaseStage
def initialize(*args)
super(*args)
@description = "Time until first merge request"
end
def median def median
@fetcher.calculate_metric(:code, @fetcher.calculate_metric(:code,
Issue::Metrics.arel_table[:first_mentioned_in_commit_at], Issue::Metrics.arel_table[:first_mentioned_in_commit_at],
......
module Gitlab module Gitlab
module CycleAnalytics module CycleAnalytics
class IssueStage < BaseStage class IssueStage < BaseStage
def initialize(*args)
super(*args)
@description = "Time before an issue gets scheduled"
end
def median def median
@fetcher.calculate_metric(:issue, @fetcher.calculate_metric(:issue,
Issue.arel_table[:created_at], Issue.arel_table[:created_at],
......
module Gitlab module Gitlab
module CycleAnalytics module CycleAnalytics
class PlanStage < BaseStage class PlanStage < BaseStage
def initialize(*args)
super(*args)
@description = "Time before an issue starts implementation"
end
def median def median
@fetcher.calculate_metric(:plan, @fetcher.calculate_metric(:plan,
[Issue::Metrics.arel_table[:first_associated_with_milestone_at], [Issue::Metrics.arel_table[:first_associated_with_milestone_at],
......
module Gitlab module Gitlab
module CycleAnalytics module CycleAnalytics
class ProductionStage < BaseStage class ProductionStage < BaseStage
def initialize(*args)
super(*args)
@description = "From issue creation until deploy to production"
end
def median def median
@fetcher.calculate_metric(:production, @fetcher.calculate_metric(:production,
Issue.arel_table[:created_at], Issue.arel_table[:created_at],
......
module Gitlab module Gitlab
module CycleAnalytics module CycleAnalytics
class ReviewStage < BaseStage class ReviewStage < BaseStage
def initialize(*args)
super(*args)
@description = "Time between merge request creation and merge/close"
end
def median def median
@fetcher.calculate_metric(:review, @fetcher.calculate_metric(:review,
MergeRequest.arel_table[:created_at], MergeRequest.arel_table[:created_at],
......
module Gitlab module Gitlab
module CycleAnalytics module CycleAnalytics
class StagingStage < BaseStage class StagingStage < BaseStage
def initialize(*args)
super(*args)
@description = "From merge request merge until deploy to production"
end
def median def median
@fetcher.calculate_metric(:staging, @fetcher.calculate_metric(:staging,
MergeRequest::Metrics.arel_table[:merged_at], MergeRequest::Metrics.arel_table[:merged_at],
......
module Gitlab module Gitlab
module CycleAnalytics module CycleAnalytics
class TestStage < BaseStage class TestStage < BaseStage
def initialize(*args)
super(*args)
@description = "Total test time for all commits/merges"
end
def median def median
@fetcher.calculate_metric(:test, @fetcher.calculate_metric(:test,
MergeRequest::Metrics.arel_table[:latest_build_started_at], MergeRequest::Metrics.arel_table[:latest_build_started_at],
......
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