-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow mappers and validators to be injected by the client (#38)
* Allow mappers and validators to be injected into CodeOwnership * Bump version
- Loading branch information
Alex Evanczuk
authored
Mar 8, 2023
1 parent
542a207
commit 80d85b4
Showing
24 changed files
with
325 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Gem::Specification.new do |spec| | ||
spec.name = "code_ownership" | ||
spec.version = '1.31.1' | ||
spec.version = '1.32.0' | ||
spec.authors = ['Gusto Engineers'] | ||
spec.email = ['[email protected]'] | ||
spec.summary = 'A gem to help engineering teams declare ownership of code' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# typed: strict | ||
|
||
module CodeOwnership | ||
class Configuration < T::Struct | ||
extend T::Sig | ||
DEFAULT_JS_PACKAGE_PATHS = T.let(['**/'], T::Array[String]) | ||
|
||
const :owned_globs, T::Array[String] | ||
const :unowned_globs, T::Array[String] | ||
const :js_package_paths, T::Array[String] | ||
const :unbuilt_gems_path, T.nilable(String) | ||
const :skip_codeowners_validation, T::Boolean | ||
const :raw_hash, T::Hash[T.untyped, T.untyped] | ||
|
||
sig { returns(Configuration) } | ||
def self.fetch | ||
config_hash = YAML.load_file('config/code_ownership.yml') | ||
|
||
if config_hash.key?("require") | ||
config_hash["require"].each do |require_directive| | ||
Private::ExtensionLoader.load(require_directive) | ||
end | ||
end | ||
|
||
new( | ||
owned_globs: config_hash.fetch('owned_globs', []), | ||
unowned_globs: config_hash.fetch('unowned_globs', []), | ||
js_package_paths: js_package_paths(config_hash), | ||
skip_codeowners_validation: config_hash.fetch('skip_codeowners_validation', false), | ||
raw_hash: config_hash | ||
) | ||
end | ||
|
||
sig { params(config_hash: T::Hash[T.untyped, T.untyped]).returns(T::Array[String]) } | ||
def self.js_package_paths(config_hash) | ||
specified_package_paths = config_hash['js_package_paths'] | ||
if specified_package_paths.nil? | ||
DEFAULT_JS_PACKAGE_PATHS.dup | ||
else | ||
Array(specified_package_paths) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# frozen_string_literal: true | ||
|
||
# typed: strict | ||
|
||
module CodeOwnership | ||
module Mapper | ||
extend T::Sig | ||
extend T::Helpers | ||
|
||
interface! | ||
|
||
class << self | ||
extend T::Sig | ||
|
||
sig { params(base: Class).void } | ||
def included(base) | ||
@mappers ||= T.let(@mappers, T.nilable(T::Array[Class])) | ||
@mappers ||= [] | ||
@mappers << base | ||
end | ||
|
||
sig { returns(T::Array[Mapper]) } | ||
def all | ||
T.unsafe(@mappers).map(&:new) | ||
end | ||
end | ||
|
||
# | ||
# This should be fast when run with ONE file | ||
# | ||
sig do | ||
abstract.params(file: String). | ||
returns(T.nilable(::CodeTeams::Team)) | ||
end | ||
def map_file_to_owner(file) | ||
end | ||
|
||
# | ||
# This should be fast when run with MANY files | ||
# | ||
sig do | ||
abstract.params(files: T::Array[String]). | ||
returns(T::Hash[String, T.nilable(::CodeTeams::Team)]) | ||
end | ||
def map_files_to_owners(files) | ||
end | ||
|
||
sig do | ||
abstract.returns(T::Hash[String, T.nilable(::CodeTeams::Team)]) | ||
end | ||
def codeowners_lines_to_owners | ||
end | ||
|
||
sig { abstract.returns(String) } | ||
def description | ||
end | ||
|
||
sig { abstract.void } | ||
def bust_caches! | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
module CodeOwnership | ||
module Private | ||
# This class handles loading extensions to code_ownership using the `require` directive | ||
# in the `code_ownership.yml` configuration. | ||
module ExtensionLoader | ||
class << self | ||
extend T::Sig | ||
sig { params(require_directive: String).void } | ||
def load(require_directive) | ||
# We want to transform the require directive to behave differently | ||
# if it's a specific local file being required versus a gem | ||
if require_directive.start_with?(".") | ||
require File.join(Pathname.pwd, require_directive) | ||
else | ||
require require_directive | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.