Class: CodeOwnership::Private::OwnershipMappers::JsPackageOwnership

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Includes:
Mapper
Defined in:
lib/code_ownership/private/ownership_mappers/js_package_ownership.rb

Constant Summary collapse

@@package_json_cache =

rubocop:disable Style/ClassVars

T.let({}, T::Hash[String, T.nilable(ParseJsPackages::Package)])

Instance Method Summary collapse

Methods included from Mapper

all, included, to_glob_cache

Instance Method Details

#bust_caches!Object



71
72
73
# File 'lib/code_ownership/private/ownership_mappers/js_package_ownership.rb', line 71

def bust_caches!
  @@package_json_cache = {} # rubocop:disable Style/ClassVars
end

#descriptionObject



55
56
57
# File 'lib/code_ownership/private/ownership_mappers/js_package_ownership.rb', line 55

def description
  'Owner metadata key in package.json'
end

#globs_to_owner(files) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/code_ownership/private/ownership_mappers/js_package_ownership.rb', line 45

def globs_to_owner(files)
  ParseJsPackages.all.each_with_object({}) do |package, res|
    owner = owner_for_package(package)
    next if owner.nil?

    res[package.directory.join('**/**').to_s] = owner
  end
end

#map_file_to_owner(file) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/code_ownership/private/ownership_mappers/js_package_ownership.rb', line 18

def map_file_to_owner(file)
  package = map_file_to_relevant_package(file)

  return nil if package.nil?

  owner_for_package(package)
end

#owner_for_package(package) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/code_ownership/private/ownership_mappers/js_package_ownership.rb', line 60

def owner_for_package(package)
  raw_owner_value = package.['owner']
  return nil if !raw_owner_value

  Private.find_team!(
    raw_owner_value,
    package.name
  )
end

#update_cache(cache, files) ⇒ Object



29
30
31
# File 'lib/code_ownership/private/ownership_mappers/js_package_ownership.rb', line 29

def update_cache(cache, files)
  globs_to_owner(files)
end