-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
362 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
'@codeowners-flow/cli': minor | ||
--- | ||
|
||
Accept configuration path to generate CODEOWNERS | ||
|
||
Now, users can point where the config file is located: | ||
|
||
```bash | ||
npx codeowners-flow generate -c ./path/to/config | ||
``` |
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 |
---|---|---|
|
@@ -2,4 +2,5 @@ node_modules/ | |
dist/ | ||
.turbo | ||
tsconfig.tsbuildinfo | ||
.history | ||
.history | ||
coverage/ |
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,10 @@ | ||
/** @type {import('@codeowners-flow/cli/config').UserConfig} */ | ||
module.exports = { | ||
outDir: '.github', | ||
rules: [ | ||
{ | ||
patterns: ['*'], | ||
owners: [{ name: '@company/core-team' }], | ||
}, | ||
], | ||
}; |
2 changes: 1 addition & 1 deletion
2
codeowners.config.mjs → examples/composing/codeowners.config.mjs
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,10 @@ | ||
/** @type {import('@codeowners-flow/cli/config').UserConfig} */ | ||
export default { | ||
outDir: '.github', | ||
rules: [ | ||
{ | ||
patterns: ['*'], | ||
owners: [{ name: '@company/core-team' }], | ||
}, | ||
], | ||
}; |
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,10 @@ | ||
/** @type {import('@codeowners-flow/cli/config').UserConfig} */ | ||
export default { | ||
outDir: '.github', | ||
rules: [ | ||
{ | ||
patterns: ['*'], | ||
owners: [{ name: '@company/core-team' }], | ||
}, | ||
], | ||
}; |
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,15 @@ | ||
import { | ||
defineConfig, | ||
defineOwner, | ||
defineRule, | ||
} from '@codeowners-flow/cli/config'; | ||
|
||
export default defineConfig({ | ||
outDir: '.github', | ||
rules: [ | ||
defineRule({ | ||
patterns: ['*'], | ||
owners: [defineOwner({ name: '@company/core-team' })], | ||
}), | ||
], | ||
}); |
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,8 @@ | ||
outDir: .github | ||
rules: | ||
- patterns: | ||
- '*' | ||
- 'docs/**' | ||
owners: | ||
- name: '@company/core-team' | ||
- name: '@company/infra-team' |
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,79 @@ | ||
import { loadUserConfig, type UserConfig } from './index.js'; | ||
|
||
const mockConfig: UserConfig = { | ||
outDir: 'outDir', | ||
rules: [ | ||
{ | ||
owners: [ | ||
{ | ||
name: 'ownerName', | ||
}, | ||
], | ||
patterns: ['*'], | ||
comments: ['comment'], | ||
excludePatterns: ['excludePatterns'], | ||
}, | ||
], | ||
}; | ||
|
||
const mockExploderLoad = vi.fn().mockResolvedValue({ config: mockConfig }); | ||
const mockExplorerSearch = vi.fn().mockResolvedValue({ config: mockConfig }); | ||
vi.mock('cosmiconfig', () => ({ | ||
cosmiconfig: () => { | ||
return { | ||
load: (...args: any) => mockExploderLoad(...args), | ||
search: (...args: any) => mockExplorerSearch(...args), | ||
}; | ||
}, | ||
})); | ||
|
||
describe('fn: loadUserConfig', () => { | ||
it('searches for config if no configRelativePath is sent', async () => { | ||
await loadUserConfig('rootDir'); | ||
expect(mockExplorerSearch).toHaveBeenCalled(); | ||
}); | ||
|
||
it('loads the config sent', () => { | ||
loadUserConfig('rootDir', 'configRelativePath'); | ||
expect(mockExploderLoad).toHaveBeenCalledWith( | ||
expect.stringContaining('configRelativePath'), | ||
); | ||
}); | ||
|
||
it('returns the parsed configuration', async () => { | ||
const config = await loadUserConfig('rootDir', 'configRelativePath'); | ||
expect(config).toEqual(mockConfig); | ||
}); | ||
|
||
describe('error handling', () => { | ||
it('throws an user-friendly error message about the schema', async () => { | ||
const customConfig: Partial<UserConfig> = { | ||
rules: [], | ||
}; | ||
|
||
mockExplorerSearch.mockResolvedValue({ config: customConfig }); | ||
|
||
try { | ||
await loadUserConfig('rootDir'); | ||
} catch (error) { | ||
expect((error as Error).message).toMatchInlineSnapshot( | ||
'"Validation error: Required at \\"outDir\\""', | ||
); | ||
} | ||
}); | ||
|
||
it('throws an user-friendly error message if config file is not found', async () => { | ||
mockExploderLoad.mockRejectedValue( | ||
new Error('no such file or directory'), | ||
); | ||
|
||
try { | ||
await loadUserConfig('rootDir', 'configRelativePath'); | ||
} catch (error) { | ||
expect((error as Error).message).toMatchInlineSnapshot( | ||
'"Config file not found. Please ensure to point a valid config file path or create a new one with the init command."', | ||
); | ||
} | ||
}); | ||
}); | ||
}); |
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
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
Oops, something went wrong.