Find the input description

This commit is contained in:
Jacob Wallraff
2023-02-17 09:24:55 -08:00
parent e6a6d913b3
commit 8ea37b3d64
2 changed files with 18 additions and 10 deletions
@@ -1,6 +1,8 @@
import {WorkflowTemplate} from "@github/actions-workflow-parser"; import {WorkflowTemplate, isMapping} from "@github/actions-workflow-parser";
import {isReusableWorkflowJob} from "@github/actions-workflow-parser/model/type-guards"; import {isReusableWorkflowJob} from "@github/actions-workflow-parser/model/type-guards";
import {isString} from "@github/actions-workflow-parser";
import {ReusableWorkflowJob} from "@github/actions-workflow-parser/model/workflow-template"; import {ReusableWorkflowJob} from "@github/actions-workflow-parser/model/workflow-template";
import {DESCRIPTION} from "@github/actions-workflow-parser/templates/template-constants";
import {TemplateToken} from "@github/actions-workflow-parser/templates/tokens/template-token"; import {TemplateToken} from "@github/actions-workflow-parser/templates/tokens/template-token";
export async function getReusableWorkflowInputDescription( export async function getReusableWorkflowInputDescription(
@@ -12,22 +14,27 @@ export async function getReusableWorkflowInputDescription(
return undefined; return undefined;
} }
const inputName = isString(token) && token.value;
if (!inputName) {
return undefined;
}
// Filter out just reusable jobs // Filter out just reusable jobs
const templateReusableJobs = template.jobs.filter(isReusableWorkflowJob); const templateReusableJobs = template.jobs.filter(isReusableWorkflowJob);
// Find the reusable job in the template that matches the current reusable job // Find the reusable job in the template that matches the current reusable job
const templateReusableJob = templateReusableJobs.find(job => job.id.value === reusableWorkflowJob.id.value); const templateReusableJob = templateReusableJobs.find(job => job.id.value === reusableWorkflowJob.id.value);
// Set the description on the reusable job to the one from the template, if any // Find the input description in the template, if any
if (templateReusableJob && reusableWorkflowJob["input-definitions"] && templateReusableJob["input-definitions"]) { if (templateReusableJob && reusableWorkflowJob["input-definitions"] && templateReusableJob["input-definitions"]) {
// For each input in the reusable job, see if there's one that matches in the template const definition = templateReusableJob["input-definitions"].find(token.value)
for (const input of reusableWorkflowJob["input-definitions"]) { if (definition && isMapping(definition)) {
return "asd" const description = definition.find(DESCRIPTION)
if (description && isString(description)) {
return description.value
}
} }
} }
return ""
return "Didn't find a matching job description!"
} }
+2 -1
View File
@@ -119,7 +119,8 @@ async function getDescription(
} }
const template = await convertWorkflowTemplate(result.context, result.value, config?.fileProvider, { const template = await convertWorkflowTemplate(result.context, result.value, config?.fileProvider, {
errorPolicy: ErrorPolicy.TryConversion errorPolicy: ErrorPolicy.TryConversion,
fetchReusableWorkflowDepth: config?.fileProvider ? 1 : 0,
}); });
const workflowContext = getWorkflowContext(document.uri, template, path); const workflowContext = getWorkflowContext(document.uri, template, path);
const description = await config.descriptionProvider.getDescription(workflowContext, token, path, template); const description = await config.descriptionProvider.getDescription(workflowContext, token, path, template);