-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extracting OwnerAssigner for testing
- Loading branch information
Showing
4 changed files
with
73 additions
and
9 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
module CodeOwnership | ||
module Private | ||
class OwnerAssigner | ||
extend T::Sig | ||
|
||
sig { params(globs_to_owning_team_map: GlobsToOwningTeamMap).returns(GlobsToOwningTeamMap) } | ||
def self.assign_owners(globs_to_owning_team_map) | ||
globs_to_owning_team_map.each_with_object({}) do |(glob, owner), mapping| | ||
mapping[glob] = owner if File.exist?(glob) | ||
Dir.glob(glob).each do |file| | ||
mapping[file] ||= owner | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module CodeOwnership | ||
RSpec.describe Private::OwnerAssigner do | ||
describe '.assign_owners' do | ||
subject(:assign_owners) { described_class.assign_owners(globs_to_owning_team_map) } | ||
|
||
let(:team_1) { instance_double(CodeTeams::Team) } | ||
let(:team_2) { instance_double(CodeTeams::Team) } | ||
|
||
let(:globs_to_owning_team_map) do | ||
{ | ||
'app/services/[test]/some_other_file.ts' => team_1, | ||
'app/services/withoutbracket/file.ts' => team_2, | ||
'app/models/*.rb' => team_2 | ||
} | ||
end | ||
|
||
before do | ||
write_file('app/services/[test]/some_other_file.ts', <<~YML) | ||
// @team Bar | ||
YML | ||
|
||
write_file('app/services/withoutbracket/file.ts', <<~YML) | ||
// @team Bar | ||
YML | ||
end | ||
|
||
it 'returns a hash with the same keys and the values that are files' do | ||
expect(assign_owners).to eq( | ||
'app/services/[test]/some_other_file.ts' => team_1, | ||
'app/services/withoutbracket/file.ts' => team_2 | ||
) | ||
end | ||
|
||
context 'when glob pattern also exists' do | ||
before do | ||
write_file('app/services/t/some_other_file.ts', <<~YML) | ||
// @team Bar | ||
YML | ||
end | ||
|
||
it 'also matches the glob pattern' do | ||
expect(assign_owners).to eq( | ||
'app/services/[test]/some_other_file.ts' => team_1, | ||
'app/services/t/some_other_file.ts' => team_1, | ||
'app/services/withoutbracket/file.ts' => team_2 | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |