MCPcopy Create free account
hub / github.com/EndBug/add-and-commit / checkInputs

Function checkInputs

src/io.ts:75–263  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

73}
74
75export async function checkInputs() {
76 function setInput(input: input, value: string | undefined) {
77 if (value) return (process.env[`INPUT_${input.toUpperCase()}`] = value);
78 else return delete process.env[`INPUT_${input.toUpperCase()}`];
79 }
80 function setDefault(input: input, value: string) {
81 if (!getInput(input)) setInput(input, value);
82 return getInput(input);
83 }
84
85 // #region add, remove
86 if (!getInput('add') && !getInput('remove'))
87 throw new Error(
88 "Both 'add' and 'remove' are empty, the action has nothing to do.",
89 );
90
91 if (getInput('add')) {
92 const parsed = parseInputArray(getInput('add'));
93 if (parsed.length === 1)
94 core.info(
95 'Add input parsed as single string, running 1 git add command.',
96 );
97 else if (parsed.length > 1)
98 core.info(
99 `Add input parsed as string array, running ${parsed.length} git add commands.`,
100 );
101 else core.setFailed('Add input: array length < 1');
102 }
103 if (getInput('remove')) {
104 const parsed = parseInputArray(getInput('remove') || '');
105 if (parsed.length === 1)
106 core.info(
107 'Remove input parsed as single string, running 1 git rm command.',
108 );
109 else if (parsed.length > 1)
110 core.info(
111 `Remove input parsed as string array, running ${parsed.length} git rm commands.`,
112 );
113 else core.setFailed('Remove input: array length < 1');
114 }
115 // #endregion
116
117 // #region default_author
118 const default_author_valid = ['github_actor', 'user_info', 'github_actions'];
119 if (!default_author_valid.includes(getInput('default_author')))
120 throw new Error(
121 `'${getInput(
122 'default_author',
123 )}' is not a valid value for default_author. Valid values: ${default_author_valid.join(
124 ', ',
125 )}`,
126 );
127 // #endregion
128
129 // #region fetch
130 if (getInput('fetch')) {
131 let value: string | boolean;
132

Callers 1

main.tsFile · 0.90

Calls 4

parseInputArrayFunction · 0.90
getUserInfoFunction · 0.90
getInputFunction · 0.70
setDefaultFunction · 0.70

Tested by

no test coverage detected