mirror of
https://code.forgejo.org/actions/git-backporting.git
synced 2025-02-23 11:05:44 -05:00
53 lines
No EOL
1.5 KiB
TypeScript
53 lines
No EOL
1.5 KiB
TypeScript
import * as core from "@actions/core";
|
|
import { AuthTokenId } from "@bp/service/configs/configs.types";
|
|
import * as fs from "fs";
|
|
|
|
export const addProcessArgs = (args: string[]) => {
|
|
process.argv = [...process.argv, ...args];
|
|
};
|
|
|
|
export const resetProcessArgs = () => {
|
|
process.argv = ["node", "backporting"];
|
|
};
|
|
|
|
export const resetEnvTokens = () => {
|
|
delete process.env[AuthTokenId.GITHUB_TOKEN];
|
|
delete process.env[AuthTokenId.GITLAB_TOKEN];
|
|
delete process.env[AuthTokenId.CODEBERG_TOKEN];
|
|
delete process.env[AuthTokenId.GIT_TOKEN];
|
|
};
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
export const spyGetInput = (obj: any) => {
|
|
const mock = jest.spyOn(core, "getInput");
|
|
mock.mockImplementation((name: string) : string => {
|
|
return obj[name] ?? "";
|
|
});
|
|
};
|
|
|
|
/**
|
|
* Check array equality performing sort on both sides.
|
|
* DO NOT USE this if ordering matters
|
|
* @param actual
|
|
* @param expected
|
|
*/
|
|
export const expectArrayEqual = (actual: unknown[], expected: unknown[]) => {
|
|
expect(actual.sort()).toEqual(expected.sort());
|
|
};
|
|
|
|
/**
|
|
* Create a test file given the full pathname
|
|
* @param pathname full file pathname e.g, /tmp/dir/filename.json
|
|
* @param content what must be written in the file
|
|
*/
|
|
export const createTestFile = (pathname: string, content: string) => {
|
|
fs.writeFileSync(pathname, content);
|
|
};
|
|
|
|
/**
|
|
* Remove a file located at pathname
|
|
* @param pathname full file pathname e.g, /tmp/dir/filename.json
|
|
*/
|
|
export const removeTestFile = (pathname: string) => {
|
|
fs.rmSync(pathname);
|
|
}; |