feat(plugin-scaffolder-node/githelpers): add function to stage files for removal
Signed-off-by: Sander van Delden <38953576+SanderDelden@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-node': patch
|
||||
---
|
||||
|
||||
Added `removeFiles` helper function for staging file removals in Git.
|
||||
@@ -318,6 +318,21 @@ export const parseRepoUrl: (
|
||||
project?: string;
|
||||
};
|
||||
|
||||
// @public (undocumented)
|
||||
export function removeFiles(options: {
|
||||
dir: string;
|
||||
filepath: string;
|
||||
auth:
|
||||
| {
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
| {
|
||||
token: string;
|
||||
};
|
||||
logger?: LoggerService | undefined;
|
||||
}): Promise<void>;
|
||||
|
||||
// @public
|
||||
export interface ScaffolderActionsExtensionPoint {
|
||||
// (undocumented)
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
import { Git } from '../scm';
|
||||
import {
|
||||
addFiles,
|
||||
removeFiles,
|
||||
cloneRepo,
|
||||
commitAndPushBranch,
|
||||
commitAndPushRepo,
|
||||
@@ -31,6 +32,7 @@ jest.mock('../scm', () => ({
|
||||
fromAuth: jest.fn().mockReturnValue({
|
||||
init: jest.fn(),
|
||||
add: jest.fn(),
|
||||
remove: jest.fn(),
|
||||
checkout: jest.fn(),
|
||||
branch: jest.fn(),
|
||||
commit: jest
|
||||
@@ -528,6 +530,47 @@ describe('addFiles', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('removeFiles', () => {
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('with minimal parameters', () => {
|
||||
beforeEach(async () => {
|
||||
await removeFiles({
|
||||
dir: '/tmp/repo/dir/',
|
||||
filepath: 'file-to-remove.txt',
|
||||
auth: {
|
||||
username: 'test-user',
|
||||
password: 'test-password',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('removes the file', () => {
|
||||
expect(mockedGit.remove).toHaveBeenCalledWith({
|
||||
filepath: 'file-to-remove.txt',
|
||||
dir: '/tmp/repo/dir/',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('with token', async () => {
|
||||
await removeFiles({
|
||||
dir: '/tmp/repo/dir/',
|
||||
filepath: 'file-to-remove.txt',
|
||||
auth: {
|
||||
token: 'test-token',
|
||||
},
|
||||
});
|
||||
|
||||
expect(mockedGit.remove).toHaveBeenCalledWith({
|
||||
filepath: 'file-to-remove.txt',
|
||||
dir: '/tmp/repo/dir/',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('commitAndPushBranch', () => {
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
|
||||
@@ -204,6 +204,27 @@ export async function addFiles(options: {
|
||||
await git.add({ dir, filepath });
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export async function removeFiles(options: {
|
||||
dir: string;
|
||||
filepath: string;
|
||||
// For use cases where token has to be used with Basic Auth
|
||||
// it has to be provided as password together with a username
|
||||
// which may be a fixed value defined by the provider.
|
||||
auth: { username: string; password: string } | { token: string };
|
||||
logger?: LoggerService | undefined;
|
||||
}): Promise<void> {
|
||||
const { dir, filepath, auth, logger } = options;
|
||||
const git = Git.fromAuth({
|
||||
...auth,
|
||||
logger,
|
||||
});
|
||||
|
||||
await git.remove({ dir, filepath });
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
|
||||
@@ -30,6 +30,7 @@ export {
|
||||
commitAndPushRepo,
|
||||
commitAndPushBranch,
|
||||
addFiles,
|
||||
removeFiles,
|
||||
createBranch,
|
||||
cloneRepo,
|
||||
} from './gitHelpers';
|
||||
|
||||
Reference in New Issue
Block a user