0e0aa99a86
- Load `app-permissions` from schema exported by `@octokit/openapi` - Update documentation in README.md - Implement the `permissions_*` inputs in the action code --------- Co-authored-by: Parker Brown <17183625+parkerbxyz@users.noreply.github.com>
24 lines
790 B
JavaScript
24 lines
790 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;
|
|
|
|
const permission = key.slice("INPUT_PERMISSION_".length).toLowerCase();
|
|
if (permissions === undefined) {
|
|
return { [permission]: value };
|
|
}
|
|
|
|
return {
|
|
// @ts-expect-error - needs to be typed correctly
|
|
...permissions,
|
|
[permission]: value,
|
|
};
|
|
}, undefined);
|
|
}
|