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