Skip to content

Commit

Permalink
Move CODEOWNERS path into code_ownership.yml configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jibarra committed Jan 31, 2025
1 parent 3a0ec29 commit 834cecf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ bin/codeownership for_team 'My Team' > tmp/ownership_report.md

A `CODEOWNERS` file defines who owns specific files or paths in a repository. When you run `bin/codeownership validate`, a `.github/CODEOWNERS` file will automatically be generated and updated.

If the `CODEOWNERS_PATH` environment variable is set, codeowners will use that path to generate the `CODEOWNERS` file. For example, `CODEOWNERS_PATH=docs` will generate `docs/CODEOWNERS`.
If `codeowners_path` is set in `code_ownership.yml` codeowners will use that path to generate the `CODEOWNERS` file. For example, `codeowners_path: docs` will generate `docs/CODEOWNERS`.

## Proper Configuration & Validation

Expand Down
4 changes: 3 additions & 1 deletion lib/code_ownership/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Configuration < T::Struct
const :skip_codeowners_validation, T::Boolean
const :raw_hash, T::Hash[T.untyped, T.untyped]
const :require_github_teams, T::Boolean
const :codeowners_path, String

sig { returns(Configuration) }
def self.fetch
Expand All @@ -29,7 +30,8 @@ def self.fetch
js_package_paths: js_package_paths(config_hash),
skip_codeowners_validation: config_hash.fetch('skip_codeowners_validation', false),
raw_hash: config_hash,
require_github_teams: config_hash.fetch('require_github_teams', false)
require_github_teams: config_hash.fetch('require_github_teams', false),
codeowners_path: config_hash.fetch('codeowners_path', '.github'),
)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/code_ownership/private/codeowners_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def self.write!
sig { returns(Pathname) }
def self.path
Pathname.pwd.join(
ENV.fetch('CODEOWNERS_PATH', '.github'),
CodeOwnership.configuration.codeowners_path,
'CODEOWNERS'
)
end
Expand Down
24 changes: 15 additions & 9 deletions spec/lib/code_ownership/private/codeowners_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,22 @@ module CodeOwnership
describe '.path' do
subject { described_class.path }

context 'when the environment variable is set' do
context 'when codeowners_path is set in the configuration' do
let(:configuration) do
Configuration.new(
owned_globs: [],
unowned_globs: [],
js_package_paths: [],
unbuilt_gems_path: nil,
skip_codeowners_validation: false,
raw_hash: {},
require_github_teams: false,
codeowners_path: path
)
end

before do
allow(ENV).to receive(:fetch).and_call_original
allow(ENV).to receive(:fetch).with('CODEOWNERS_PATH', anything).and_return(path)
allow(CodeOwnership).to receive(:configuration).and_return(configuration)
end

context "to 'foo'" do
Expand All @@ -25,12 +37,6 @@ module CodeOwnership
end
end
end

context 'when the environment variable is not set' do
it 'uses the default' do
expect(subject).to eq(Pathname.pwd.join('.github', 'CODEOWNERS'))
end
end
end
end
end

0 comments on commit 834cecf

Please sign in to comment.