This commit is contained in:
Colin McDonnell
2026-01-13 06:02:29 +00:00
parent 9903072286
commit a57866a8cd
11 changed files with 27384 additions and 1262 deletions
+21
View File
@@ -0,0 +1,21 @@
name: "Get Installation Token"
description: "Get a GitHub App installation token for the current repository"
author: "Pullfrog"
inputs:
repos:
description: "Comma-separated list of additional repo names to grant access to (e.g., 'repo1,repo2'). Current repo is always included."
required: false
outputs:
token:
description: "GitHub App installation token"
runs:
using: "node24"
main: "entry"
post: "entry"
branding:
icon: "key"
color: "green"
+26030
View File
File diff suppressed because one or more lines are too long
+66
View File
@@ -0,0 +1,66 @@
#!/usr/bin/env node
/**
* entry point for get-installation-token action.
* handles both main and post execution using the isPost state pattern.
*/
import * as core from "@actions/core";
import { acquireInstallationToken, revokeInstallationToken } from "./token.ts";
const STATE_TOKEN = "token";
const STATE_IS_POST = "isPost";
async function main(): Promise<void> {
core.saveState(STATE_IS_POST, "true");
const reposInput = core.getInput("repos");
const repos = reposInput
? reposInput.split(",").map((r) => r.trim()).filter(Boolean)
: undefined;
const token = await acquireInstallationToken({ repos });
// mask the token in logs
core.setSecret(token);
// save token to state for post cleanup
core.saveState(STATE_TOKEN, token);
// set as output
core.setOutput("token", token);
const scope = repos?.length
? `current repo + ${repos.join(", ")}`
: "current repo only";
core.info(`installation token acquired successfully (${scope})`);
}
async function post(): Promise<void> {
const token = core.getState(STATE_TOKEN);
if (!token) {
core.debug("no token found in state, skipping revocation");
return;
}
await revokeInstallationToken(token);
core.info("installation token revoked successfully");
}
async function run(): Promise<void> {
try {
const isPost = core.getState(STATE_IS_POST) === "true";
if (isPost) {
await post();
} else {
await main();
}
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
core.setFailed(message);
}
}
await run();
+14
View File
@@ -0,0 +1,14 @@
/**
* token acquisition and revocation for get-installation-token action.
* reuses the existing github.ts utilities.
*/
import { acquireNewToken, revokeGitHubInstallationToken } from "../utils/github.ts";
export async function acquireInstallationToken(opts?: { repos?: string[] }): Promise<string> {
return acquireNewToken(opts);
}
export async function revokeInstallationToken(token: string): Promise<void> {
return revokeGitHubInstallationToken(token);
}