MCPcopy Create free account
hub / github.com/alibaba/open-code-review / parseInputs

Function parseInputs

scripts/github-actions/action-contract.test.js:45–66  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

43}
44
45function parseInputs(text) {
46 const lines = text.split(/\r?\n/);
47 const start = lines.findIndex((line) => /^inputs:\s*$/.test(line));
48 assert.ok(start >= 0, "action.yml must define inputs");
49 const end = lines.findIndex((line, index) => index > start && /^(outputs|runs):\s*$/.test(line));
50 const inputs = {};
51 const limit = end >= 0 ? end : lines.length;
52
53 for (let index = start + 1; index < limit; index += 1) {
54 const match = /^ ([A-Za-z0-9_]+):\s*$/.exec(lines[index]);
55 if (!match) continue;
56 const name = match[1];
57 let defaultValue;
58 for (let cursor = index + 1; cursor < limit; cursor += 1) {
59 if (/^ [A-Za-z0-9_]+:\s*$/.test(lines[cursor])) break;
60 const defaultMatch = /^ default:\s*(.*)$/.exec(lines[cursor]);
61 if (defaultMatch) defaultValue = parseScalar(defaultMatch[1]);
62 }
63 inputs[name] = { default: defaultValue };
64 }
65 return inputs;
66}
67
68function parseSteps(text) {
69 const lines = text.split(/\r?\n/);

Callers 1

Calls 1

parseScalarFunction · 0.85

Tested by

no test coverage detected