update filter and consolidate logic
Signed-off-by: mbruhin <47482924+mbruhin@users.noreply.github.com>
This commit is contained in:
+2
-3
@@ -23,6 +23,7 @@ import {
|
||||
addFiles,
|
||||
cloneRepo,
|
||||
parseRepoUrl,
|
||||
filterGitFiles,
|
||||
} from '@backstage/plugin-scaffolder-node';
|
||||
import { Config } from '@backstage/config';
|
||||
import fs from 'fs-extra';
|
||||
@@ -413,9 +414,7 @@ export function createPublishBitbucketCloudPullRequestAction(options: {
|
||||
// copy files
|
||||
fs.cpSync(sourceDir, tempDir, {
|
||||
recursive: true,
|
||||
filter: path => {
|
||||
return !(path.indexOf('.git') > -1);
|
||||
},
|
||||
filter: filterGitFiles,
|
||||
});
|
||||
|
||||
await addFiles({
|
||||
|
||||
+2
-3
@@ -26,6 +26,7 @@ import {
|
||||
addFiles,
|
||||
cloneRepo,
|
||||
parseRepoUrl,
|
||||
filterGitFiles,
|
||||
} from '@backstage/plugin-scaffolder-node';
|
||||
import { Config } from '@backstage/config';
|
||||
import fs from 'fs-extra';
|
||||
@@ -453,9 +454,7 @@ export function createPublishBitbucketServerPullRequestAction(options: {
|
||||
// copy files
|
||||
fs.cpSync(sourceDir, tempDir, {
|
||||
recursive: true,
|
||||
filter: path => {
|
||||
return !(path.indexOf('.git') > -1);
|
||||
},
|
||||
filter: filterGitFiles,
|
||||
});
|
||||
|
||||
await addFiles({
|
||||
|
||||
@@ -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