Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: hidden directories scan #405

Merged
merged 9 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ You can configure `codeowners-generator` from several places:

- **check** (`--check`): It will fail if the CODEOWNERS generated doesn't match the current (or missing) CODEOWNERS . Useful for validating that the CODEOWNERS file is not out of date during CI.

- **hidden-directories** (`--hidden-directories`): Also include searching in hidden (dot) directories.
For more details you can invoke:

```sh
Expand Down
1 change: 1 addition & 0 deletions src/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ program
'--check',
'It will fail if the CODEOWNERS generated does not match the current (or missing) CODEOWNERS. Useful for validating that the CODEOWNERS file is up to date date during CI'
)
.option('--hidden-directories', 'Includes hidden directories when searching for CODEOWNERS files', false)
.action(generateCommand);

program.parse(process.argv);
14 changes: 13 additions & 1 deletion src/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@ type GenerateInput = {
useMaintainers?: boolean;
useRootMaintainers?: boolean;
includes?: string[];
hiddenDirectories: boolean;
};

const { basename, dirname } = path;

export const generate: Generate = async ({ rootDir, includes, useMaintainers = false, useRootMaintainers = false }) => {
export const generate: Generate = async ({
rootDir,
includes,
useMaintainers = false,
useRootMaintainers = false,
hiddenDirectories = false,
}) => {
debug('input:', rootDir, includes, useMaintainers, useRootMaintainers);

const includePatterns = includes && includes.length ? includes : INCLUDES;
Expand All @@ -48,6 +55,7 @@ export const generate: Generate = async ({ rootDir, includes, useMaintainers = f
debug('provided globs:', globs);

const matches = sync(globs, {
dot: hiddenDirectories,
onlyFiles: true,
});

Expand Down Expand Up @@ -98,6 +106,7 @@ export const generate: Generate = async ({ rootDir, includes, useMaintainers = f

interface Options extends GlobalOptions {
check?: boolean;
hiddenDirectories?: boolean;
}

export const command = async (options: Options, command: Command): Promise<void> => {
Expand All @@ -114,6 +123,7 @@ export const command = async (options: Options, command: Command): Promise<void>
const groupSourceComments = globalOptions.groupSourceComments || options.groupSourceComments;
const preserveBlockPosition = globalOptions.preserveBlockPosition || options.preserveBlockPosition;
const customRegenerationCommand = globalOptions.customRegenerationCommand || options.customRegenerationCommand;
const { hiddenDirectories } = options;

debug('Options:', {
...globalOptions,
Expand All @@ -123,13 +133,15 @@ export const command = async (options: Options, command: Command): Promise<void>
groupSourceComments,
preserveBlockPosition,
customRegenerationCommand,
hiddenDirectories,
});

try {
const ownerRules = await generate({
rootDir: __dirname,
useMaintainers,
useRootMaintainers,
hiddenDirectories,
...globalOptions,
});

Expand Down
Loading