Module: PackStats::Private::Metrics

Extended by:
T::Sig
Defined in:
lib/pack_stats/private/metrics.rb,
lib/pack_stats/private/metrics/files.rb,
lib/pack_stats/private/metrics/packages.rb,
lib/pack_stats/private/metrics/dependencies.rb,
lib/pack_stats/private/metrics/public_usage.rb,
lib/pack_stats/private/metrics/packages_by_team.rb,
lib/pack_stats/private/metrics/packwerk_checker_usage.rb

Defined Under Namespace

Classes: Dependencies, Files, Packages, PackagesByTeam, PackwerkCheckerUsage, PublicUsage

Constant Summary collapse

UNKNOWN_OWNER =
T.let('Unknown', String)

Class Method Summary collapse

Class Method Details

.file_count(violations) ⇒ Object



47
48
49
# File 'lib/pack_stats/private/metrics.rb', line 47

def self.file_count(violations)
  violations.sum { |v| v.files.count }
end

.has_readme?(package) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/pack_stats/private/metrics.rb', line 52

def self.has_readme?(package)
  package.directory.join('README.md').exist?
end

.humanized_package_name(name) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/pack_stats/private/metrics.rb', line 38

def self.humanized_package_name(name)
  if name == ParsePackwerk::ROOT_PACKAGE_NAME
    'root'
  else
    name
  end
end

.tags_for_other_team(team_name) ⇒ Object



33
34
35
# File 'lib/pack_stats/private/metrics.rb', line 33

def self.tags_for_other_team(team_name)
  [Tag.for('other_team', team_name || Metrics::UNKNOWN_OWNER)]
end

.tags_for_package(package, app_name) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pack_stats/private/metrics.rb', line 16

def self.tags_for_package(package, app_name)

  tags = [
    Tag.new(key: 'package', value: humanized_package_name(package.name)),
    Tag.new(key: 'app', value: app_name),
    *Metrics.tags_for_team(Private.package_owner(package)),
  ]

  layer = package.config['layer']
  if layer
    tags << Tag.new(key: 'layer', value: layer)
  end

  tags
end

.tags_for_team(team_name) ⇒ Object



11
12
13
# File 'lib/pack_stats/private/metrics.rb', line 11

def self.tags_for_team(team_name)
  [Tag.for('team', team_name || UNKNOWN_OWNER)]
end