feat: initial version (#1)
Some checks failed
/ demo (push) Has been cancelled

Co-authored-by: Parker Brown <17183625+parkerbxyz@users.noreply.github.com>
Co-authored-by: Gregor Martynus <gr2m@users.noreply.github.com>
This commit is contained in:
Gregor Martynus
2023-06-08 17:04:10 -07:00
committed by GitHub
parent abcb015889
commit f45685208f
14 changed files with 24977 additions and 3 deletions

59
lib/main.js Normal file
View File

@@ -0,0 +1,59 @@
// @ts-check
import core from "@actions/core";
import { createAppAuth } from "@octokit/auth-app";
import { request } from "@octokit/request";
/**
* @param {string} appId
* @param {string} privateKey
* @param {string} repository
* @param {core} core
* @param {createAppAuth} createAppAuth
* @param {request} request
*/
export async function main(
appId,
privateKey,
repository,
core,
createAppAuth,
request
) {
// Get owner and repo name from GITHUB_REPOSITORY
const [owner, repo] = repository.split("/");
const auth = createAppAuth({
appId,
privateKey,
});
const appAuthentication = await auth({
type: "app",
});
// Get the installation ID
// https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#get-a-repository-installation-for-the-authenticated-app
const { data: installation } = await request(
"GET /repos/{owner}/{repo}/installation",
{
owner,
repo,
headers: {
authorization: `bearer ${appAuthentication.token}`,
},
}
);
// Create a new installation token
const authentication = await auth({
type: "installation",
installationId: installation.id,
repositoryNames: [repo],
});
core.setOutput("token", authentication.token);
// Make token accessible to post function (so we can invalidate it)
core.saveState("token", authentication.token);
}

20
lib/post.js Normal file
View File

@@ -0,0 +1,20 @@
// @ts-check
import core from "@actions/core";
import { request } from "@octokit/request";
/**
* @param {core} core
* @param {request} request
*/
export async function post(core, request) {
const token = core.getState("token");
await request("DELETE /installation/token", {
headers: {
authorization: `token ${token}`,
},
});
core.info("Token revoked");
}