diff --git a/README.md b/README.md index 839b6f2..6c12a02 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/code_ownership/configuration.rb b/lib/code_ownership/configuration.rb index 33bef67..a93ff98 100644 --- a/lib/code_ownership/configuration.rb +++ b/lib/code_ownership/configuration.rb @@ -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 @@ -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 diff --git a/lib/code_ownership/private/codeowners_file.rb b/lib/code_ownership/private/codeowners_file.rb index 811dc67..7b1794b 100644 --- a/lib/code_ownership/private/codeowners_file.rb +++ b/lib/code_ownership/private/codeowners_file.rb @@ -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 diff --git a/spec/lib/code_ownership/private/codeowners_file_spec.rb b/spec/lib/code_ownership/private/codeowners_file_spec.rb index 9efb754..0281f2a 100644 --- a/spec/lib/code_ownership/private/codeowners_file_spec.rb +++ b/spec/lib/code_ownership/private/codeowners_file_spec.rb @@ -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 @@ -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