-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathaction-inputs.ts
More file actions
43 lines (39 loc) · 1.31 KB
/
action-inputs.ts
File metadata and controls
43 lines (39 loc) · 1.31 KB
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
import {ActionInputs, ActionReference, parseActionReference} from "@actions/languageservice/action";
import {WorkflowContext} from "@actions/languageservice/context/workflow-context";
import {Value} from "@actions/languageservice/value-providers/config";
import {isActionStep} from "@actions/workflow-parser/model/type-guards";
import {Octokit} from "@octokit/rest";
import {fetchActionMetadata} from "../utils/action-metadata.js";
import {TTLCache} from "../utils/cache.js";
export async function getActionInputs(
client: Octokit,
cache: TTLCache,
action: ActionReference
): Promise<ActionInputs | undefined> {
return (await fetchActionMetadata(client, cache, action))?.inputs;
}
export async function getActionInputValues(
client: Octokit,
cache: TTLCache,
context: WorkflowContext
): Promise<Value[]> {
if (!context.step || !isActionStep(context.step)) {
return [];
}
const action = parseActionReference(context.step.uses.value);
if (!action) {
return [];
}
const inputs = await getActionInputs(client, cache, action);
if (!inputs) {
return [];
}
return Object.entries(inputs).map(([inputName, input]) => {
return {
label: inputName,
description: input.description,
insertText: `${inputName}: `,
deprecated: input.deprecationMessage !== undefined
};
});
}