Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

Commit

Permalink
Add various paths for CODEOWNERS file
Browse files Browse the repository at this point in the history
  • Loading branch information
ekadlecova committed Feb 22, 2019
1 parent 232b932 commit 33f3d71
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 7 deletions.
12 changes: 8 additions & 4 deletions lib/codeowners/checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,17 @@ def main_group
codeowners.main_group
end

def codeowners_filename
File.join(@repo_dir, '.github', 'CODEOWNERS')
end

def commit_changes!
@git.add(codeowners_filename)
@git.commit('Fix pattern :robot:')
end

private

def codeowners_filename
directories = ['', '.github', 'docs', '.gitlab']
paths = directories.map { |dir| File.join(@repo_dir, dir, 'CODEOWNERS') }
Dir.glob(paths).first || paths.first
end
end
end
5 changes: 2 additions & 3 deletions spec/codeowners/checker/group/line_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@

describe '.subclasses' do
let(:line_subclasses) do
ObjectSpace.each_object(::Class).select { |klass| klass < described_class } - [
Codeowners::Checker::Group::UnrecognizedLine
]
ObjectSpace.each_object(::Class).select { |klass| klass < described_class } -
[Codeowners::Checker::Group::UnrecognizedLine]
end

it 'includes all subclasses except of unrecognized line' do
Expand Down
45 changes: 45 additions & 0 deletions spec/codeowners/checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,49 @@ def setup_git_for_project
end
end
end

describe '#codeowners' do
subject { described_class.new(folder_name, from, to) }

context 'when the file is in the .github folder' do
it 'returns the content of the codeowners file' do
expect(subject.codeowners).to be_a(Codeowners::Checker::CodeOwners)
expect(subject.codeowners.to_content).to eq(
['# comment ignored', '.rubocop.yml @owner', 'Gemfile @owner1', 'lib/billing/* @owner2',
'lib/shared/* @owner2 @owner1']
)
end
end

context 'when the file is in the root folder' do
before { FileUtils.mv('project/.github/CODEOWNERS', 'project/CODEOWNERS') }

it 'returns the content of the codeowners file' do
expect(subject.codeowners.to_content).to eq(
['# comment ignored', '.rubocop.yml @owner', 'Gemfile @owner1', 'lib/billing/* @owner2',
'lib/shared/* @owner2 @owner1']
)
end
end

context 'when the file does not exist' do
before { FileUtils.rm_f('project/.github/CODEOWNERS') }

it 'uses a root folder for the file and returns an empty array for the content' do
expect(subject.codeowners.to_content).to eq([])
end
end
end

describe '#main_group' do
subject { described_class.new(folder_name, from, to) }

it 'returns an array containing the main group' do
expect(subject.main_group.to_content).to eq(
['# comment ignored', '.rubocop.yml @owner', 'Gemfile @owner1', 'lib/billing/* @owner2',
'lib/shared/* @owner2 @owner1']
)
expect(subject.main_group).to be_a(Codeowners::Checker::Group)
end
end
end

0 comments on commit 33f3d71

Please sign in to comment.