Rename folders
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import {ActionInputs, ActionReference, parseActionReference} from "@github/actions-languageservice/action";
|
||||
import {WorkflowContext} from "@github/actions-languageservice/context/workflow-context";
|
||||
import {Value} from "@github/actions-languageservice/value-providers/config";
|
||||
import {isActionStep} from "@github/actions-workflow-parser/model/type-guards";
|
||||
import {Octokit} from "@octokit/rest";
|
||||
import {fetchActionMetadata} from "../utils/action-metadata";
|
||||
import {TTLCache} from "../utils/cache";
|
||||
|
||||
export async function getActionInputs(
|
||||
client: Octokit,
|
||||
cache: TTLCache,
|
||||
action: ActionReference
|
||||
): Promise<ActionInputs | undefined> {
|
||||
return (await fetchActionMetadata(client, cache, action))?.inputs;
|
||||
}
|
||||
|
||||
export async function getActionInputValues(
|
||||
client: Octokit,
|
||||
cache: TTLCache,
|
||||
context: WorkflowContext
|
||||
): Promise<Value[]> {
|
||||
if (!context.step || !isActionStep(context.step)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const action = parseActionReference(context.step.uses.value);
|
||||
if (!action) {
|
||||
return [];
|
||||
}
|
||||
const inputs = await getActionInputs(client, cache, action);
|
||||
if (!inputs) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Object.entries(inputs).map(([inputName, input]) => {
|
||||
return {
|
||||
label: inputName,
|
||||
description: input.description,
|
||||
insertText: `${inputName}: `,
|
||||
deprecated: input.deprecationMessage !== undefined
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import {Value} from "@github/actions-languageservice/value-providers/config";
|
||||
import {Octokit} from "@octokit/rest";
|
||||
import {TTLCache} from "../utils/cache";
|
||||
|
||||
export async function getEnvironments(client: Octokit, cache: TTLCache, owner: string, name: string): Promise<Value[]> {
|
||||
const environments = await cache.get(`${owner}/${name}/environments`, undefined, () =>
|
||||
fetchEnvironments(client, owner, name)
|
||||
);
|
||||
return Array.from(environments).map(env => ({label: env}));
|
||||
}
|
||||
|
||||
async function fetchEnvironments(client: Octokit, owner: string, name: string): Promise<string[]> {
|
||||
let environments: string[] = [];
|
||||
try {
|
||||
const response = await client.repos.getAllEnvironments({
|
||||
owner,
|
||||
repo: name
|
||||
});
|
||||
|
||||
if (response.data.environments) {
|
||||
environments = response.data.environments.map(env => env.name);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("Failure to retrieve environments: ", e);
|
||||
}
|
||||
|
||||
return environments;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import {log} from "@github/actions-languageservice/log";
|
||||
import {Value} from "@github/actions-languageservice/value-providers/config";
|
||||
import {DEFAULT_RUNNER_LABELS} from "@github/actions-languageservice/value-providers/default";
|
||||
import {Octokit} from "@octokit/rest";
|
||||
import {TTLCache} from "../utils/cache";
|
||||
|
||||
// Limitation: getRunnerLabels returns default hosted labels and labels for repository self-hosted runners.
|
||||
// It doesn't return labels for organization runners visible to the repository.
|
||||
export async function getRunnerLabels(client: Octokit, cache: TTLCache, owner: string, name: string): Promise<Value[]> {
|
||||
const repoLabels = await cache.get(`${owner}/${name}/runner-labels`, undefined, () =>
|
||||
fetchRunnerLabels(client, owner, name)
|
||||
);
|
||||
|
||||
for (const label of DEFAULT_RUNNER_LABELS) {
|
||||
repoLabels.add(label);
|
||||
}
|
||||
|
||||
return Array.from(repoLabels).map(label => ({label}));
|
||||
}
|
||||
|
||||
async function fetchRunnerLabels(client: Octokit, owner: string, name: string): Promise<Set<string>> {
|
||||
const labels = new Set<string>();
|
||||
try {
|
||||
const itor = client.paginate.iterator(client.actions.listSelfHostedRunnersForRepo, {
|
||||
owner,
|
||||
repo: name,
|
||||
per_page: 100
|
||||
});
|
||||
|
||||
for await (const response of itor) {
|
||||
for (const runner of response.data) {
|
||||
for (const label of runner.labels) {
|
||||
labels.add(label.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
log(`Failure to retrieve runner labels: ${e}`);
|
||||
}
|
||||
|
||||
return labels;
|
||||
}
|
||||
Reference in New Issue
Block a user