debian-mirror-gitlab/lib/gitlab/tracking/standard_context.rb

45 lines
895 B
Ruby
Raw Normal View History

2021-03-08 18:12:59 +05:30
# frozen_string_literal: true
module Gitlab
module Tracking
class StandardContext
2021-04-29 21:17:54 +05:30
GITLAB_STANDARD_SCHEMA_URL = 'iglu:com.gitlab/gitlab_standard/jsonschema/1-0-4'
GITLAB_RAILS_SOURCE = 'gitlab-rails'
2021-03-08 18:12:59 +05:30
2021-04-29 21:17:54 +05:30
def initialize(namespace: nil, project: nil, user: nil, **extra)
@extra = extra
2021-03-08 18:12:59 +05:30
end
2021-03-11 19:13:27 +05:30
def to_context
SnowplowTracker::SelfDescribingJson.new(GITLAB_STANDARD_SCHEMA_URL, to_h)
2021-03-08 18:12:59 +05:30
end
2021-03-11 19:13:27 +05:30
def environment
return 'staging' if Gitlab.staging?
2021-04-17 20:07:23 +05:30
return 'production' if Gitlab.com?
return 'org' if Gitlab.org?
return 'self-managed' if Rails.env.production?
2021-03-11 19:13:27 +05:30
'development'
2021-03-08 18:12:59 +05:30
end
2021-03-11 19:13:27 +05:30
def source
GITLAB_RAILS_SOURCE
2021-03-08 18:12:59 +05:30
end
private
def to_h
2021-03-11 19:13:27 +05:30
{
environment: environment,
2021-04-29 21:17:54 +05:30
source: source,
extra: @extra
}
2021-03-08 18:12:59 +05:30
end
end
end
end