Update custom value providers
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { ValueProviderConfig } from "@github/actions-languageservice";
|
import { ValueProviderConfig } from "@github/actions-languageservice";
|
||||||
import { WorkflowContext } from "@github/actions-languageservice/context/workflow-context";
|
import { WorkflowContext } from "@github/actions-languageservice/context/workflow-context";
|
||||||
import { Value } from "@github/actions-languageservice/value-providers/config";
|
import { ValueProviderKind } from "@github/actions-languageservice/value-providers/config";
|
||||||
import { Octokit } from "@octokit/rest";
|
import { Octokit } from "@octokit/rest";
|
||||||
import { RepositoryContext } from "./initializationOptions";
|
import { RepositoryContext } from "./initializationOptions";
|
||||||
import { TTLCache } from "./utils/cache";
|
import { TTLCache } from "./utils/cache";
|
||||||
@@ -9,44 +9,27 @@ import { getRunnerLabels } from "./value-providers/runs-on";
|
|||||||
|
|
||||||
export function valueProviders(
|
export function valueProviders(
|
||||||
sessionToken: string | undefined,
|
sessionToken: string | undefined,
|
||||||
repoContext: RepositoryContext | undefined,
|
repo: RepositoryContext | undefined,
|
||||||
cache: TTLCache
|
cache: TTLCache
|
||||||
): ValueProviderConfig {
|
): ValueProviderConfig {
|
||||||
if (!repoContext) {
|
if (!repo || !sessionToken) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const octokit = new Octokit({
|
||||||
|
auth: sessionToken,
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"job-environment": passOctoKit(
|
"job-environment": {
|
||||||
sessionToken,
|
kind: ValueProviderKind.AllowedValues,
|
||||||
repoContext,
|
get: (_: WorkflowContext) =>
|
||||||
cache,
|
getEnvironments(octokit, cache, repo.owner, repo.name),
|
||||||
getEnvironments
|
},
|
||||||
),
|
"runs-on": {
|
||||||
"runs-on": passOctoKit(sessionToken, repoContext, cache, getRunnerLabels),
|
kind: ValueProviderKind.SuggestedValues,
|
||||||
};
|
get: (_: WorkflowContext) =>
|
||||||
}
|
getRunnerLabels(octokit, cache, repo.owner, repo.name),
|
||||||
|
},
|
||||||
function passOctoKit(
|
|
||||||
sessionToken: string | undefined,
|
|
||||||
repo: RepositoryContext,
|
|
||||||
cache: TTLCache,
|
|
||||||
f: (
|
|
||||||
octokit: Octokit,
|
|
||||||
cache: TTLCache,
|
|
||||||
owner: string,
|
|
||||||
name: string
|
|
||||||
) => Promise<Value[]>
|
|
||||||
) {
|
|
||||||
return async function (context: WorkflowContext): Promise<Value[]> {
|
|
||||||
if (!sessionToken) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const octokit = new Octokit({
|
|
||||||
auth: sessionToken,
|
|
||||||
});
|
|
||||||
|
|
||||||
return f(octokit, cache, repo.owner, repo.name);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user