2950cbc446
This pull request fixes the handling of permissions inputs. - Updated `getPermissionsFromInputs` in `lib/get-permissions-from-inputs.js` to use hyphens (`INPUT_PERMISSION-`) instead of underscores (`INPUT_PERMISSION_`) in input keys, added a check to skip empty values, and clarified behavior when no permissions are set. - Added a `shouldRetry` function to retry requests when server errors (HTTP status 500 or higher) occur in the `main` function in `lib/main.js` to prevent unnecessary retries. - Updated test cases in `tests/main-token-permissions-set.test.js` to match the new input key format with hyphens. - Added a default empty string for unset inputs (e.g., `INPUT_PERMISSION-ADMINISTRATION`) in `tests/main.js` to simulate the behavior of the Actions runner. - Updated snapshots in `tests/snapshots/index.js.md` to reflect the updated hyphenated input keys in permissions. --------- Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
27 lines
891 B
JavaScript
27 lines
891 B
JavaScript
/**
|
|
* Finds all permissions passed via `permision-*` inputs and turns them into an object.
|
|
*
|
|
* @see https://docs.github.com/en/actions/sharing-automations/creating-actions/metadata-syntax-for-github-actions#inputs
|
|
* @param {NodeJS.ProcessEnv} env
|
|
* @returns {undefined | Record<string, string>}
|
|
*/
|
|
export function getPermissionsFromInputs(env) {
|
|
return Object.entries(env).reduce((permissions, [key, value]) => {
|
|
if (!key.startsWith("INPUT_PERMISSION-")) return permissions;
|
|
if (!value) return permissions;
|
|
|
|
const permission = key.slice("INPUT_PERMISSION-".length).toLowerCase();
|
|
|
|
// Inherit app permissions if no permissions inputs are set
|
|
if (permissions === undefined) {
|
|
return { [permission]: value };
|
|
}
|
|
|
|
return {
|
|
// @ts-expect-error - needs to be typed correctly
|
|
...permissions,
|
|
[permission]: value,
|
|
};
|
|
}, undefined);
|
|
}
|