Skip to content

Commit b4641b7

Browse files
authored
Merge pull request #349 from YiweiShen/codez-chore-323-refactor-constants-centralize-default-ignore-patterns-3025611328
refactor(constants): centralize default ignore patterns
2 parents 3eed551 + 8d150ee commit b4641b7

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/file/constants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* Default ignore patterns for file scanning.
3+
* Extracted for reuse and customization.
4+
*/
5+
export const DEFAULT_IGNORE_PATTERNS: string[] = ['.git/**', 'node_modules/**'];

src/file/file.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import * as os from 'os';
1212
import ignore from 'ignore';
1313
import * as core from '@actions/core';
1414
import { toErrorMessage } from '../utils/error.js';
15+
import { DEFAULT_IGNORE_PATTERNS } from './constants.js';
1516

1617
/**
1718
* Calculate the SHA-256 hash of the specified file.
@@ -58,10 +59,8 @@ export async function captureFileState(
5859
const gitignorePath = path.join(workspace, '.gitignore');
5960
const ig = ignore();
6061

61-
// Add default ignores - crucial for avoiding git metadata and sensitive files
62-
ig.add('.git/**');
63-
// Consider adding other common ignores if necessary, e.g., node_modules, build artifacts
64-
// ig.add('node_modules/**');
62+
// Add default ignore patterns (e.g., .git, node_modules)
63+
ig.add(DEFAULT_IGNORE_PATTERNS);
6564

6665
if (await pathExists(gitignorePath)) {
6766
core.info(`Reading .gitignore rules from ${gitignorePath}`);
@@ -82,7 +81,7 @@ export async function captureFileState(
8281
cwd: workspace,
8382
onlyFiles: true, // Only files, not directories
8483
dot: true, // Include dotfiles
85-
ignore: ['.git/**', 'node_modules/**'], // Ignore .git and node_modules directories
84+
ignore: DEFAULT_IGNORE_PATTERNS, // Use default ignore patterns
8685
});
8786

8887
// Filter the glob results using the ignore instance

0 commit comments

Comments
 (0)