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

39 lines
1.4 KiB
TypeScript

import {DescriptionDictionary} from "@actions/expressions";
import {ContextProviderConfig} from "@actions/languageservice";
import {Mode} from "@actions/languageservice/context-providers/default";
import {WorkflowContext} from "@actions/languageservice/context/workflow-context";
import {Octokit} from "@octokit/rest";
import {getSecrets} from "./context-providers/secrets";
import {getStepsContext} from "./context-providers/steps";
import {getVariables} from "./context-providers/variables";
import {RepositoryContext} from "./initializationOptions";
import {TTLCache} from "./utils/cache";
export function contextProviders(
client: Octokit | undefined,
repo: RepositoryContext | undefined,
cache: TTLCache
): ContextProviderConfig {
if (!repo || !client) {
return {getContext: () => Promise.resolve(undefined)};
}
const getContext = async (
name: string,
defaultContext: DescriptionDictionary | undefined,
workflowContext: WorkflowContext,
mode: Mode
) => {
switch (name) {
case "secrets":
return await getSecrets(workflowContext, client, cache, repo, defaultContext, mode);
case "vars":
return await getVariables(workflowContext, client, cache, repo, defaultContext);
case "steps":
return await getStepsContext(client, cache, defaultContext, workflowContext);
}
};
return {getContext};
}