Class: GitlabQuality::TestTooling::LabelsInference

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_quality/test_tooling/labels_inference.rb

Constant Summary collapse

WWW_GITLAB_COM_SITE =
'https://about.gitlab.com'
WWW_GITLAB_COM_GROUPS_JSON =
"#{WWW_GITLAB_COM_SITE}/groups.json".freeze
WWW_GITLAB_COM_CATEGORIES_JSON =
"#{WWW_GITLAB_COM_SITE}/categories.json".freeze
EM_KEYS =
{
  all: %w[engineering_managers backend_engineering_managers frontend_engineering_managers fullstack_managers],
  generic: %w[engineering_managers],
  backend: %w[backend_engineering_managers],
  frontend: %w[frontend_engineering_managers],
  fullstack: %w[fullstack_managers]
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.fetch_json(json_url) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/gitlab_quality/test_tooling/labels_inference.rb', line 65

def self.fetch_json(json_url)
  json = with_retries { HTTParty.get(json_url, format: :plain) }
  JSON.parse(json)
rescue JSON::ParserError
  Runtime::Logger.debug("#{self.class.name}##{__method__} attempted to parse invalid JSON:\n\n#{json}")
  {}
end

Instance Method Details

#engineering_managers_from_product_group(product_group, *scopes) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/gitlab_quality/test_tooling/labels_inference.rb', line 37

def engineering_managers_from_product_group(product_group, *scopes)
  group_data = groups_mapping[product_group]
  return [] unless group_data

  default_scope = scopes.empty?
  scopes = [:all] if default_scope
  ems = resolve_ems(group_data, scopes, default_scope)

  ems.uniq.sort.map { |name| name.start_with?('@') ? name : "@#{name}" }
end

#infer_labels_from_feature_category(feature_category) ⇒ Object



26
27
28
29
30
31
# File 'lib/gitlab_quality/test_tooling/labels_inference.rb', line 26

def infer_labels_from_feature_category(feature_category)
  [
    categories_mapping.dig(feature_category, 'label'),
    *infer_labels_from_product_group(categories_mapping.dig(feature_category, 'group'))
  ].compact.to_set
end

#infer_labels_from_product_group(product_group) ⇒ Object



22
23
24
# File 'lib/gitlab_quality/test_tooling/labels_inference.rb', line 22

def infer_labels_from_product_group(product_group)
  [groups_mapping.dig(product_group, 'label')].compact.to_set
end

#product_group_from_feature_category(feature_category) ⇒ Object



33
34
35
# File 'lib/gitlab_quality/test_tooling/labels_inference.rb', line 33

def product_group_from_feature_category(feature_category)
  categories_mapping.dig(feature_category, 'group')
end