Skip to content

Commit

Permalink
feat: hidden directories scan (#405)
Browse files Browse the repository at this point in the history
Adding a command line flag to extend the file scan for hidden
directories.
  • Loading branch information
guyeise5 authored Jan 12, 2025
1 parent 477bd6b commit 80d3507
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ 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
22 changes: 22 additions & 0 deletions __tests__/generate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -844,4 +844,26 @@ describe('Generate', () => {
await generateCommand({}, { parent: {} });
expect(writeFile).toHaveBeenCalled();
});

it('should call sync with dot flag when hidden flag is set', async () => {
await generateCommand(
{
hiddenDirectories: true,
},
{ parent: {} }
);

expect(sync.mock.calls[0][1]?.dot).toBeTruthy;
});

it('should call sync without dot flag when hidden flag is not set', async () => {
await generateCommand(
{
hiddenDirectories: false,
},
{ parent: {} }
);

expect(sync.mock.calls[0][1]?.dot).toBeFalsy;
});
});
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ inputs:
version:
description: codeowners-generator version. It will default to the latest in npm otherwise'
required: false
hidden-directories:
description: Also include searching in hidden (dot) directories.
required: false
default: 'false'

runs:
using: 'composite'
Expand Down Expand Up @@ -70,6 +74,10 @@ runs:
ARGS_INPUT+=("--includes ${{inputs.includes}}")
fi
if [ "${{inputs.hidden-directories}}" ]; then
ARGS_INPUT+=("--hidden-directories")
fi
if [ ! -z "${{inputs.version}}" ]; then
VERSION="${{inputs.version}}"
fi
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

0 comments on commit 80d3507

Please sign in to comment.