Skip to content

Commit 834cecf

Browse files
committed
Move CODEOWNERS path into code_ownership.yml configuration
1 parent 3a0ec29 commit 834cecf

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ bin/codeownership for_team 'My Team' > tmp/ownership_report.md
164164

165165
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.
166166

167-
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`.
167+
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`.
168168

169169
## Proper Configuration & Validation
170170

lib/code_ownership/configuration.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Configuration < T::Struct
1212
const :skip_codeowners_validation, T::Boolean
1313
const :raw_hash, T::Hash[T.untyped, T.untyped]
1414
const :require_github_teams, T::Boolean
15+
const :codeowners_path, String
1516

1617
sig { returns(Configuration) }
1718
def self.fetch
@@ -29,7 +30,8 @@ def self.fetch
2930
js_package_paths: js_package_paths(config_hash),
3031
skip_codeowners_validation: config_hash.fetch('skip_codeowners_validation', false),
3132
raw_hash: config_hash,
32-
require_github_teams: config_hash.fetch('require_github_teams', false)
33+
require_github_teams: config_hash.fetch('require_github_teams', false),
34+
codeowners_path: config_hash.fetch('codeowners_path', '.github'),
3335
)
3436
end
3537

lib/code_ownership/private/codeowners_file.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def self.write!
112112
sig { returns(Pathname) }
113113
def self.path
114114
Pathname.pwd.join(
115-
ENV.fetch('CODEOWNERS_PATH', '.github'),
115+
CodeOwnership.configuration.codeowners_path,
116116
'CODEOWNERS'
117117
)
118118
end

spec/lib/code_ownership/private/codeowners_file_spec.rb

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,22 @@ module CodeOwnership
33
describe '.path' do
44
subject { described_class.path }
55

6-
context 'when the environment variable is set' do
6+
context 'when codeowners_path is set in the configuration' do
7+
let(:configuration) do
8+
Configuration.new(
9+
owned_globs: [],
10+
unowned_globs: [],
11+
js_package_paths: [],
12+
unbuilt_gems_path: nil,
13+
skip_codeowners_validation: false,
14+
raw_hash: {},
15+
require_github_teams: false,
16+
codeowners_path: path
17+
)
18+
end
19+
720
before do
8-
allow(ENV).to receive(:fetch).and_call_original
9-
allow(ENV).to receive(:fetch).with('CODEOWNERS_PATH', anything).and_return(path)
21+
allow(CodeOwnership).to receive(:configuration).and_return(configuration)
1022
end
1123

1224
context "to 'foo'" do
@@ -25,12 +37,6 @@ module CodeOwnership
2537
end
2638
end
2739
end
28-
29-
context 'when the environment variable is not set' do
30-
it 'uses the default' do
31-
expect(subject).to eq(Pathname.pwd.join('.github', 'CODEOWNERS'))
32-
end
33-
end
3440
end
3541
end
3642
end

0 commit comments

Comments
 (0)