Skip to content

Commit 80d3507

Browse files
authored
feat: hidden directories scan (#405)
Adding a command line flag to extend the file scan for hidden directories.
1 parent 477bd6b commit 80d3507

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ You can configure `codeowners-generator` from several places:
208208

209209
- **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.
210210

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

213215
```sh

__tests__/generate.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,4 +844,26 @@ describe('Generate', () => {
844844
await generateCommand({}, { parent: {} });
845845
expect(writeFile).toHaveBeenCalled();
846846
});
847+
848+
it('should call sync with dot flag when hidden flag is set', async () => {
849+
await generateCommand(
850+
{
851+
hiddenDirectories: true,
852+
},
853+
{ parent: {} }
854+
);
855+
856+
expect(sync.mock.calls[0][1]?.dot).toBeTruthy;
857+
});
858+
859+
it('should call sync without dot flag when hidden flag is not set', async () => {
860+
await generateCommand(
861+
{
862+
hiddenDirectories: false,
863+
},
864+
{ parent: {} }
865+
);
866+
867+
expect(sync.mock.calls[0][1]?.dot).toBeFalsy;
868+
});
847869
});

action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ inputs:
3232
version:
3333
description: codeowners-generator version. It will default to the latest in npm otherwise'
3434
required: false
35+
hidden-directories:
36+
description: Also include searching in hidden (dot) directories.
37+
required: false
38+
default: 'false'
3539

3640
runs:
3741
using: 'composite'
@@ -70,6 +74,10 @@ runs:
7074
ARGS_INPUT+=("--includes ${{inputs.includes}}")
7175
fi
7276
77+
if [ "${{inputs.hidden-directories}}" ]; then
78+
ARGS_INPUT+=("--hidden-directories")
79+
fi
80+
7381
if [ ! -z "${{inputs.version}}" ]; then
7482
VERSION="${{inputs.version}}"
7583
fi

src/bin/cli.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ program
4343
'--check',
4444
'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'
4545
)
46+
.option('--hidden-directories', 'Includes hidden directories when searching for CODEOWNERS files', false)
4647
.action(generateCommand);
4748

4849
program.parse(process.argv);

src/commands/generate.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,18 @@ type GenerateInput = {
2424
useMaintainers?: boolean;
2525
useRootMaintainers?: boolean;
2626
includes?: string[];
27+
hiddenDirectories: boolean;
2728
};
2829

2930
const { basename, dirname } = path;
3031

31-
export const generate: Generate = async ({ rootDir, includes, useMaintainers = false, useRootMaintainers = false }) => {
32+
export const generate: Generate = async ({
33+
rootDir,
34+
includes,
35+
useMaintainers = false,
36+
useRootMaintainers = false,
37+
hiddenDirectories = false,
38+
}) => {
3239
debug('input:', rootDir, includes, useMaintainers, useRootMaintainers);
3340

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

5057
const matches = sync(globs, {
58+
dot: hiddenDirectories,
5159
onlyFiles: true,
5260
});
5361

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

99107
interface Options extends GlobalOptions {
100108
check?: boolean;
109+
hiddenDirectories?: boolean;
101110
}
102111

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

118128
debug('Options:', {
119129
...globalOptions,
@@ -123,13 +133,15 @@ export const command = async (options: Options, command: Command): Promise<void>
123133
groupSourceComments,
124134
preserveBlockPosition,
125135
customRegenerationCommand,
136+
hiddenDirectories,
126137
});
127138

128139
try {
129140
const ownerRules = await generate({
130141
rootDir: __dirname,
131142
useMaintainers,
132143
useRootMaintainers,
144+
hiddenDirectories,
133145
...globalOptions,
134146
});
135147

0 commit comments

Comments
 (0)