Merge pull request #29950 from mbruhin/fix-git-filtering-bitbucket-pull-request-scaffolder
Fix git filtering bitbucket pull request scaffolder
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-backend-module-bitbucket-server': patch
|
||||
'@backstage/plugin-scaffolder-backend-module-bitbucket-cloud': patch
|
||||
'@backstage/plugin-scaffolder-node': patch
|
||||
---
|
||||
|
||||
Update pull request creation filter to include .gitignore files in the created pull request
|
||||
+2
-3
@@ -23,6 +23,7 @@ import {
|
||||
addFiles,
|
||||
cloneRepo,
|
||||
parseRepoUrl,
|
||||
isNotGitDirectoryOrContents,
|
||||
} 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: isNotGitDirectoryOrContents,
|
||||
});
|
||||
|
||||
await addFiles({
|
||||
|
||||
+2
-3
@@ -26,6 +26,7 @@ import {
|
||||
addFiles,
|
||||
cloneRepo,
|
||||
parseRepoUrl,
|
||||
isNotGitDirectoryOrContents,
|
||||
} 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: isNotGitDirectoryOrContents,
|
||||
});
|
||||
|
||||
await addFiles({
|
||||
|
||||
@@ -316,6 +316,9 @@ export function initRepoAndPush(input: {
|
||||
commitHash: string;
|
||||
}>;
|
||||
|
||||
// @public
|
||||
export function isNotGitDirectoryOrContents(path: string): boolean;
|
||||
|
||||
// @public (undocumented)
|
||||
export const parseRepoUrl: (
|
||||
repoUrl: string,
|
||||
|
||||
@@ -33,4 +33,8 @@ export {
|
||||
createBranch,
|
||||
cloneRepo,
|
||||
} from './gitHelpers';
|
||||
export { parseRepoUrl, getRepoSourceDirectory } from './util';
|
||||
export {
|
||||
parseRepoUrl,
|
||||
getRepoSourceDirectory,
|
||||
isNotGitDirectoryOrContents,
|
||||
} from './util';
|
||||
|
||||
@@ -244,4 +244,30 @@ describe('scaffolder action utils', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('isNotGitDirectoryOrContents', () => {
|
||||
it('should filter .git directory and its contents but keep other files', () => {
|
||||
// Import the function to test
|
||||
const { isNotGitDirectoryOrContents } = require('./util');
|
||||
|
||||
// Should filter out .git directory
|
||||
expect(isNotGitDirectoryOrContents('.git')).toBe(false);
|
||||
|
||||
// Should filter out .git directory in subdirectories
|
||||
expect(isNotGitDirectoryOrContents('subdir/.git')).toBe(false);
|
||||
|
||||
// Should filter out files inside .git directory
|
||||
expect(isNotGitDirectoryOrContents('.git/config')).toBe(false);
|
||||
expect(isNotGitDirectoryOrContents('subdir/.git/config')).toBe(false);
|
||||
|
||||
// Should keep .gitignore and other non-.git-directory files
|
||||
expect(isNotGitDirectoryOrContents('.gitignore')).toBe(true);
|
||||
expect(isNotGitDirectoryOrContents('src/components/GitHubIcon.js')).toBe(
|
||||
true,
|
||||
);
|
||||
expect(isNotGitDirectoryOrContents('.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 isNotGitDirectoryOrContents(path: string): boolean {
|
||||
return !(path.endsWith('.git') || path.includes('.git/'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user