Merge pull request #7 from github/elbrenn/environments
Get custom values for environment
This commit is contained in:
@@ -7,6 +7,7 @@ import { Octokit } from "@octokit/rest";
|
|||||||
import { CompletionItem, DocumentUri, Position } from "vscode-languageserver";
|
import { CompletionItem, DocumentUri, Position } from "vscode-languageserver";
|
||||||
import { TextDocument } from "vscode-languageserver-textdocument";
|
import { TextDocument } from "vscode-languageserver-textdocument";
|
||||||
import { RepositoryContext } from "./initializationOptions";
|
import { RepositoryContext } from "./initializationOptions";
|
||||||
|
import { getEnvironments } from "./value-providers/job-environment";
|
||||||
import { getRunnerLabels } from "./value-providers/runs-on";
|
import { getRunnerLabels } from "./value-providers/runs-on";
|
||||||
|
|
||||||
export async function onCompletion(
|
export async function onCompletion(
|
||||||
@@ -38,10 +39,17 @@ async function getCustomValues(
|
|||||||
if (!repo) {
|
if (!repo) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (key === "runs-on") {
|
|
||||||
const octokit = new Octokit({
|
const octokit = new Octokit({
|
||||||
auth: sessionToken,
|
auth: sessionToken,
|
||||||
});
|
});
|
||||||
return await getRunnerLabels(octokit, repo.owner, repo.name);
|
|
||||||
|
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: "bob",
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.data.environments) {
|
||||||
|
environments = response.data.environments.map((env) => env.name);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log("Failure to retrieve environments: ", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Array.from(environments).map((env) => ({ label: env }));
|
||||||
|
}
|
||||||
@@ -34,7 +34,7 @@ export async function getRunnerLabels(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log("Failure to retrieve runner labels: ", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Array.from(labels).map((label) => ({ label }));
|
return Array.from(labels).map((label) => ({ label }));
|
||||||
|
|||||||
Reference in New Issue
Block a user