Add a context provider for secrets

This commit is contained in:
Josh Gross
2022-11-29 16:56:20 -05:00
parent a67069da17
commit 72c7fbd032
10 changed files with 105 additions and 9 deletions
@@ -0,0 +1,22 @@
import {StringData} from "@github/actions-expressions/data/string";
import {Octokit} from "@octokit/rest";
import {TTLCache} from "../utils/cache";
export function getSecrets(octokit: Octokit, cache: TTLCache, owner: string, name: string): Promise<StringData[]> {
return cache.get(`${owner}/${name}/secrets`, undefined, () => fetchSecrets(octokit, owner, name));
}
async function fetchSecrets(octokit: Octokit, owner: string, name: string): Promise<StringData[]> {
try {
const response = await octokit.actions.listRepoSecrets({
owner,
repo: name
});
return response.data.secrets.map(secret => new StringData(secret.name));
} catch (e) {
console.log("Failure to retrieve secrets: ", e);
}
return [];
}