All files / src/utils inputs.ts

100% Statements 28/28
100% Branches 8/8
100% Functions 1/1
100% Lines 28/28

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 441x                       1x 16x   16x 1x 1x   15x 15x 15x 15x 16x 16x 16x 16x 16x 16x 16x 16x   16x 1x 1x   14x 14x 14x 14x 14x 14x 14x  
import * as core from "@actions/core";
import { ViewTypes, isViewType } from "./view-types";
 
export type ActionInputs = {
	target: string;
	ignore: string[];
	showHiddenFiles: boolean;
	theme: string;
	viewType: ViewTypes;
	override: boolean;
};
 
export const getInputs = (): ActionInputs => {
	const viewType = core.getInput("viewType")?.toUpperCase() || ViewTypes.Table;
 
	if (!isViewType(viewType)) {
		throw new Error(`The viewType input must be one of the following: [${Object.values(ViewTypes).join(", ")}]`);
	}
 
	const inputs: ActionInputs = {
		target: core.getInput("target"),
		ignore: core
			.getInput("ignore")
			?.split(",")
			.map((i) => i.trim())
			.filter(Boolean),
		showHiddenFiles: core.getInput("showHiddenFiles").toUpperCase() === "TRUE",
		theme: core.getInput("theme"),
		viewType,
		override: core.getInput("override").toUpperCase() === "TRUE",
	};
 
	if (!inputs.target) {
		throw new Error("The target input is required.");
	}
 
	core.info(
		`Inputs: ${Object.entries(inputs)
			.map(([key, value]) => `${key}=${value}`)
			.join(", ")}`,
	);
	return inputs;
};