2021-01-15 03:10:30 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Tracking
|
|
|
|
class StandardContext
|
2021-04-26 21:10:25 +00:00
|
|
|
GITLAB_STANDARD_SCHEMA_URL = 'iglu:com.gitlab/gitlab_standard/jsonschema/1-0-5'
|
2021-03-23 15:09:28 +00:00
|
|
|
GITLAB_RAILS_SOURCE = 'gitlab-rails'
|
2021-01-15 03:10:30 +00:00
|
|
|
|
2021-04-01 12:08:56 +00:00
|
|
|
def initialize(namespace: nil, project: nil, user: nil, **extra)
|
2021-04-26 21:10:25 +00:00
|
|
|
@namespace = namespace
|
|
|
|
@plan = @namespace&.actual_plan_name
|
2021-04-01 12:08:56 +00:00
|
|
|
@extra = extra
|
2021-01-15 03:10:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_context
|
|
|
|
SnowplowTracker::SelfDescribingJson.new(GITLAB_STANDARD_SCHEMA_URL, to_h)
|
|
|
|
end
|
|
|
|
|
2021-01-25 15:09:00 +00:00
|
|
|
def environment
|
|
|
|
return 'staging' if Gitlab.staging?
|
|
|
|
|
2021-02-20 00:10:55 +00:00
|
|
|
return 'production' if Gitlab.com?
|
|
|
|
|
|
|
|
return 'org' if Gitlab.org?
|
|
|
|
|
|
|
|
return 'self-managed' if Rails.env.production?
|
|
|
|
|
2021-01-25 15:09:00 +00:00
|
|
|
'development'
|
|
|
|
end
|
|
|
|
|
2021-01-28 21:09:04 +00:00
|
|
|
def source
|
|
|
|
GITLAB_RAILS_SOURCE
|
|
|
|
end
|
|
|
|
|
2021-01-15 03:10:30 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def to_h
|
2021-02-11 21:09:00 +00:00
|
|
|
{
|
|
|
|
environment: environment,
|
2021-04-01 12:08:56 +00:00
|
|
|
source: source,
|
2021-04-26 21:10:25 +00:00
|
|
|
plan: @plan,
|
2021-04-01 12:08:56 +00:00
|
|
|
extra: @extra
|
|
|
|
}
|
2021-01-15 03:10:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|