diff --git a/Gemfile.lock b/Gemfile.lock index 0f0f09d..ef8314c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -17,7 +17,7 @@ GIT PATH remote: . specs: - danger-packwerk (0.13.0) + danger-packwerk (0.14.0) code_ownership danger-plugin-api (~> 1.0) packwerk @@ -61,9 +61,9 @@ GEM cork nap open4 (~> 1.3) - code_ownership (1.29.1) + code_ownership (1.29.2) code_teams (~> 1.0) - parse_packwerk + packs sorbet-runtime code_teams (1.0.0) sorbet-runtime @@ -142,8 +142,10 @@ GEM faraday (>= 1, < 3) sawyer (~> 0.9) open4 (1.3.4) + packs (0.0.5) + sorbet-runtime parallel (1.22.1) - parse_packwerk (0.17.0) + parse_packwerk (0.18.0) sorbet-runtime parser (3.1.3.0) ast (~> 2.4.1) diff --git a/lib/danger-packwerk/private/ownership_information.rb b/lib/danger-packwerk/private/ownership_information.rb index 4dcc36f..980908b 100644 --- a/lib/danger-packwerk/private/ownership_information.rb +++ b/lib/danger-packwerk/private/ownership_information.rb @@ -1,6 +1,7 @@ # typed: strict require 'code_ownership' +require 'packs' module DangerPackwerk module Private @@ -14,7 +15,8 @@ class OwnershipInformation < T::Struct sig { params(package: ParsePackwerk::Package, org_name: String).returns(OwnershipInformation) } def self.for_package(package, org_name) - team = CodeOwnership.for_package(package) + pack = Packs.find(package.name) + team = pack.nil? ? nil : CodeOwnership.for_package(pack) if team.nil? OwnershipInformation.new diff --git a/lib/danger-packwerk/version.rb b/lib/danger-packwerk/version.rb index 9c5e9b3..0d2ae72 100644 --- a/lib/danger-packwerk/version.rb +++ b/lib/danger-packwerk/version.rb @@ -2,5 +2,5 @@ # frozen_string_literal: true module DangerPackwerk - VERSION = '0.13.0' + VERSION = '0.14.0' end diff --git a/sorbet/rbi/gems/code_ownership@1.29.1.rbi b/sorbet/rbi/gems/code_ownership@1.29.1.rbi deleted file mode 100644 index 4315ad2..0000000 --- a/sorbet/rbi/gems/code_ownership@1.29.1.rbi +++ /dev/null @@ -1,336 +0,0 @@ -# typed: true - -# DO NOT EDIT MANUALLY -# This is an autogenerated file for types exported from the `code_ownership` gem. -# Please instead update this file by running `bin/tapioca gem code_ownership`. - -module CodeOwnership - extend ::CodeOwnership - - requires_ancestor { Kernel } - - sig do - params( - backtrace: T.nilable(T::Array[::String]), - excluded_teams: T::Array[::CodeTeams::Team] - ).returns(T.nilable(::CodeTeams::Team)) - end - def for_backtrace(backtrace, excluded_teams: T.unsafe(nil)); end - - sig { params(klass: T.nilable(T.any(::Class, ::Module))).returns(T.nilable(::CodeTeams::Team)) } - def for_class(klass); end - - sig { params(file: ::String).returns(T.nilable(::CodeTeams::Team)) } - def for_file(file); end - - sig { params(package: ::ParsePackwerk::Package).returns(T.nilable(::CodeTeams::Team)) } - def for_package(package); end - - sig { params(team: T.any(::CodeTeams::Team, ::String)).returns(::String) } - def for_team(team); end - - sig { params(files: T::Array[::String], autocorrect: T::Boolean, stage_changes: T::Boolean).void } - def validate!(files: T.unsafe(nil), autocorrect: T.unsafe(nil), stage_changes: T.unsafe(nil)); end - - class << self - sig { void } - def bust_caches!; end - - sig { params(filename: ::String).void } - def remove_file_annotation!(filename); end - end -end - -class CodeOwnership::Cli - class << self - def for_file(argv); end - def for_team(argv); end - def run!(argv); end - - private - - def validate!(argv); end - end -end - -class CodeOwnership::InvalidCodeOwnershipConfigurationError < ::StandardError; end - -module CodeOwnership::Private - class << self - sig { void } - def bust_caches!; end - - sig { returns(::CodeOwnership::Private::Configuration) } - def configuration; end - - sig { returns(::CodeOwnership::Private::OwnershipMappers::FileAnnotations) } - def file_annotations_mapper; end - - sig { params(files: T::Array[::String]).returns(T::Hash[::String, T::Array[::String]]) } - def files_by_mapper(files); end - - sig { params(team_name: ::String, location_of_reference: ::String).returns(::CodeTeams::Team) } - def find_team!(team_name, location_of_reference); end - - sig { returns(T::Array[::CodeOwnership::Private::OwnershipMappers::Interface]) } - def mappers; end - - sig { params(klass: T.nilable(T.any(::Class, ::Module))).returns(T.nilable(::String)) } - def path_from_klass(klass); end - - sig { returns(T::Array[::String]) } - def tracked_files; end - - sig { params(files: T::Array[::String], autocorrect: T::Boolean, stage_changes: T::Boolean).void } - def validate!(files:, autocorrect: T.unsafe(nil), stage_changes: T.unsafe(nil)); end - end -end - -class CodeOwnership::Private::Configuration < ::T::Struct - const :js_package_paths, T::Array[::String] - const :owned_globs, T::Array[::String] - const :skip_codeowners_validation, T::Boolean - const :unowned_globs, T::Array[::String] - - class << self - sig { returns(::CodeOwnership::Private::Configuration) } - def fetch; end - - def inherited(s); end - - sig { params(config_hash: T::Hash[T.untyped, T.untyped]).returns(T::Array[::String]) } - def js_package_paths(config_hash); end - end -end - -CodeOwnership::Private::Configuration::DEFAULT_JS_PACKAGE_PATHS = T.let(T.unsafe(nil), Array) -module CodeOwnership::Private::OwnershipMappers; end - -class CodeOwnership::Private::OwnershipMappers::FileAnnotations - include ::CodeOwnership::Private::OwnershipMappers::Interface - - sig { override.void } - def bust_caches!; end - - sig { override.returns(T::Hash[::String, T.nilable(::CodeTeams::Team)]) } - def codeowners_lines_to_owners; end - - sig { override.returns(::String) } - def description; end - - sig { params(filename: ::String).returns(T.nilable(::CodeTeams::Team)) } - def file_annotation_based_owner(filename); end - - sig { override.params(file: ::String).returns(T.nilable(::CodeTeams::Team)) } - def map_file_to_owner(file); end - - sig { override.params(files: T::Array[::String]).returns(T::Hash[::String, T.nilable(::CodeTeams::Team)]) } - def map_files_to_owners(files); end - - sig { params(filename: ::String).void } - def remove_file_annotation!(filename); end -end - -CodeOwnership::Private::OwnershipMappers::FileAnnotations::TEAM_PATTERN = T.let(T.unsafe(nil), Regexp) - -module CodeOwnership::Private::OwnershipMappers::Interface - interface! - - sig { abstract.void } - def bust_caches!; end - - sig { abstract.returns(T::Hash[::String, T.nilable(::CodeTeams::Team)]) } - def codeowners_lines_to_owners; end - - sig { abstract.returns(::String) } - def description; end - - sig { abstract.params(file: ::String).returns(T.nilable(::CodeTeams::Team)) } - def map_file_to_owner(file); end - - sig { abstract.params(files: T::Array[::String]).returns(T::Hash[::String, T.nilable(::CodeTeams::Team)]) } - def map_files_to_owners(files); end -end - -class CodeOwnership::Private::OwnershipMappers::JsPackageOwnership - include ::CodeOwnership::Private::OwnershipMappers::Interface - - sig { override.void } - def bust_caches!; end - - sig { override.returns(T::Hash[::String, T.nilable(::CodeTeams::Team)]) } - def codeowners_lines_to_owners; end - - sig { override.returns(::String) } - def description; end - - sig { override.params(file: ::String).returns(T.nilable(::CodeTeams::Team)) } - def map_file_to_owner(file); end - - sig { override.params(files: T::Array[::String]).returns(T::Hash[::String, T.nilable(::CodeTeams::Team)]) } - def map_files_to_owners(files); end - - sig { params(package: ::CodeOwnership::Private::ParseJsPackages::Package).returns(T.nilable(::CodeTeams::Team)) } - def owner_for_package(package); end - - private - - sig { params(file: ::String).returns(T.nilable(::CodeOwnership::Private::ParseJsPackages::Package)) } - def map_file_to_relevant_package(file); end -end - -class CodeOwnership::Private::OwnershipMappers::PackageOwnership - include ::CodeOwnership::Private::OwnershipMappers::Interface - - sig { override.void } - def bust_caches!; end - - sig { override.returns(T::Hash[::String, T.nilable(::CodeTeams::Team)]) } - def codeowners_lines_to_owners; end - - sig { override.returns(::String) } - def description; end - - sig { override.params(file: ::String).returns(T.nilable(::CodeTeams::Team)) } - def map_file_to_owner(file); end - - sig { override.params(files: T::Array[::String]).returns(T::Hash[::String, T.nilable(::CodeTeams::Team)]) } - def map_files_to_owners(files); end - - sig { params(package: ::ParsePackwerk::Package).returns(T.nilable(::CodeTeams::Team)) } - def owner_for_package(package); end -end - -class CodeOwnership::Private::OwnershipMappers::TeamGlobs - include ::CodeOwnership::Private::OwnershipMappers::Interface - - sig { override.void } - def bust_caches!; end - - sig { override.returns(T::Hash[::String, T.nilable(::CodeTeams::Team)]) } - def codeowners_lines_to_owners; end - - sig { override.returns(::String) } - def description; end - - sig { override.params(file: ::String).returns(T.nilable(::CodeTeams::Team)) } - def map_file_to_owner(file); end - - sig { override.params(files: T::Array[::String]).returns(T::Hash[::String, T.nilable(::CodeTeams::Team)]) } - def map_files_to_owners(files); end -end - -module CodeOwnership::Private::ParseJsPackages - class << self - sig { returns(T::Array[::CodeOwnership::Private::ParseJsPackages::Package]) } - def all; end - end -end - -CodeOwnership::Private::ParseJsPackages::METADATA = T.let(T.unsafe(nil), String) -CodeOwnership::Private::ParseJsPackages::PACKAGE_JSON_NAME = T.let(T.unsafe(nil), String) - -class CodeOwnership::Private::ParseJsPackages::Package < ::T::Struct - const :metadata, T::Hash[::String, T.untyped] - const :name, ::String - - sig { returns(::Pathname) } - def directory; end - - class << self - sig { params(pathname: ::Pathname).returns(::CodeOwnership::Private::ParseJsPackages::Package) } - def from(pathname); end - - def inherited(s); end - end -end - -CodeOwnership::Private::ParseJsPackages::ROOT_PACKAGE_NAME = T.let(T.unsafe(nil), String) -module CodeOwnership::Private::TeamPlugins; end - -class CodeOwnership::Private::TeamPlugins::Github < ::CodeTeams::Plugin - sig { returns(::CodeOwnership::Private::TeamPlugins::Github::GithubStruct) } - def github; end -end - -class CodeOwnership::Private::TeamPlugins::Github::GithubStruct < ::Struct - def do_not_add_to_codeowners_file; end - def do_not_add_to_codeowners_file=(_); end - def team; end - def team=(_); end - - class << self - def [](*_arg0); end - def inspect; end - def members; end - def new(*_arg0); end - end -end - -class CodeOwnership::Private::TeamPlugins::Ownership < ::CodeTeams::Plugin - sig { returns(T::Array[::String]) } - def owned_globs; end -end - -module CodeOwnership::Private::Validations; end - -class CodeOwnership::Private::Validations::FilesHaveOwners - include ::CodeOwnership::Private::Validations::Interface - - sig do - override - .params( - files: T::Array[::String], - autocorrect: T::Boolean, - stage_changes: T::Boolean - ).returns(T::Array[::String]) - end - def validation_errors(files:, autocorrect: T.unsafe(nil), stage_changes: T.unsafe(nil)); end -end - -class CodeOwnership::Private::Validations::FilesHaveUniqueOwners - include ::CodeOwnership::Private::Validations::Interface - - sig do - override - .params( - files: T::Array[::String], - autocorrect: T::Boolean, - stage_changes: T::Boolean - ).returns(T::Array[::String]) - end - def validation_errors(files:, autocorrect: T.unsafe(nil), stage_changes: T.unsafe(nil)); end -end - -class CodeOwnership::Private::Validations::GithubCodeownersUpToDate - include ::CodeOwnership::Private::Validations::Interface - - sig do - override - .params( - files: T::Array[::String], - autocorrect: T::Boolean, - stage_changes: T::Boolean - ).returns(T::Array[::String]) - end - def validation_errors(files:, autocorrect: T.unsafe(nil), stage_changes: T.unsafe(nil)); end - - private - - sig { returns(T::Array[::String]) } - def codeowners_file_lines; end -end - -module CodeOwnership::Private::Validations::Interface - interface! - - sig do - abstract - .params( - files: T::Array[::String], - autocorrect: T::Boolean, - stage_changes: T::Boolean - ).returns(T::Array[::String]) - end - def validation_errors(files:, autocorrect: T.unsafe(nil), stage_changes: T.unsafe(nil)); end -end diff --git a/sorbet/rbi/gems/code_ownership@1.29.2.rbi b/sorbet/rbi/gems/code_ownership@1.29.2.rbi new file mode 100644 index 0000000..e8d648b --- /dev/null +++ b/sorbet/rbi/gems/code_ownership@1.29.2.rbi @@ -0,0 +1,525 @@ +# typed: true + +# DO NOT EDIT MANUALLY +# This is an autogenerated file for types exported from the `code_ownership` gem. +# Please instead update this file by running `bin/tapioca gem code_ownership`. + +# source://code_ownership//lib/code_ownership/cli.rb#7 +module CodeOwnership + extend ::CodeOwnership + + requires_ancestor { Kernel } + + # Given a backtrace from either `Exception#backtrace` or `caller`, find the + # first line that corresponds to a file with assigned ownership + # + # source://code_ownership//lib/code_ownership.rb#95 + sig do + params( + backtrace: T.nilable(T::Array[::String]), + excluded_teams: T::Array[::CodeTeams::Team] + ).returns(T.nilable(::CodeTeams::Team)) + end + def for_backtrace(backtrace, excluded_teams: T.unsafe(nil)); end + + # source://code_ownership//lib/code_ownership.rb#127 + sig { params(klass: T.nilable(T.any(::Class, ::Module))).returns(T.nilable(::CodeTeams::Team)) } + def for_class(klass); end + + # source://code_ownership//lib/code_ownership.rb#21 + sig { params(file: ::String).returns(T.nilable(::CodeTeams::Team)) } + def for_file(file); end + + # source://code_ownership//lib/code_ownership.rb#144 + sig { params(package: ::Packs::Pack).returns(T.nilable(::CodeTeams::Team)) } + def for_package(package); end + + # source://code_ownership//lib/code_ownership.rb#39 + sig { params(team: T.any(::CodeTeams::Team, ::String)).returns(::String) } + def for_team(team); end + + # source://code_ownership//lib/code_ownership.rb#83 + sig { params(files: T::Array[::String], autocorrect: T::Boolean, stage_changes: T::Boolean).void } + def validate!(files: T.unsafe(nil), autocorrect: T.unsafe(nil), stage_changes: T.unsafe(nil)); end + + class << self + # Generally, you should not ever need to do this, because once your ruby process loads, cached content should not change. + # Namely, the set of files, packages, and directories which are tracked for ownership should not change. + # The primary reason this is helpful is for clients of CodeOwnership who want to test their code, and each test context + # has different ownership and tracked files. + # + # source://code_ownership//lib/code_ownership.rb#153 + sig { void } + def bust_caches!; end + + # source://code_ownership//lib/code_ownership.rb#72 + sig { params(filename: ::String).void } + def remove_file_annotation!(filename); end + end +end + +# source://code_ownership//lib/code_ownership/cli.rb#8 +class CodeOwnership::Cli + class << self + # For now, this just returns team ownership + # Later, this could also return code ownership errors about that file. + # + # source://code_ownership//lib/code_ownership/cli.rb#76 + def for_file(argv); end + + # source://code_ownership//lib/code_ownership/cli.rb#123 + def for_team(argv); end + + # source://code_ownership//lib/code_ownership/cli.rb#9 + def run!(argv); end + + private + + # source://code_ownership//lib/code_ownership/cli.rb#33 + def validate!(argv); end + end +end + +# source://code_ownership//lib/code_ownership.rb#68 +class CodeOwnership::InvalidCodeOwnershipConfigurationError < ::StandardError; end + +# source://code_ownership//lib/code_ownership/private/configuration.rb#4 +module CodeOwnership::Private + class << self + # source://code_ownership//lib/code_ownership/private.rb#30 + sig { void } + def bust_caches!; end + + # source://code_ownership//lib/code_ownership/private.rb#24 + sig { returns(::CodeOwnership::Private::Configuration) } + def configuration; end + + # source://code_ownership//lib/code_ownership/private.rb#69 + sig { returns(::CodeOwnership::Private::OwnershipMappers::FileAnnotations) } + def file_annotations_mapper; end + + # source://code_ownership//lib/code_ownership/private.rb#106 + sig { params(files: T::Array[::String]).returns(T::Hash[::String, T::Array[::String]]) } + def files_by_mapper(files); end + + # source://code_ownership//lib/code_ownership/private.rb#96 + sig { params(team_name: ::String, location_of_reference: ::String).returns(::CodeTeams::Team) } + def find_team!(team_name, location_of_reference); end + + # source://code_ownership//lib/code_ownership/private.rb#59 + sig { returns(T::Array[::CodeOwnership::Private::OwnershipMappers::Interface]) } + def mappers; end + + # Returns a string version of the relative path to a Rails constant, + # or nil if it can't find something + # + # source://code_ownership//lib/code_ownership/private.rb#77 + sig { params(klass: T.nilable(T.any(::Class, ::Module))).returns(T.nilable(::String)) } + def path_from_klass(klass); end + + # The output of this function is string pathnames relative to the root. + # + # source://code_ownership//lib/code_ownership/private.rb#90 + sig { returns(T::Array[::String]) } + def tracked_files; end + + # source://code_ownership//lib/code_ownership/private.rb#37 + sig { params(files: T::Array[::String], autocorrect: T::Boolean, stage_changes: T::Boolean).void } + def validate!(files:, autocorrect: T.unsafe(nil), stage_changes: T.unsafe(nil)); end + end +end + +# source://code_ownership//lib/code_ownership/private/configuration.rb#5 +class CodeOwnership::Private::Configuration < ::T::Struct + const :owned_globs, T::Array[::String] + const :unowned_globs, T::Array[::String] + const :js_package_paths, T::Array[::String] + const :skip_codeowners_validation, T::Boolean + + class << self + # source://code_ownership//lib/code_ownership/private/configuration.rb#15 + sig { returns(::CodeOwnership::Private::Configuration) } + def fetch; end + + # source://sorbet-runtime/0.5.10588/lib/types/struct.rb#13 + def inherited(s); end + + # source://code_ownership//lib/code_ownership/private/configuration.rb#27 + sig { params(config_hash: T::Hash[T.untyped, T.untyped]).returns(T::Array[::String]) } + def js_package_paths(config_hash); end + end +end + +# source://code_ownership//lib/code_ownership/private/configuration.rb#7 +CodeOwnership::Private::Configuration::DEFAULT_JS_PACKAGE_PATHS = T.let(T.unsafe(nil), Array) + +# source://code_ownership//lib/code_ownership/private/ownership_mappers/interface.rb#7 +module CodeOwnership::Private::OwnershipMappers; end + +# Calculate, cache, and return a mapping of file names (relative to the root +# of the repository) to team name. +# +# Example: +# +# { +# 'app/models/company.rb' => Team.find('Setup & Onboarding'), +# ... +# } +# +# source://code_ownership//lib/code_ownership/private/ownership_mappers/file_annotations.rb#17 +class CodeOwnership::Private::OwnershipMappers::FileAnnotations + include ::CodeOwnership::Private::OwnershipMappers::Interface + + # source://code_ownership//lib/code_ownership/private/ownership_mappers/file_annotations.rb#113 + sig { override.void } + def bust_caches!; end + + # source://code_ownership//lib/code_ownership/private/ownership_mappers/file_annotations.rb#102 + sig { override.returns(T::Hash[::String, T.nilable(::CodeTeams::Team)]) } + def codeowners_lines_to_owners; end + + # source://code_ownership//lib/code_ownership/private/ownership_mappers/file_annotations.rb#108 + sig { override.returns(::String) } + def description; end + + # source://code_ownership//lib/code_ownership/private/ownership_mappers/file_annotations.rb#50 + sig { params(filename: ::String).returns(T.nilable(::CodeTeams::Team)) } + def file_annotation_based_owner(filename); end + + # source://code_ownership//lib/code_ownership/private/ownership_mappers/file_annotations.rb#29 + sig { override.params(file: ::String).returns(T.nilable(::CodeTeams::Team)) } + def map_file_to_owner(file); end + + # source://code_ownership//lib/code_ownership/private/ownership_mappers/file_annotations.rb#38 + sig { override.params(files: T::Array[::String]).returns(T::Hash[::String, T.nilable(::CodeTeams::Team)]) } + def map_files_to_owners(files); end + + # source://code_ownership//lib/code_ownership/private/ownership_mappers/file_annotations.rb#86 + sig { params(filename: ::String).void } + def remove_file_annotation!(filename); end +end + +# source://code_ownership//lib/code_ownership/private/ownership_mappers/file_annotations.rb#23 +CodeOwnership::Private::OwnershipMappers::FileAnnotations::TEAM_PATTERN = T.let(T.unsafe(nil), Regexp) + +# @abstract Subclasses must implement the `abstract` methods below. +# +# source://code_ownership//lib/code_ownership/private/ownership_mappers/interface.rb#8 +module CodeOwnership::Private::OwnershipMappers::Interface + interface! + + # @abstract + # + # source://code_ownership//lib/code_ownership/private/ownership_mappers/interface.rb#45 + sig { abstract.void } + def bust_caches!; end + + # @abstract + # + # source://code_ownership//lib/code_ownership/private/ownership_mappers/interface.rb#37 + sig { abstract.returns(T::Hash[::String, T.nilable(::CodeTeams::Team)]) } + def codeowners_lines_to_owners; end + + # @abstract + # + # source://code_ownership//lib/code_ownership/private/ownership_mappers/interface.rb#41 + sig { abstract.returns(::String) } + def description; end + + # This should be fast when run with ONE file + # + # @abstract + # + # source://code_ownership//lib/code_ownership/private/ownership_mappers/interface.rb#21 + sig { abstract.params(file: ::String).returns(T.nilable(::CodeTeams::Team)) } + def map_file_to_owner(file); end + + # This should be fast when run with MANY files + # + # @abstract + # + # source://code_ownership//lib/code_ownership/private/ownership_mappers/interface.rb#31 + sig { abstract.params(files: T::Array[::String]).returns(T::Hash[::String, T.nilable(::CodeTeams::Team)]) } + def map_files_to_owners(files); end +end + +# source://code_ownership//lib/code_ownership/private/ownership_mappers/js_package_ownership.rb#8 +class CodeOwnership::Private::OwnershipMappers::JsPackageOwnership + include ::CodeOwnership::Private::OwnershipMappers::Interface + + # source://code_ownership//lib/code_ownership/private/ownership_mappers/js_package_ownership.rb#80 + sig { override.void } + def bust_caches!; end + + # Package ownership ignores the passed in files when generating code owners lines. + # This is because Package ownership knows that the fastest way to find code owners for package based ownership + # is to simply iterate over the packages and grab the owner, rather than iterating over each file just to get what package it is in + # In theory this means that we may generate code owners lines that cover files that are not in the passed in argument, + # but in practice this is not of consequence because in reality we never really want to generate code owners for only a + # subset of files, but rather we want code ownership for all files. + # + # source://code_ownership//lib/code_ownership/private/ownership_mappers/js_package_ownership.rb#54 + sig { override.returns(T::Hash[::String, T.nilable(::CodeTeams::Team)]) } + def codeowners_lines_to_owners; end + + # source://code_ownership//lib/code_ownership/private/ownership_mappers/js_package_ownership.rb#64 + sig { override.returns(::String) } + def description; end + + # source://code_ownership//lib/code_ownership/private/ownership_mappers/js_package_ownership.rb#18 + sig { override.params(file: ::String).returns(T.nilable(::CodeTeams::Team)) } + def map_file_to_owner(file); end + + # source://code_ownership//lib/code_ownership/private/ownership_mappers/js_package_ownership.rb#31 + sig { override.params(files: T::Array[::String]).returns(T::Hash[::String, T.nilable(::CodeTeams::Team)]) } + def map_files_to_owners(files); end + + # source://code_ownership//lib/code_ownership/private/ownership_mappers/js_package_ownership.rb#69 + sig { params(package: ::CodeOwnership::Private::ParseJsPackages::Package).returns(T.nilable(::CodeTeams::Team)) } + def owner_for_package(package); end + + private + + # takes a file and finds the relevant `package.json` file by walking up the directory + # structure. Example, given `packages/a/b/c.rb`, this looks for `packages/a/b/package.json`, `packages/a/package.json`, + # `packages/package.json`, and `package.json` in that order, stopping at the first file to actually exist. + # We do additional caching so that we don't have to check for file existence every time + # + # source://code_ownership//lib/code_ownership/private/ownership_mappers/js_package_ownership.rb#91 + sig { params(file: ::String).returns(T.nilable(::CodeOwnership::Private::ParseJsPackages::Package)) } + def map_file_to_relevant_package(file); end +end + +# source://code_ownership//lib/code_ownership/private/ownership_mappers/package_ownership.rb#8 +class CodeOwnership::Private::OwnershipMappers::PackageOwnership + include ::CodeOwnership::Private::OwnershipMappers::Interface + + # source://code_ownership//lib/code_ownership/private/ownership_mappers/package_ownership.rb#80 + sig { override.void } + def bust_caches!; end + + # Package ownership ignores the passed in files when generating code owners lines. + # This is because Package ownership knows that the fastest way to find code owners for package based ownership + # is to simply iterate over the packages and grab the owner, rather than iterating over each file just to get what package it is in + # In theory this means that we may generate code owners lines that cover files that are not in the passed in argument, + # but in practice this is not of consequence because in reality we never really want to generate code owners for only a + # subset of files, but rather we want code ownership for all files. + # + # source://code_ownership//lib/code_ownership/private/ownership_mappers/package_ownership.rb#54 + sig { override.returns(T::Hash[::String, T.nilable(::CodeTeams::Team)]) } + def codeowners_lines_to_owners; end + + # source://code_ownership//lib/code_ownership/private/ownership_mappers/package_ownership.rb#64 + sig { override.returns(::String) } + def description; end + + # source://code_ownership//lib/code_ownership/private/ownership_mappers/package_ownership.rb#18 + sig { override.params(file: ::String).returns(T.nilable(::CodeTeams::Team)) } + def map_file_to_owner(file); end + + # source://code_ownership//lib/code_ownership/private/ownership_mappers/package_ownership.rb#31 + sig { override.params(files: T::Array[::String]).returns(T::Hash[::String, T.nilable(::CodeTeams::Team)]) } + def map_files_to_owners(files); end + + # source://code_ownership//lib/code_ownership/private/ownership_mappers/package_ownership.rb#69 + sig { params(package: ::Packs::Pack).returns(T.nilable(::CodeTeams::Team)) } + def owner_for_package(package); end +end + +# source://code_ownership//lib/code_ownership/private/ownership_mappers/team_globs.rb#8 +class CodeOwnership::Private::OwnershipMappers::TeamGlobs + include ::CodeOwnership::Private::OwnershipMappers::Interface + + # source://code_ownership//lib/code_ownership/private/ownership_mappers/team_globs.rb#56 + sig { override.void } + def bust_caches!; end + + # source://code_ownership//lib/code_ownership/private/ownership_mappers/team_globs.rb#45 + sig { override.returns(T::Hash[::String, T.nilable(::CodeTeams::Team)]) } + def codeowners_lines_to_owners; end + + # source://code_ownership//lib/code_ownership/private/ownership_mappers/team_globs.rb#62 + sig { override.returns(::String) } + def description; end + + # source://code_ownership//lib/code_ownership/private/ownership_mappers/team_globs.rb#38 + sig { override.params(file: ::String).returns(T.nilable(::CodeTeams::Team)) } + def map_file_to_owner(file); end + + # source://code_ownership//lib/code_ownership/private/ownership_mappers/team_globs.rb#22 + sig { override.params(files: T::Array[::String]).returns(T::Hash[::String, T.nilable(::CodeTeams::Team)]) } + def map_files_to_owners(files); end +end + +# Modeled off of ParsePackwerk +# +# source://code_ownership//lib/code_ownership/private/parse_js_packages.rb#8 +module CodeOwnership::Private::ParseJsPackages + class << self + # source://code_ownership//lib/code_ownership/private/parse_js_packages.rb#57 + sig { returns(T::Array[::CodeOwnership::Private::ParseJsPackages::Package]) } + def all; end + end +end + +# source://code_ownership//lib/code_ownership/private/parse_js_packages.rb#13 +CodeOwnership::Private::ParseJsPackages::METADATA = T.let(T.unsafe(nil), String) + +# source://code_ownership//lib/code_ownership/private/parse_js_packages.rb#12 +CodeOwnership::Private::ParseJsPackages::PACKAGE_JSON_NAME = T.let(T.unsafe(nil), String) + +# source://code_ownership//lib/code_ownership/private/parse_js_packages.rb#15 +class CodeOwnership::Private::ParseJsPackages::Package < ::T::Struct + const :name, ::String + const :metadata, T::Hash[::String, T.untyped] + + # source://code_ownership//lib/code_ownership/private/parse_js_packages.rb#48 + sig { returns(::Pathname) } + def directory; end + + class << self + # source://code_ownership//lib/code_ownership/private/parse_js_packages.rb#22 + sig { params(pathname: ::Pathname).returns(::CodeOwnership::Private::ParseJsPackages::Package) } + def from(pathname); end + + # source://sorbet-runtime/0.5.10588/lib/types/struct.rb#13 + def inherited(s); end + end +end + +# source://code_ownership//lib/code_ownership/private/parse_js_packages.rb#11 +CodeOwnership::Private::ParseJsPackages::ROOT_PACKAGE_NAME = T.let(T.unsafe(nil), String) + +# source://code_ownership//lib/code_ownership/private/team_plugins/ownership.rb#5 +module CodeOwnership::Private::TeamPlugins; end + +# source://code_ownership//lib/code_ownership/private/team_plugins/github.rb#6 +class CodeOwnership::Private::TeamPlugins::Github < ::CodeTeams::Plugin + # source://code_ownership//lib/code_ownership/private/team_plugins/github.rb#13 + sig { returns(::CodeOwnership::Private::TeamPlugins::Github::GithubStruct) } + def github; end +end + +# source://code_ownership//lib/code_ownership/private/team_plugins/github.rb#10 +class CodeOwnership::Private::TeamPlugins::Github::GithubStruct < ::Struct + # Returns the value of attribute do_not_add_to_codeowners_file + # + # @return [Object] the current value of do_not_add_to_codeowners_file + def do_not_add_to_codeowners_file; end + + # Sets the attribute do_not_add_to_codeowners_file + # + # @param value [Object] the value to set the attribute do_not_add_to_codeowners_file to. + # @return [Object] the newly set value + # + # source://code_ownership//lib/code_ownership/private/team_plugins/github.rb#10 + def do_not_add_to_codeowners_file=(_); end + + # Returns the value of attribute team + # + # @return [Object] the current value of team + def team; end + + # Sets the attribute team + # + # @param value [Object] the value to set the attribute team to. + # @return [Object] the newly set value + # + # source://code_ownership//lib/code_ownership/private/team_plugins/github.rb#10 + def team=(_); end + + class << self + def [](*_arg0); end + def inspect; end + def members; end + def new(*_arg0); end + end +end + +# source://code_ownership//lib/code_ownership/private/team_plugins/ownership.rb#6 +class CodeOwnership::Private::TeamPlugins::Ownership < ::CodeTeams::Plugin + # source://code_ownership//lib/code_ownership/private/team_plugins/ownership.rb#11 + sig { returns(T::Array[::String]) } + def owned_globs; end +end + +# source://code_ownership//lib/code_ownership/private/validations/interface.rb#5 +module CodeOwnership::Private::Validations; end + +# source://code_ownership//lib/code_ownership/private/validations/files_have_owners.rb#6 +class CodeOwnership::Private::Validations::FilesHaveOwners + include ::CodeOwnership::Private::Validations::Interface + + # source://code_ownership//lib/code_ownership/private/validations/files_have_owners.rb#12 + sig do + override + .params( + files: T::Array[::String], + autocorrect: T::Boolean, + stage_changes: T::Boolean + ).returns(T::Array[::String]) + end + def validation_errors(files:, autocorrect: T.unsafe(nil), stage_changes: T.unsafe(nil)); end +end + +# source://code_ownership//lib/code_ownership/private/validations/files_have_unique_owners.rb#6 +class CodeOwnership::Private::Validations::FilesHaveUniqueOwners + include ::CodeOwnership::Private::Validations::Interface + + # source://code_ownership//lib/code_ownership/private/validations/files_have_unique_owners.rb#12 + sig do + override + .params( + files: T::Array[::String], + autocorrect: T::Boolean, + stage_changes: T::Boolean + ).returns(T::Array[::String]) + end + def validation_errors(files:, autocorrect: T.unsafe(nil), stage_changes: T.unsafe(nil)); end +end + +# source://code_ownership//lib/code_ownership/private/validations/github_codeowners_up_to_date.rb#6 +class CodeOwnership::Private::Validations::GithubCodeownersUpToDate + include ::CodeOwnership::Private::Validations::Interface + + # source://code_ownership//lib/code_ownership/private/validations/github_codeowners_up_to_date.rb#12 + sig do + override + .params( + files: T::Array[::String], + autocorrect: T::Boolean, + stage_changes: T::Boolean + ).returns(T::Array[::String]) + end + def validation_errors(files:, autocorrect: T.unsafe(nil), stage_changes: T.unsafe(nil)); end + + private + + # Generate the contents of a CODEOWNERS file that GitHub can use to + # automatically assign reviewers + # https://help.github.com/articles/about-codeowners/ + # + # source://code_ownership//lib/code_ownership/private/validations/github_codeowners_up_to_date.rb#100 + sig { returns(T::Array[::String]) } + def codeowners_file_lines; end +end + +# @abstract Subclasses must implement the `abstract` methods below. +# +# source://code_ownership//lib/code_ownership/private/validations/interface.rb#6 +module CodeOwnership::Private::Validations::Interface + interface! + + # @abstract + # + # source://code_ownership//lib/code_ownership/private/validations/interface.rb#13 + sig do + abstract + .params( + files: T::Array[::String], + autocorrect: T::Boolean, + stage_changes: T::Boolean + ).returns(T::Array[::String]) + end + def validation_errors(files:, autocorrect: T.unsafe(nil), stage_changes: T.unsafe(nil)); end +end diff --git a/sorbet/rbi/gems/packs@0.0.5.rbi b/sorbet/rbi/gems/packs@0.0.5.rbi new file mode 100644 index 0000000..399b800 --- /dev/null +++ b/sorbet/rbi/gems/packs@0.0.5.rbi @@ -0,0 +1,111 @@ +# typed: true + +# DO NOT EDIT MANUALLY +# This is an autogenerated file for types exported from the `packs` gem. +# Please instead update this file by running `bin/tapioca gem packs`. + +# source://packs//lib/packs/pack.rb#3 +module Packs + class << self + # source://packs//lib/packs.rb#16 + sig { returns(T::Array[::Packs::Pack]) } + def all; end + + # source://packs//lib/packs.rb#34 + sig { void } + def bust_cache!; end + + # source://packs//lib/packs.rb#41 + sig { returns(::Packs::Private::Configuration) } + def config; end + + # @yield [config] + # + # source://packs//lib/packs.rb#47 + sig { params(blk: T.proc.params(arg0: ::Packs::Private::Configuration).void).void } + def configure(&blk); end + + # source://packs//lib/packs.rb#21 + sig { params(name: ::String).returns(T.nilable(::Packs::Pack)) } + def find(name); end + + # source://packs//lib/packs.rb#26 + sig { params(file_path: T.any(::Pathname, ::String)).returns(T.nilable(::Packs::Pack)) } + def for_file(file_path); end + + private + + # source://packs//lib/packs.rb#73 + sig { returns(T::Array[::Pathname]) } + def package_glob_patterns; end + + # source://packs//lib/packs.rb#59 + sig { returns(T::Hash[::String, ::Packs::Pack]) } + def packs_by_name; end + end +end + +# source://packs//lib/packs.rb#10 +Packs::PACKAGE_FILE = T.let(T.unsafe(nil), String) + +# source://packs//lib/packs/pack.rb#4 +class Packs::Pack < ::T::Struct + const :name, ::String + const :path, ::Pathname + const :relative_path, ::Pathname + const :raw_hash, T::Hash[T.untyped, T.untyped] + + # source://packs//lib/packs/pack.rb#34 + sig { returns(::String) } + def last_name; end + + # source://packs//lib/packs/pack.rb#39 + sig { returns(T::Hash[T.untyped, T.untyped]) } + def metadata; end + + # source://packs//lib/packs/pack.rb#28 + sig { params(relative: T::Boolean).returns(::Pathname) } + def yml(relative: T.unsafe(nil)); end + + class << self + # source://packs//lib/packs/pack.rb#13 + sig { params(package_yml_absolute_path: ::Pathname).returns(::Packs::Pack) } + def from(package_yml_absolute_path); end + + # source://sorbet-runtime/0.5.10588/lib/types/struct.rb#13 + def inherited(s); end + end +end + +# source://packs//lib/packs/private/configuration.rb#4 +module Packs::Private + class << self + # source://packs//lib/packs/private.rb#10 + sig { returns(::Pathname) } + def root; end + end +end + +# source://packs//lib/packs/private/configuration.rb#5 +class Packs::Private::Configuration < ::T::Struct + prop :pack_paths, T::Array[::String] + + class << self + # source://packs//lib/packs/private/configuration.rb#17 + sig { returns(::Packs::Private::Configuration) } + def fetch; end + + # source://sorbet-runtime/0.5.10588/lib/types/struct.rb#13 + def inherited(s); end + + # source://packs//lib/packs/private/configuration.rb#26 + sig { params(config_hash: T::Hash[T.untyped, T.untyped]).returns(T::Array[::String]) } + def pack_paths(config_hash); end + end +end + +# source://packs//lib/packs/private/configuration.rb#7 +Packs::Private::Configuration::CONFIGURATION_PATHNAME = T.let(T.unsafe(nil), Pathname) + +# source://packs//lib/packs/private/configuration.rb#9 +Packs::Private::Configuration::DEFAULT_PACK_PATHS = T.let(T.unsafe(nil), Array) diff --git a/sorbet/rbi/gems/parse_packwerk@0.16.0.rbi b/sorbet/rbi/gems/parse_packwerk@0.18.0.rbi similarity index 90% rename from sorbet/rbi/gems/parse_packwerk@0.16.0.rbi rename to sorbet/rbi/gems/parse_packwerk@0.18.0.rbi index 49e5a19..1bebe2d 100644 --- a/sorbet/rbi/gems/parse_packwerk@0.16.0.rbi +++ b/sorbet/rbi/gems/parse_packwerk@0.18.0.rbi @@ -11,7 +11,7 @@ module ParsePackwerk sig { returns(T::Array[::ParsePackwerk::Package]) } def all; end - # source://parse_packwerk//lib/parse_packwerk.rb#112 + # source://parse_packwerk//lib/parse_packwerk.rb#110 sig { void } def bust_cache!; end @@ -36,7 +36,7 @@ module ParsePackwerk # We memoize packages_by_name for fast lookup. # Since Graph is an immutable value object, we can create indexes and general caching mechanisms safely. # - # source://parse_packwerk//lib/parse_packwerk.rb#100 + # source://parse_packwerk//lib/parse_packwerk.rb#98 sig { returns(T::Hash[::String, ::ParsePackwerk::Package]) } def packages_by_name; end end @@ -120,38 +120,39 @@ ParsePackwerk::PUBLIC_PATH = T.let(T.unsafe(nil), String) # source://parse_packwerk//lib/parse_packwerk/package.rb#4 class ParsePackwerk::Package < ::T::Struct const :name, ::String - const :enforce_dependencies, T::Boolean - const :enforce_privacy, T::Boolean + const :enforce_dependencies, T.any(::String, T::Boolean) + const :enforce_privacy, T.any(::String, T::Boolean) const :public_path, ::String, default: T.unsafe(nil) const :metadata, T::Hash[T.untyped, T.untyped] const :dependencies, T::Array[::String] + const :config, T::Hash[T.untyped, T.untyped] - # source://parse_packwerk//lib/parse_packwerk/package.rb#35 + # source://parse_packwerk//lib/parse_packwerk/package.rb#37 sig { returns(::Pathname) } def directory; end - # source://parse_packwerk//lib/parse_packwerk/package.rb#45 - sig { returns(T::Boolean) } + # source://parse_packwerk//lib/parse_packwerk/package.rb#47 + sig { returns(T.any(::String, T::Boolean)) } def enforces_dependencies?; end - # source://parse_packwerk//lib/parse_packwerk/package.rb#50 - sig { returns(T::Boolean) } + # source://parse_packwerk//lib/parse_packwerk/package.rb#52 + sig { returns(T.any(::String, T::Boolean)) } def enforces_privacy?; end - # source://parse_packwerk//lib/parse_packwerk/package.rb#40 + # source://parse_packwerk//lib/parse_packwerk/package.rb#42 sig { returns(::Pathname) } def public_directory; end - # source://parse_packwerk//lib/parse_packwerk/package.rb#55 + # source://parse_packwerk//lib/parse_packwerk/package.rb#57 sig { returns(T::Array[::ParsePackwerk::Violation]) } def violations; end - # source://parse_packwerk//lib/parse_packwerk/package.rb#30 + # source://parse_packwerk//lib/parse_packwerk/package.rb#32 sig { returns(::Pathname) } def yml; end class << self - # source://parse_packwerk//lib/parse_packwerk/package.rb#15 + # source://parse_packwerk//lib/parse_packwerk/package.rb#16 sig { params(pathname: ::Pathname).returns(::ParsePackwerk::Package) } def from(pathname); end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a34afff..1cd31f7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,6 +3,8 @@ require 'bundler/setup' require 'cork' require 'json' +require 'packs' +require 'packs/rspec/support' module DangerHelpers # These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb @@ -59,23 +61,6 @@ def testing_dangerfile ParsePackwerk.bust_cache! allow(Packwerk::RailsLoadPaths).to receive(:extract_relevant_paths).and_return({}) end - - config.around do |example| - prefix = [File.basename($0), Process.pid].join('-') # rubocop:disable Style/SpecialGlobalVars - tmpdir = Dir.mktmpdir(prefix) - Dir.chdir(tmpdir) do - example.run - end - ensure - FileUtils.rm_rf(tmpdir) - end -end - -def write_file(path, content = '') - pathname = Pathname.new(path) - FileUtils.mkdir_p(pathname.dirname) - pathname.write(content) - path end def sorbet_double(stubbed_class, attr_map = {}) @@ -85,22 +70,7 @@ def sorbet_double(stubbed_class, attr_map = {}) end def write_package_yml( - pack_name, - dependencies: [], - enforce_dependencies: true, - enforce_privacy: true, - metadata: {}, - owner: nil + pack_name ) - metadata['owner'] = owner if owner - - package = ParsePackwerk::Package.new( - name: pack_name, - dependencies: dependencies, - enforce_dependencies: enforce_dependencies, - enforce_privacy: enforce_privacy, - metadata: metadata - ) - - ParsePackwerk.write_package_yml!(package) + write_pack(pack_name, { 'enforce_dependencies' => true, 'enforce_privacy' => true }) end