Files
languageservices/languageservice/src/description-providers/reusable-job-inputs.ts
T
Christopher Schleiden b82ddcdb42 Update import paths
String replacement from `@github/actions-` to `@actions/`
2023-03-23 09:57:18 -07:00

42 lines
1.2 KiB
TypeScript

import {isMapping, isString} from "@actions/workflow-parser";
import {DESCRIPTION} from "@actions/workflow-parser/templates/template-constants";
import {WorkflowContext} from "../context/workflow-context";
import {TokenResult} from "../utils/find-token";
export function isReusableWorkflowJobInput(tokenResult: TokenResult): boolean {
return (
tokenResult.parent?.definition?.key === "workflow-job-with" &&
tokenResult.token !== null &&
isString(tokenResult.token)
);
}
export function getReusableWorkflowInputDescription(
workflowContext: WorkflowContext,
tokenResult: TokenResult
): string {
const reusableWorkflowJob = workflowContext.reusableWorkflowJob;
if (!reusableWorkflowJob) {
return "";
}
const inputName = tokenResult.token && isString(tokenResult.token) && tokenResult.token.value;
if (!inputName) {
return "";
}
// Find the input description in the template, if any
if (reusableWorkflowJob["input-definitions"]) {
const definition = reusableWorkflowJob["input-definitions"].find(inputName);
if (definition && isMapping(definition)) {
const description = definition.find(DESCRIPTION);
if (description && isString(description)) {
return description.value;
}
}
}
return "";
}