-
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.
Fix bug where team YML files are considered unowned (#32)
* Add failing test * Fix failing test and update existing tests with new expectations * Fix bug where team YML files are considered unowned
- Loading branch information
Alex Evanczuk
authored
Feb 22, 2023
1 parent
8913407
commit f7696fb
Showing
5 changed files
with
89 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
code_ownership (1.30.0) | ||
code_ownership (1.31.0) | ||
code_teams (~> 1.0) | ||
packs | ||
sorbet-runtime | ||
|
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.30.0' | ||
spec.version = '1.31.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
62 changes: 62 additions & 0 deletions
62
lib/code_ownership/private/ownership_mappers/team_yml_ownership.rb
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: true | ||
|
||
module CodeOwnership | ||
module Private | ||
module OwnershipMappers | ||
class TeamYmlOwnership | ||
extend T::Sig | ||
include Interface | ||
|
||
@@map_files_to_owners = T.let(@map_files_to_owners, T.nilable(T::Hash[String, T.nilable(::CodeTeams::Team)])) # rubocop:disable Style/ClassVars | ||
@@map_files_to_owners = {} # rubocop:disable Style/ClassVars | ||
@@codeowners_lines_to_owners = T.let(@codeowners_lines_to_owners, T.nilable(T::Hash[String, T.nilable(::CodeTeams::Team)])) # rubocop:disable Style/ClassVars | ||
@@codeowners_lines_to_owners = {} # rubocop:disable Style/ClassVars | ||
|
||
sig do | ||
override. | ||
params(files: T::Array[String]). | ||
returns(T::Hash[String, T.nilable(::CodeTeams::Team)]) | ||
end | ||
def map_files_to_owners(files) # rubocop:disable Lint/UnusedMethodArgument | ||
return @@map_files_to_owners if @@map_files_to_owners&.keys && @@map_files_to_owners.keys.count > 0 | ||
|
||
@@map_files_to_owners = CodeTeams.all.each_with_object({}) do |team, map| # rubocop:disable Style/ClassVars | ||
map[team.config_yml] = team | ||
end | ||
end | ||
|
||
sig do | ||
override.params(file: String). | ||
returns(T.nilable(::CodeTeams::Team)) | ||
end | ||
def map_file_to_owner(file) | ||
map_files_to_owners([file])[file] | ||
end | ||
|
||
sig do | ||
override.returns(T::Hash[String, T.nilable(::CodeTeams::Team)]) | ||
end | ||
def codeowners_lines_to_owners | ||
return @@codeowners_lines_to_owners if @@codeowners_lines_to_owners&.keys && @@codeowners_lines_to_owners.keys.count > 0 | ||
|
||
@@codeowners_lines_to_owners = CodeTeams.all.each_with_object({}) do |team, map| # rubocop:disable Style/ClassVars | ||
map[team.config_yml] = team | ||
end | ||
end | ||
|
||
sig { override.void } | ||
def bust_caches! | ||
@@codeowners_lines_to_owners = {} # rubocop:disable Style/ClassVars | ||
@@map_files_to_owners = {} # rubocop:disable Style/ClassVars | ||
end | ||
|
||
sig { override.returns(String) } | ||
def description | ||
'Team YML ownership' | ||
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