Get custom values for environment
This commit is contained in:
committed by
Beth Brennan
parent
7a6f26efdb
commit
b0fda7d65c
@@ -7,6 +7,7 @@ import { Octokit } from "@octokit/rest";
|
||||
import { CompletionItem, DocumentUri, Position } from "vscode-languageserver";
|
||||
import { TextDocument } from "vscode-languageserver-textdocument";
|
||||
import { RepositoryContext } from "./initializationOptions";
|
||||
import { getEnvironments } from "./value-providers/job-environtment";
|
||||
import { getRunnerLabels } from "./value-providers/runs-on";
|
||||
|
||||
export async function onCompletion(
|
||||
@@ -38,10 +39,17 @@ async function getCustomValues(
|
||||
if (!repo) {
|
||||
return;
|
||||
}
|
||||
if (key === "runs-on") {
|
||||
const octokit = new Octokit({
|
||||
auth: sessionToken,
|
||||
});
|
||||
return await getRunnerLabels(octokit, repo.owner, repo.name);
|
||||
|
||||
const octokit = new Octokit({
|
||||
auth: sessionToken,
|
||||
});
|
||||
|
||||
switch (key) {
|
||||
case "job-environment": {
|
||||
return await getEnvironments(octokit, repo.owner, repo.name);
|
||||
}
|
||||
case "runs-on": {
|
||||
return await getRunnerLabels(octokit, repo.owner, repo.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { Value } from "@github/actions-languageservice/value-providers/config";
|
||||
import { Octokit } from "@octokit/rest";
|
||||
|
||||
export async function getEnvironments(
|
||||
client: Octokit,
|
||||
owner: string,
|
||||
name: string
|
||||
): Promise<Value[]> {
|
||||
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(e);
|
||||
}
|
||||
|
||||
return Array.from(environments).map((e) => ({ label: e }));
|
||||
}
|
||||
Reference in New Issue
Block a user