mirror of
https://github.com/actions/create-github-app-token.git
synced 2026-12-03 15:09:03 +00:00
Revert the redundant redaction in lib/post.js; the token is already masked via core.setSecret in main. The empty warning came from the mocked 401 response having no body, so give it one instead. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 61859778-5e53-432d-864c-8eddd0375f86
49 lines
1.1 KiB
JavaScript
49 lines
1.1 KiB
JavaScript
// @ts-check
|
|
|
|
/**
|
|
* @param {import("@actions/core")} core
|
|
* @param {import("@octokit/request").request} request
|
|
*/
|
|
export async function post(core, request) {
|
|
const skipTokenRevoke = core.getBooleanInput("skip-token-revoke");
|
|
|
|
if (skipTokenRevoke) {
|
|
core.info("Token revocation was skipped");
|
|
return;
|
|
}
|
|
|
|
const token = core.getState("token");
|
|
|
|
if (!token) {
|
|
core.info("Token is not set");
|
|
return;
|
|
}
|
|
|
|
const expiresAt = core.getState("expiresAt");
|
|
if (expiresAt && tokenExpiresIn(expiresAt) < 0) {
|
|
core.info("Token expired, skipping token revocation");
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await request("DELETE /installation/token", {
|
|
headers: {
|
|
authorization: `token ${token}`,
|
|
},
|
|
});
|
|
core.info("Token revoked");
|
|
} catch (error) {
|
|
core.warning(`Token revocation failed: ${error.message}`);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param {string} expiresAt
|
|
*/
|
|
function tokenExpiresIn(expiresAt) {
|
|
const now = new Date();
|
|
const expiresAtDate = new Date(expiresAt);
|
|
|
|
return Math.round((expiresAtDate.getTime() - now.getTime()) / 1000);
|
|
}
|