diff --git a/actions-languageserver/src/context-providers/secrets.ts b/actions-languageserver/src/context-providers/secrets.ts index 6cff0ce..61c6ca0 100644 --- a/actions-languageserver/src/context-providers/secrets.ts +++ b/actions-languageserver/src/context-providers/secrets.ts @@ -41,6 +41,15 @@ export async function getSecrets( } >(); + secrets.orgSecrets.forEach(secret => + secretsMap.set(secret.value.toLowerCase(), { + key: secret.value, + value: new data.StringData("***"), + description: "Organization secret" + }) + ); + + // Override org secrets with repo secrets secrets.repoSecrets.forEach(secret => secretsMap.set(secret.value.toLowerCase(), { key: secret.value, @@ -76,6 +85,7 @@ async function getRemoteSecrets( ): Promise<{ repoSecrets: StringData[]; environmentSecrets: StringData[]; + orgSecrets: StringData[]; }> { return { repoSecrets: await cache.get(`${repo.owner}/${repo.name}/secrets`, undefined, () => @@ -86,7 +96,8 @@ async function getRemoteSecrets( (await cache.get(`${repo.owner}/${repo.name}/secrets/environment/${environmentName}`, undefined, () => fetchEnvironmentSecrets(octokit, repo.id, environmentName) ))) || - [] + [], + orgSecrets: await cache.get(`${repo.owner}/secrets`, undefined, () => fetchOrganizationSecrets(octokit, repo)) }; } @@ -129,3 +140,22 @@ async function fetchEnvironmentSecrets( return []; } + +async function fetchOrganizationSecrets(octokit: Octokit, repo: RepositoryContext): Promise { + if (!repo.organizationOwned) { + return []; + } + + try { + const secrets: {name: string}[] = await octokit.paginate("GET /repos/{owner}/{repo}/actions/organization-secrets", { + owner: repo.owner, + repo: repo.name, + per_page: 100 + }); + return secrets.map(secret => new StringData(secret.name)); + } catch (e) { + console.log("Failure to retrieve organization secrets: ", e); + } + + return []; +} diff --git a/actions-languageserver/src/context-providers/variables.ts b/actions-languageserver/src/context-providers/variables.ts index bde04b7..52babbd 100644 --- a/actions-languageserver/src/context-providers/variables.ts +++ b/actions-languageserver/src/context-providers/variables.ts @@ -42,6 +42,15 @@ export async function getVariables( } >(); + variables.organizationVariables.forEach(variable => + variablesMap.set(variable.key.toLowerCase(), { + key: variable.key, + value: new data.StringData(variable.value.coerceString()), + description: `${variable.value.coerceString()} - Organization variable` + }) + ); + + // Override org variables with repo variables variables.repoVariables.forEach(variable => variablesMap.set(variable.key.toLowerCase(), { key: variable.key, @@ -77,6 +86,7 @@ export async function getRemoteVariables( ): Promise<{ repoVariables: Pair[]; environmentVariables: Pair[]; + organizationVariables: Pair[]; }> { // Repo variables return { @@ -88,7 +98,10 @@ export async function getRemoteVariables( (await cache.get(`${repo.owner}/${repo.name}/vars/environment/${environmentName}`, undefined, () => fetchEnvironmentVariables(octokit, repo.id, environmentName) ))) || - [] + [], + organizationVariables: await cache.get(`${repo.owner}/vars`, undefined, () => + fetchOrganizationVariables(octokit, repo) + ) }; } @@ -137,3 +150,27 @@ async function fetchEnvironmentVariables( return []; } + +async function fetchOrganizationVariables(octokit: Octokit, repo: RepositoryContext): Promise { + if (!repo.organizationOwned) { + return []; + } + + try { + const variables: {name: string; value: string}[] = await octokit.paginate( + "GET /repos/{owner}/{repo}/actions/organization-variables", + { + owner: repo.owner, + repo: repo.name, + per_page: 100 + } + ); + return variables.map(variable => { + return {key: variable.name, value: new StringData(variable.value)}; + }); + } catch (e) { + console.log("Failure to retrieve organization variables: ", e); + } + + return []; +}