c3c17c79cc
This PR switches from evaluating values passed to `skip-token-revoke` as true if they are truthy in JavaScript, to using `getBooleanInput`. This change ensures that only proper YAML boolean values are recognized, preventing unintended evaluations to true. - The definition of `getBooleanInput` is here: definition of `core#getBooealnInput` is here: https://github.com/actions/toolkit/blob/930c89072712a3aac52d74b23338f00bb0cfcb24/packages/core/src/core.ts#L188-L208 The documentation states, `"If truthy, the token will not be revoked when the current job is complete"`, so this change could be considered a breaking change. This means that if there are users who rely on `truthy` and expect values like whitespace or `"false"` to be evaluated as true (though this is likely rare), it would be a breaking change. - `Boolean(" ")` and `Boolean("false")` are both evaluated as true. Alternatively, it can simply be considered a fix. How to handle this is up to the maintainer. Resolves https://github.com/actions/create-github-app-token/issues/216
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);
|
|
}
|