update filter and consolidate logic
Signed-off-by: mbruhin <47482924+mbruhin@users.noreply.github.com>
This commit is contained in:
@@ -33,4 +33,4 @@ export {
|
||||
createBranch,
|
||||
cloneRepo,
|
||||
} from './gitHelpers';
|
||||
export { parseRepoUrl, getRepoSourceDirectory } from './util';
|
||||
export { parseRepoUrl, getRepoSourceDirectory, filterGitFiles } from './util';
|
||||
|
||||
@@ -244,4 +244,26 @@ describe('scaffolder action utils', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('filterGitFiles', () => {
|
||||
it('should filter .git directory and its contents but keep other files', () => {
|
||||
// Import the function to test
|
||||
const { filterGitFiles } = require('./util');
|
||||
|
||||
// Should filter out .git directory
|
||||
expect(filterGitFiles('.git')).toBe(false);
|
||||
|
||||
// Should filter out .git directory in subdirectories
|
||||
expect(filterGitFiles('subdir/.git')).toBe(false);
|
||||
|
||||
// Should filter out files inside .git directory
|
||||
expect(filterGitFiles('.git/config')).toBe(false);
|
||||
expect(filterGitFiles('subdir/.git/config')).toBe(false);
|
||||
|
||||
// Should keep .gitignore and other non-.git-directory files
|
||||
expect(filterGitFiles('.gitignore')).toBe(true);
|
||||
expect(filterGitFiles('src/components/GitHubIcon.js')).toBe(true);
|
||||
expect(filterGitFiles('.github/workflows/ci.yml')).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -186,3 +186,12 @@ export const parseSchemas = (
|
||||
outputSchema: action.schema.output,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Filter function to exclude the .git directory and its contents
|
||||
* while keeping other files like .gitignore
|
||||
* @public
|
||||
*/
|
||||
export function filterGitFiles(path: string): boolean {
|
||||
return !(path.endsWith('.git') || path.includes('.git/'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user